SO3Engine
SO3VehicleContraint.cpp
Go to the documentation of this file.
1
12
13namespace SO3
14{
15
16SVehicleContraint::SVehicleContraint() : SPhysicContraint(0, 0, 0, SPhysicContraint::SO3_VEHICLE_CONTRAINT)
17{
18 // Forbiden, private.
19}
20
21SVehicleContraint::SVehicleContraint(SScene* scene, SBody* son) : SPhysicContraint(scene, son, 0, SPhysicContraint::SO3_VEHICLE_CONTRAINT)
22{
23 UpdateJoint();
24}
25
27{
28 //mjoint deleted in SPhysicContraint
29}
30
34
36{
37 mSonBody = body;
38 UpdateJoint();
39}
40
41void SVehicleContraint::UpdateJoint()
42{
44 SAFE_DELETE(mJoint);
45
46 if (mSonBody)
47 {
49 }
50}
51
53{
54 if (mJoint == NULL)
55 return 0.0f;
56 else
57 return static_cast<OgreNewt::Vehicle*>(mJoint)->getSpeed();
58}
59
60void SVehicleContraint::AddTire(SNode* node, Ogre::Real mass, Ogre::Real radius, Ogre::Real width, Ogre::Real friction, Ogre::Real susLength, Ogre::Real susSpring, Ogre::Real susShock, bool steer, bool driving)
61{
62 if (mJoint == NULL)
63 return;
64
65 //set a minimum friction
66 if (friction <= 0.0f)
67 friction = 0.01f;
68
69 //set a minimum mass
70 if (mass <= 0.0f)
71 mass = 0.001f;
72
73 static_cast<OgreNewt::Vehicle*>(mJoint)->AddSingleSuspensionTire(node->GetOgreSceneNodePointer(), mass, radius, width, friction, susLength, susSpring, susShock, steer, driving);
74}
75
76void SVehicleContraint::SetSteerAngle(Ogre::Radian angle)
77{
78 if (mJoint == NULL)
79 return;
80
81 static_cast<OgreNewt::Vehicle*>(mJoint)->setSteerAngle(angle);
82}
83
84void SVehicleContraint::SetDrivingTorque(Ogre::Radian torque)
85{
86 if (mJoint == NULL)
87 return;
88
89 static_cast<OgreNewt::Vehicle*>(mJoint)->setDrivingTorque(torque);
90}
91
92void SVehicleContraint::SetBrake(Ogre::Real brake)
93{
94 if (mJoint == NULL)
95 return;
96
97 static_cast<OgreNewt::Vehicle*>(mJoint)->setBrake(brake);
98}
99
101{
102 if (mJoint == NULL)
103 return true;
104
105 return static_cast<OgreNewt::Vehicle*>(mJoint)->getVehicleOnAir();
106}
107
109{
110 return static_cast<OgreNewt::Vehicle*>(mJoint)->getTireOnAir(node->GetOgreSceneNodePointer());
111}
112
114{
115 return static_cast<OgreNewt::Vehicle*>(mJoint)->getTireAngularVelocity(node->GetOgreSceneNodePointer());
116}
117
118}
base class for all joints.
Represents a wheeled vehicle.
void waitForUpdateToFinish() const
OgreNewt::Body * getOgreNewtBodyPointer()
Definition SO3Body.cpp:340
Ogre::SceneNode * GetOgreSceneNodePointer()
OgreNewt::Joint * mJoint
OgreNewt::World * GetPhysicWorld()
SPhysicWorld * GetPhysicsWorld()
void AddTire(SNode *node, Ogre::Real mass, Ogre::Real radius, Ogre::Real width, Ogre::Real friction, Ogre::Real susLength, Ogre::Real susSpring, Ogre::Real susShock, bool steer, bool driving)
Ogre::Real GetTireAngularVelocity(SNode *node)
virtual void SetParentBody(SBody *body)
void SetSteerAngle(Ogre::Radian angle)
void SetDrivingTorque(Ogre::Radian torque)
virtual void SetSonBody(SBody *body)
void SetBrake(Ogre::Real brake)
Manage Physics Contraint. .