SO3Engine
OgreNewt_Vehicle.cpp
Go to the documentation of this file.
8#include <CustomDGRayCastCar.h>
9
10namespace OgreNewt
11{
13// TIRE FUNCTIONS
14 // constructor
16 {
17 m_body = carBody;
18 // make a matrix to indicate the cal local coordinate system
19 dMatrix carCordenatSytem;
20 carCordenatSytem.m_front = dVector (0.0f, 0.0f, -1.0f, 0.0f); // Ogre front direction is is -z axis
21 carCordenatSytem.m_up = dVector (0.0f, 1.0f, 0.0f, 0.0f); // Ogre vertical direction is y up axis
22 carCordenatSytem.m_right = carCordenatSytem.m_front * carCordenatSytem.m_up; // tire coordinate system perpendicular front and up
23 carCordenatSytem.m_posit = dVector (0.0f, 0.0f, 0.0f, 1.0f); // this most be a zero vector
24
25 RaycastVehicle* controller = new RaycastVehicle(carCordenatSytem, carBody);
26 SetSupportJoint(controller);
27 }
28
30 {
31 }
32
34 {
35 return m_body;
36 }
37
38 void Vehicle::AddSingleSuspensionTire(Ogre::Node* node, const Ogre::Real mass, const Ogre::Real radius, const Ogre::Real width, const Ogre::Real friction, const Ogre::Real susLength, const Ogre::Real susSpring, const Ogre::Real susShock, const bool steer, const bool driving)
39 {
41 veh->addTire(node, mass, radius, width, friction, susLength, susSpring, susShock, steer, driving);
42 }
43
45 {
47 return veh->GetTiresCount();
48 }
49
50 Ogre::Real Vehicle::getSpeed()
51 {
53 return veh->GetSpeed();
54 /*Ogre::Vector3 vel = getBody0()->getVelocity();
55 Ogre::Real speed = sqrt((vel.x * vel.x) + (vel.y * vel.y) + (vel.z * vel.z));
56 return speed;*/
57 }
58
59 void Vehicle::setSteerAngle(Ogre::Radian angle)
60 {
62 return veh->ApplySteering(angle.valueRadians());
63 }
64
65 void Vehicle::setDrivingTorque(Ogre::Radian torque)
66 {
68 return veh->ApplyTorque(torque.valueRadians());
69 }
70
71 void Vehicle::setBrake(Ogre::Real brake)
72 {
74 return veh->ApplyBrake(brake);
75 }
76
78 {
80
81 return veh->GetVehicleOnAir() ? true : false;
82 }
83
84 void Vehicle::showDebugData(Ogre::SceneNode* debugRootNode)
85 {
87 veh->showDebugData(debugRootNode);
88 }
89
90 bool Vehicle::getTireOnAir(Ogre::Node* node)
91 {
93 int index = veh->getTireIndexByNode(node);
94 if (index == -1)
95 return true;
96
97 return veh->getTireOnAir(index);
98 }
99
100 Ogre::Real Vehicle::getTireAngularVelocity(Ogre::Node* node)
101 {
103 int index = veh->getTireIndexByNode(node);
104 if (index == -1)
105 return 0.0f;
106
107 return veh->getTireAngularVelocity(index);
108 }
109
110} // end NAMESPACE OgreNewt
111
112
113
main class for all Rigid Bodies in the system.
base class for all joints.
CustomJoint * m_joint
void SetSupportJoint(CustomJoint *supportJoint)
SetSupportJoint.
void addTire(Ogre::Node *node, const Ogre::Real mass, const Ogre::Real radius, const Ogre::Real width, const Ogre::Real friction, const Ogre::Real susLength, const Ogre::Real susSpring, const Ogre::Real susShock, const bool steer, const bool driving)
Ogre::Real getTireAngularVelocity(unsigned int index)
void ApplyBrake(dFloat brakeTorque)
int getTireIndexByNode(Ogre::Node *node)
bool getTireOnAir(unsigned int index)
void showDebugData(Ogre::SceneNode *debugRootNode)
show joint visual debugging data
OgreNewt::Body * getVehicleBody()
virtual void showDebugData(Ogre::SceneNode *debugRootNode)
show joint visual debugging data
int GetTiresCount() const
get current tire count
void AddSingleSuspensionTire(Ogre::Node *node, const Ogre::Real mass, const Ogre::Real radius, const Ogre::Real width, const Ogre::Real friction, const Ogre::Real susLength, const Ogre::Real susSpring, const Ogre::Real susShock, const bool steer=false, const bool driving=false)
add and independent suspension tire to the car body
virtual ~Vehicle()
destructor
bool getTireOnAir(Ogre::Node *node)
Vehicle(OgreNewt::Body *carBody)
constructor
void setBrake(Ogre::Real brake)
void setDrivingTorque(Ogre::Radian torque)
void setSteerAngle(Ogre::Radian angle)
Ogre::Real getTireAngularVelocity(Ogre::Node *node)