RigsofRods
Soft-body Physics Simulation
TyrePressure.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2015-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "TyrePressure.h"
23 
24 #include "Actor.h"
25 #include "InputEngine.h"
26 #include "SoundScriptManager.h"
27 
28 #include <Ogre.h>
29 
30 using namespace RoR;
31 
33 {
34  if (App::GetInputEngine()->getEventBoolValue(EV_COMMON_PRESSURE_LESS))
35  {
36  float change = m_ref_tyre_pressure * (1.0f - pow(2.0f, dt / 2.0f));
37  change = Ogre::Math::Clamp(change, -dt * 10.0f, -dt * 1.0f);
38  if (m_pressure_pressed = this->ModifyTyrePressure(change))
39  {
41  }
42  }
43  else if (App::GetInputEngine()->getEventBoolValue(EV_COMMON_PRESSURE_MORE))
44  {
45  float change = m_ref_tyre_pressure * (pow(2.0f, dt / 2.0f) - 1.0f);
46  change = Ogre::Math::Clamp(change, +dt * 1.0f, +dt * 10.0f);
47  if (m_pressure_pressed = this->ModifyTyrePressure(change))
48  {
50  }
51  }
52  else if (m_pressure_pressed)
53  {
55  m_pressure_pressed = false;
57  }
58  else if (m_pressure_pressed_timer > 0.0f)
59  {
61  }
62 }
63 
65 {
66  float newpressure = Ogre::Math::Clamp(m_ref_tyre_pressure + v, 0.0f, 100.0f);
67  if (newpressure == m_ref_tyre_pressure)
68  return false;
69 
70  for (int beam_id: m_pressure_beams)
71  {
72  m_actor->ar_beams[beam_id].k = 10000 + newpressure * 10000;
73  }
74  m_ref_tyre_pressure = newpressure;
75  return true;
76 }
RoR::TyrePressure::m_pressure_pressed
bool m_pressure_pressed
Definition: TyrePressure.h:56
RoR::TyrePressure::m_ref_tyre_pressure
float m_ref_tyre_pressure
Definition: TyrePressure.h:58
RoR::TyrePressure::ModifyTyrePressure
bool ModifyTyrePressure(float v)
Definition: TyrePressure.cpp:64
TyrePressure.h
Wheel 'pressure adjustment' logic (only for 'wheels2')
RoR::TyrePressure::m_pressure_pressed_timer
float m_pressure_pressed_timer
Definition: TyrePressure.h:57
RoR::EV_COMMON_PRESSURE_MORE
@ EV_COMMON_PRESSURE_MORE
increase tire pressure (note: only very few trucks support this)
Definition: InputEngine.h:246
Actor.h
RoR::EV_COMMON_PRESSURE_LESS
@ EV_COMMON_PRESSURE_LESS
decrease tire pressure (note: only very few trucks support this)
Definition: InputEngine.h:245
RoR::Actor::ar_beams
beam_t * ar_beams
Definition: Actor.h:281
RoR::TyrePressure::m_pressure_beams
std::vector< int > m_pressure_beams
Definition: TyrePressure.h:55
RoR::TyrePressure::m_actor
ActorPtr m_actor
Definition: TyrePressure.h:54
RoR::SS_TRIG_AIR
@ SS_TRIG_AIR
Definition: SoundScriptManager.h:68
SOUND_START
#define SOUND_START(_ACTOR_, _TRIG_)
Definition: SoundScriptManager.h:35
SoundScriptManager.h
SOUND_STOP
#define SOUND_STOP(_ACTOR_, _TRIG_)
Definition: SoundScriptManager.h:36
RoR::beam_t::k
float k
tensile spring
Definition: SimData.h:336
RoR::App::GetInputEngine
InputEngine * GetInputEngine()
Definition: Application.cpp:271
InputEngine.h
Handles controller inputs from player. Defines input events and binding mechanism,...
RoR
Definition: AppContext.h:36
RoR::TyrePressure::UpdateInputEvents
void UpdateInputEvents(float dt)
Definition: TyrePressure.cpp:32