Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
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
30using 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}
Handles controller inputs from player.
#define SOUND_START(_ACTOR_, _TRIG_)
#define SOUND_STOP(_ACTOR_, _TRIG_)
Wheel 'pressure adjustment' logic (only for 'wheels2')
beam_t * ar_beams
Definition Actor.h:348
void UpdateInputEvents(float dt)
std::vector< int > m_pressure_beams
float m_pressure_pressed_timer
bool ModifyTyrePressure(float v)
@ EV_COMMON_PRESSURE_LESS
decrease tire pressure (note: only very few trucks support this)
@ EV_COMMON_PRESSURE_MORE
increase tire pressure (note: only very few trucks support this)
InputEngine * GetInputEngine()
float k
tensile spring
Definition SimData.h:311