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
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
34using namespace Ogre;
35using namespace RoR;
36
37Screwprop::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{
46 reset();
47}
48
53
55{
56 if (!App::GetGameContext()->GetTerrain()->getWater())
57 return;
58
60 if (depth < 0)
61 return; //out of water!
64 dir.normalise();
65 if (reverse)
66 dir = -dir;
67 rudaxis.normalise();
68 dir = (throtle * fullpower) * (Quaternion(Degree(rudder), rudaxis) * dir);
70
71 if (update && splashp && throtle > 0.1)
72 {
73 if (depth < 0.2)
75 else
78 }
79}
80
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;
92}
93
94void 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
104{
105 if (reverse)
106 return -throtle;
107 else
108 return throtle;
109}
110
112{
113 return rudder / 45.0;
114}
115
117{
118 setThrottle(0);
119 rudder = 0;
120 reverse = false;
121}
122
124{
125 throtle = 0;
126 reverse = !reverse;
127}
Central state/object manager and communications hub.
Game state manager and message-queue provider.
Core data structures for simulation; Everything affected by by either physics, network or user intera...
#define SOUND_MODULATE(_ACTOR_, _MOD_, _VALUE_)
node_t * ar_nodes
Definition Actor.h:330
void allocRipple(Ogre::Vector3 pos, Ogre::Vector3 vel)
Definition DustPool.cpp:184
void allocSplash(Ogre::Vector3 pos, Ogre::Vector3 vel)
Definition DustPool.cpp:173
const TerrainPtr & GetTerrain()
DustPool * GetDustPool(const char *name)
Definition GfxScene.cpp:277
ActorPtr m_actor
Definition ScrewProp.h:66
float fullpower
in HP
Definition ScrewProp.h:61
virtual ~Screwprop() override
Definition ScrewProp.cpp:49
DustPool * ripplep
Definition ScrewProp.h:59
void toggleReverse()
void updateForces(int update)
Definition ScrewProp.cpp:54
DustPool * splashp
Definition ScrewProp.h:59
NodeNum_t noderef
Definition ScrewProp.h:68
Screwprop(ActorPtr actor, NodeNum_t noderef, NodeNum_t nodeback, NodeNum_t nodeup, float power)
Definition ScrewProp.cpp:37
NodeNum_t nodeback
Definition ScrewProp.h:67
NodeNum_t nodeup
Definition ScrewProp.h:69
float getRudder()
void setRudder(float val)
Definition ScrewProp.cpp:94
float getThrottle()
void setThrottle(float val)
Definition ScrewProp.cpp:81
Wavefield * getWater()
Definition Terrain.h:87
float CalcWavesHeight(Vec3 pos, float timeshift_sec=0.f)
Definition Wavefield.cpp:90
GameContext * GetGameContext()
GfxScene * GetGfxScene()
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Ogre::Vector3 AbsPosition
absolute position in the world (shaky)
Definition SimData.h:267
Ogre::Vector3 Forces
Definition SimData.h:269
Ogre::Vector3 RelPosition
relative to the local physics origin (one origin per actor) (shaky)
Definition SimData.h:266