Rigs of Rods
2026.01
Soft-body Physics Simulation
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
Loading...
Searching...
No Matches
source
main
physics
water
ScrewProp.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
6
For more information, see http://www.rigsofrods.org/
7
8
Rigs of Rods is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License version 3, as
10
published by the Free Software Foundation.
11
12
Rigs of Rods is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19
*/
20
21
#include "
ScrewProp.h
"
22
23
#include "
Application.h
"
24
#include "
Actor.h
"
25
#include "
SimData.h
"
26
#include "
ActorManager.h
"
27
#include "
DustPool.h
"
28
#include "
GameContext.h
"
29
#include "
GfxScene.h
"
30
#include "
SoundScriptManager.h
"
31
#include "
Terrain.h
"
32
#include "
GfxWater.h
"
33
34
using namespace
Ogre
;
35
using namespace
RoR
;
36
37
Screwprop::Screwprop
(
ActorPtr
a,
NodeNum_t
noderef,
NodeNum_t
nodeback,
NodeNum_t
nodeup,
float
fullpower) :
38
m_actor(a)
39
, noderef(noderef)
40
, nodeback(nodeback)
41
, nodeup(nodeup)
42
, fullpower(fullpower)
43
{
44
splashp
=
RoR::App::GetGfxScene
()->
GetDustPool
(
"splash"
);
45
ripplep
=
RoR::App::GetGfxScene
()->
GetDustPool
(
"ripple"
);
46
reset
();
47
}
48
49
Screwprop::~Screwprop
()
50
{
51
52
}
53
54
void
Screwprop::updateForces
(
int
update)
55
{
56
if
(!
App::GetGameContext
()->GetTerrain()->getWater())
57
return
;
58
59
float
depth =
App::GetGameContext
()->
GetTerrain
()->
getWater
()->
CalcWavesHeight
(
m_actor
->
ar_nodes
[
noderef
].
AbsPosition
) -
m_actor
->
ar_nodes
[
noderef
].
AbsPosition
.y;
60
if
(depth < 0)
61
return
;
//out of water!
62
Vector3 dir =
m_actor
->
ar_nodes
[
nodeback
].
RelPosition
-
m_actor
->
ar_nodes
[
noderef
].
RelPosition
;
63
Vector3 rudaxis =
m_actor
->
ar_nodes
[
noderef
].
RelPosition
-
m_actor
->
ar_nodes
[
nodeup
].
RelPosition
;
64
dir.normalise();
65
if
(
reverse
)
66
dir = -dir;
67
rudaxis.normalise();
68
dir = (
throtle
*
fullpower
) * (Quaternion(Degree(
rudder
), rudaxis) * dir);
69
m_actor
->
ar_nodes
[
noderef
].
Forces
+= dir;
70
71
if
(update &&
splashp
&&
throtle
> 0.1)
72
{
73
if
(depth < 0.2)
74
splashp
->
allocSplash
(
m_actor
->
ar_nodes
[
noderef
].
AbsPosition
, 10.0 * dir /
fullpower
);
75
else
76
splashp
->
allocSplash
(
m_actor
->
ar_nodes
[
noderef
].
AbsPosition
, 5.0 * dir /
fullpower
);
77
ripplep
->
allocRipple
(
m_actor
->
ar_nodes
[
noderef
].
AbsPosition
, 10.0 * dir /
fullpower
);
78
}
79
}
80
81
void
Screwprop::setThrottle
(
float
val)
82
{
83
if
(val > 1.0)
84
val = 1.0;
85
if
(val < -1.0)
86
val = -1.0;
87
throtle
= fabs(val);
88
reverse
= (val < 0);
89
//pseudo-rpm
90
float
prpm = (0.5 + fabs(val) / 2.0) * 100.0;
91
SOUND_MODULATE
(
m_actor
,
SS_MOD_ENGINE
, prpm);
92
}
93
94
void
Screwprop::setRudder
(
float
val)
95
{
96
if
(val > 1.0)
97
val = 1.0;
98
if
(val < -1.0)
99
val = -1.0;
100
rudder
= val * 45.0;
101
}
102
103
void
Screwprop::setMaxPower
(
float
power)
104
{
105
if
(power >= 0)
106
{
107
fullpower
= power;
108
}
109
}
110
111
float
Screwprop::getThrottle
()
112
{
113
if
(
reverse
)
114
return
-
throtle
;
115
else
116
return
throtle
;
117
}
118
119
float
Screwprop::getRudder
()
120
{
121
return
rudder
/ 45.0;
122
}
123
124
void
Screwprop::reset
()
125
{
126
setThrottle
(0);
127
rudder
= 0;
128
reverse
=
false
;
129
}
130
131
void
Screwprop::toggleReverse
()
132
{
133
throtle
= 0;
134
reverse
= !
reverse
;
135
}
Actor.h
ActorManager.h
Application.h
Central state/object manager and communications hub.
DustPool.h
GameContext.h
Game state manager and message-queue provider.
GfxScene.h
GfxWater.h
ScrewProp.h
SimData.h
Core data structures for simulation; Everything affected by by either physics, network or user intera...
SoundScriptManager.h
SOUND_MODULATE
#define SOUND_MODULATE(_ACTOR_, _MOD_, _VALUE_)
Definition
SoundScriptManager.h:40
Terrain.h
RefCountingObjectPtr< Actor >
RoR::Actor::ar_nodes
node_t * ar_nodes
Definition
Actor.h:365
RoR::DustPool::allocRipple
void allocRipple(Ogre::Vector3 pos, Ogre::Vector3 vel)
Definition
DustPool.cpp:183
RoR::DustPool::allocSplash
void allocSplash(Ogre::Vector3 pos, Ogre::Vector3 vel)
Definition
DustPool.cpp:172
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition
GameContext.h:117
RoR::GfxScene::GetDustPool
DustPool * GetDustPool(const char *name)
Definition
GfxScene.cpp:277
RoR::Screwprop::m_actor
ActorPtr m_actor
Definition
ScrewProp.h:67
RoR::Screwprop::fullpower
float fullpower
in HP
Definition
ScrewProp.h:62
RoR::Screwprop::~Screwprop
virtual ~Screwprop() override
Definition
ScrewProp.cpp:49
RoR::Screwprop::ripplep
DustPool * ripplep
Definition
ScrewProp.h:60
RoR::Screwprop::reverse
bool reverse
Definition
ScrewProp.h:61
RoR::Screwprop::toggleReverse
void toggleReverse()
Definition
ScrewProp.cpp:131
RoR::Screwprop::throtle
float throtle
Definition
ScrewProp.h:64
RoR::Screwprop::updateForces
void updateForces(int update)
Definition
ScrewProp.cpp:54
RoR::Screwprop::splashp
DustPool * splashp
Definition
ScrewProp.h:60
RoR::Screwprop::noderef
NodeNum_t noderef
Definition
ScrewProp.h:69
RoR::Screwprop::Screwprop
Screwprop(ActorPtr actor, NodeNum_t noderef, NodeNum_t nodeback, NodeNum_t nodeup, float power)
Definition
ScrewProp.cpp:37
RoR::Screwprop::nodeback
NodeNum_t nodeback
Definition
ScrewProp.h:68
RoR::Screwprop::nodeup
NodeNum_t nodeup
Definition
ScrewProp.h:70
RoR::Screwprop::getRudder
float getRudder()
Definition
ScrewProp.cpp:119
RoR::Screwprop::reset
void reset()
Definition
ScrewProp.cpp:124
RoR::Screwprop::setRudder
void setRudder(float val)
Definition
ScrewProp.cpp:94
RoR::Screwprop::getThrottle
float getThrottle()
Definition
ScrewProp.cpp:111
RoR::Screwprop::rudder
float rudder
Definition
ScrewProp.h:63
RoR::Screwprop::setMaxPower
void setMaxPower(float power)
Definition
ScrewProp.cpp:103
RoR::Screwprop::setThrottle
void setThrottle(float val)
Definition
ScrewProp.cpp:81
RoR::Terrain::getWater
Wavefield * getWater()
Definition
Terrain.h:87
RoR::Wavefield::CalcWavesHeight
float CalcWavesHeight(Vec3 pos, float timeshift_sec=0.f)
Definition
Wavefield.cpp:90
RoR::SS_MOD_ENGINE
@ SS_MOD_ENGINE
Definition
SoundScriptManager.h:125
Ogre
Definition
ExtinguishableFireAffector.cpp:35
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition
Application.cpp:312
RoR::App::GetGfxScene
GfxScene * GetGfxScene()
Definition
Application.cpp:307
RoR
Definition
AppContext.h:36
RoR::NodeNum_t
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Definition
ForwardDeclarations.h:54
RoR::node_t::AbsPosition
Ogre::Vector3 AbsPosition
absolute position in the world (shaky)
Definition
SimData.h:267
RoR::node_t::Forces
Ogre::Vector3 Forces
Definition
SimData.h:269
RoR::node_t::RelPosition
Ogre::Vector3 RelPosition
relative to the local physics origin (one origin per actor) (shaky)
Definition
SimData.h:266
Generated on Sun Oct 18 2026 08:40:11 for Rigs of Rods by
1.9.8