RigsofRods
Soft-body Physics Simulation
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 "Water.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 {
46  reset();
47 }
48 
49 void Screwprop::updateForces(int update)
50 {
51  if (!App::GetGameContext()->GetTerrain()->getWater())
52  return;
53 
55  if (depth < 0)
56  return; //out of water!
59  dir.normalise();
60  if (reverse)
61  dir = -dir;
62  rudaxis.normalise();
63  dir = (throtle * fullpower) * (Quaternion(Degree(rudder), rudaxis) * dir);
64  m_actor->ar_nodes[noderef].Forces += dir;
65 
66  if (update && splashp && throtle > 0.1)
67  {
68  if (depth < 0.2)
70  else
73  }
74 }
75 
76 void Screwprop::setThrottle(float val)
77 {
78  if (val > 1.0)
79  val = 1.0;
80  if (val < -1.0)
81  val = -1.0;
82  throtle = fabs(val);
83  reverse = (val < 0);
84  //pseudo-rpm
85  float prpm = (0.5 + fabs(val) / 2.0) * 100.0;
87 }
88 
89 void Screwprop::setRudder(float val)
90 {
91  if (val > 1.0)
92  val = 1.0;
93  if (val < -1.0)
94  val = -1.0;
95  rudder = val * 45.0;
96 }
97 
99 {
100  if (reverse)
101  return -throtle;
102  else
103  return throtle;
104 }
105 
107 {
108  return rudder / 45.0;
109 }
110 
112 {
113  setThrottle(0);
114  rudder = 0;
115  reverse = false;
116 }
117 
119 {
120  throtle = 0;
121  reverse = !reverse;
122 }
GameContext.h
Game state manager and message-queue provider.
RoR::IWater::CalcWavesHeight
virtual float CalcWavesHeight(Ogre::Vector3 pos)=0
RoR::Screwprop::nodeback
NodeNum_t nodeback
Definition: ScrewProp.h:58
RoR::Screwprop::reset
void reset()
Definition: ScrewProp.cpp:111
RoR::Screwprop::m_actor
ActorPtr m_actor
Definition: ScrewProp.h:57
RoR::node_t::AbsPosition
Ogre::Vector3 AbsPosition
absolute position in the world (shaky)
Definition: SimData.h:294
RoR::Screwprop::ripplep
DustPool * ripplep
Definition: ScrewProp.h:50
RoR::Screwprop::fullpower
float fullpower
in HP
Definition: ScrewProp.h:52
RoR::Screwprop::setRudder
void setRudder(float val)
Definition: ScrewProp.cpp:89
RoR::node_t::RelPosition
Ogre::Vector3 RelPosition
relative to the local physics origin (one origin per actor) (shaky)
Definition: SimData.h:293
RefCountingObjectPtr< Actor >
ActorManager.h
Actor.h
RoR::DustPool::allocRipple
void allocRipple(Ogre::Vector3 pos, Ogre::Vector3 vel)
Definition: DustPool.cpp:183
ScrewProp.h
RoR::Screwprop::nodeup
NodeNum_t nodeup
Definition: ScrewProp.h:60
RoR::NodeNum_t
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Definition: ForwardDeclarations.h:52
RoR::Screwprop::rudder
float rudder
Definition: ScrewProp.h:53
SimData.h
Core data structures for simulation; Everything affected by by either physics, network or user intera...
GfxScene.h
RoR::Screwprop::setThrottle
void setThrottle(float val)
Definition: ScrewProp.cpp:76
Application.h
Central state/object manager and communications hub.
RoR::Screwprop::noderef
NodeNum_t noderef
Definition: ScrewProp.h:59
SoundScriptManager.h
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition: Application.cpp:280
RoR::Screwprop::getRudder
float getRudder()
Definition: ScrewProp.cpp:106
RoR::Screwprop::splashp
DustPool * splashp
Definition: ScrewProp.h:50
RoR::GfxScene::GetDustPool
DustPool * GetDustPool(const char *name)
Definition: GfxScene.cpp:263
DustPool.h
SOUND_MODULATE
#define SOUND_MODULATE(_ACTOR_, _MOD_, _VALUE_)
Definition: SoundScriptManager.h:40
RoR::Actor::ar_nodes
node_t * ar_nodes
Definition: Actor.h:279
RoR::DustPool::allocSplash
void allocSplash(Ogre::Vector3 pos, Ogre::Vector3 vel)
Definition: DustPool.cpp:172
RoR::Screwprop::throtle
float throtle
Definition: ScrewProp.h:54
RoR::Screwprop::getThrottle
float getThrottle()
Definition: ScrewProp.cpp:98
RoR::Screwprop::reverse
bool reverse
Definition: ScrewProp.h:51
Terrain.h
Ogre
Definition: ExtinguishableFireAffector.cpp:35
RoR::Screwprop::updateForces
void updateForces(int update)
Definition: ScrewProp.cpp:49
RoR::SS_MOD_ENGINE
@ SS_MOD_ENGINE
Definition: SoundScriptManager.h:125
RoR
Definition: AppContext.h:36
Water.h
RoR::App::GetGfxScene
GfxScene * GetGfxScene()
Definition: Application.cpp:276
RoR::Terrain::getWater
IWater * getWater()
Definition: Terrain.h:84
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition: GameContext.h:117
RoR::node_t::Forces
Ogre::Vector3 Forces
Definition: SimData.h:296
RoR::Screwprop::toggleReverse
void toggleReverse()
Definition: ScrewProp.cpp:118