Bullet Collision Detection & Physics Library: btRaycastVehicle.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btRaycastVehicle.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
3 *
4 * Permission to use, copy, modify, distribute and sell this software
5 * and its documentation for any purpose is hereby granted without fee,
6 * provided that the above copyright notice appear in all copies.
7 * Erwin Coumans makes no representations about the suitability
8 * of this software for any purpose.
9 * It is provided "as is" without express or implied warranty.
10 */
11 #ifndef BT_RAYCASTVEHICLE_H
12 #define BT_RAYCASTVEHICLE_H
13
14 #include "BulletDynamics/Dynamics/btRigidBody.h"
15 #include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
16 #include "btVehicleRaycaster.h"
17 class btDynamicsWorld;
18 #include "LinearMath/btAlignedObjectArray.h"
19 #include "btWheelInfo.h"
20 #include "BulletDynamics/Dynamics/btActionInterface.h"
21
22 class btVehicleTuning;
23
25 class btRaycastVehicle : public btActionInterface
26 {
27
28 btAlignedObjectArray<btVector3> m_forwardWS;
29 btAlignedObjectArray<btVector3> m_axle;
30 btAlignedObjectArray<btScalar> m_forwardImpulse;
31 btAlignedObjectArray<btScalar> m_sideImpulse;
32
34 int m_userConstraintType;
35 int m_userConstraintId;
36
37 public:
38 class btVehicleTuning
39 {
40 public:
41
42 btVehicleTuning()
43 :m_suspensionStiffness(btScalar(5.88)),
44 m_suspensionCompression(btScalar(0.83)),
45 m_suspensionDamping(btScalar(0.88)),
46 m_maxSuspensionTravelCm(btScalar(500.)),
47 m_frictionSlip(btScalar(10.5)),
48 m_maxSuspensionForce(btScalar(6000.))
49 {
50 }
51 btScalar m_suspensionStiffness;
52 btScalar m_suspensionCompression;
53 btScalar m_suspensionDamping;
54 btScalar m_maxSuspensionTravelCm;
55 btScalar m_frictionSlip;
56 btScalar m_maxSuspensionForce;
57
58 };
59 private:
60
61 btScalar m_tau;
62 btScalar m_damping;
63 btVehicleRaycaster* m_vehicleRaycaster;
64 btScalar m_pitchControl;
65 btScalar m_steeringValue;
66 btScalar m_currentVehicleSpeedKmHour;
67
68 btRigidBody* m_chassisBody;
69
70 int m_indexRightAxis;
71 int m_indexUpAxis;
72 int m_indexForwardAxis;
73
74 void defaultInit(const btVehicleTuning& tuning);
75
76 public:
77
78 //constructor to create a car from an existing rigidbody
79 btRaycastVehicle(const btVehicleTuning& tuning,btRigidBody* chassis, btVehicleRaycaster* raycaster );
80
81 virtual ~btRaycastVehicle() ;
82
83
85 virtual void updateAction( btCollisionWorld* collisionWorld, btScalar step)
86 {
87 (void) collisionWorld;
88 updateVehicle(step);
89 }
90
91
93 void debugDraw(btIDebugDraw* debugDrawer);
94
95 const btTransform& getChassisWorldTransform() const;
96
97 btScalar rayCast(btWheelInfo& wheel);
98
99 virtual void updateVehicle(btScalar step);
100
101
102 void resetSuspension();
103
104 btScalar getSteeringValue(int wheel) const;
105
106 void setSteeringValue(btScalar steering,int wheel);
107
108
109 void applyEngineForce(btScalar force, int wheel);
110
111 const btTransform& getWheelTransformWS( int wheelIndex ) const;
112
113 void updateWheelTransform( int wheelIndex, bool interpolatedTransform = true );
114
115 // void setRaycastWheelInfo( int wheelIndex , bool isInContact, const btVector3& hitPoint, const btVector3& hitNormal,btScalar depth);
116
117 btWheelInfo& addWheel( const btVector3& connectionPointCS0, const btVector3& wheelDirectionCS0,const btVector3& wheelAxleCS,btScalar suspensionRestLength,btScalar wheelRadius,const btVehicleTuning& tuning, bool isFrontWheel);
118
119 inline int getNumWheels() const {
120 return int (m_wheelInfo.size());
121 }
122
123 btAlignedObjectArray<btWheelInfo> m_wheelInfo;
124
125
126 const btWheelInfo& getWheelInfo(int index) const;
127
128 btWheelInfo& getWheelInfo(int index);
129
130 void updateWheelTransformsWS(btWheelInfo& wheel , bool interpolatedTransform = true);
131
132
133 void setBrake(btScalar brake,int wheelIndex);
134
135 void setPitchControl(btScalar pitch)
136 {
137 m_pitchControl = pitch;
138 }
139
140 void updateSuspension(btScalar deltaTime);
141
142 virtual void updateFriction(btScalar timeStep);
143
144
145
146 inline btRigidBody* getRigidBody()
147 {
148 return m_chassisBody;
149 }
150
151 const btRigidBody* getRigidBody() const
152 {
153 return m_chassisBody;
154 }
155
156 inline int getRightAxis() const
157 {
158 return m_indexRightAxis;
159 }
160 inline int getUpAxis() const
161 {
162 return m_indexUpAxis;
163 }
164
165 inline int getForwardAxis() const
166 {
167 return m_indexForwardAxis;
168 }
169
170
172 btVector3 getForwardVector() const
173 {
174 const btTransform& chassisTrans = getChassisWorldTransform();
175
176 btVector3 forwardW (
177 chassisTrans.getBasis()[0][m_indexForwardAxis],
178 chassisTrans.getBasis()[1][m_indexForwardAxis],
179 chassisTrans.getBasis()[2][m_indexForwardAxis]);
180
181 return forwardW;
182 }
183
185 btScalar getCurrentSpeedKmHour() const
186 {
187 return m_currentVehicleSpeedKmHour;
188 }
189
190 virtual void setCoordinateSystem(int rightIndex,int upIndex,int forwardIndex)
191 {
192 m_indexRightAxis = rightIndex;
193 m_indexUpAxis = upIndex;
194 m_indexForwardAxis = forwardIndex;
195 }
196
197
199 int getUserConstraintType() const
200 {
201 return m_userConstraintType ;
202 }
203
204 void setUserConstraintType(int userConstraintType)
205 {
206 m_userConstraintType = userConstraintType;
207 };
208
209 void setUserConstraintId(int uid)
210 {
211 m_userConstraintId = uid;
212 }
213
214 int getUserConstraintId() const
215 {
216 return m_userConstraintId;
217 }
218
219 };
220
221 class btDefaultVehicleRaycaster : public btVehicleRaycaster
222 {
223 btDynamicsWorld* m_dynamicsWorld;
224 public:
225 btDefaultVehicleRaycaster(btDynamicsWorld* world)
226 :m_dynamicsWorld(world)
227 {
228 }
229
230 virtual void* castRay(const btVector3& from,const btVector3& to, btVehicleRaycasterResult& result);
231
232 };
233
234
235 #endif //BT_RAYCASTVEHICLE_H
236
btRaycastVehicle::~btRaycastVehicle
virtual ~btRaycastVehicle()
Definition: btRaycastVehicle.cpp:57
btRaycastVehicle::m_userConstraintId
int m_userConstraintId
Definition: btRaycastVehicle.h:35
btRaycastVehicle::setSteeringValue
void setSteeringValue(btScalar steering, int wheel)
Definition: btRaycastVehicle.cpp:367
btRaycastVehicle::getUserConstraintId
int getUserConstraintId() const
Definition: btRaycastVehicle.h:214
btRaycastVehicle::getWheelTransformWS
const btTransform & getWheelTransformWS(int wheelIndex) const
Definition: btRaycastVehicle.cpp:95
btRaycastVehicle::m_sideImpulse
btAlignedObjectArray< btScalar > m_sideImpulse
Definition: btRaycastVehicle.h:31
btRaycastVehicle::m_indexRightAxis
int m_indexRightAxis
Definition: btRaycastVehicle.h:70
btAlignedObjectArray< btVector3 >
btRaycastVehicle::m_userConstraintType
int m_userConstraintType
backwards compatibility
Definition: btRaycastVehicle.h:34
btDefaultVehicleRaycaster::castRay
virtual void * castRay(const btVector3 &from, const btVector3 &to, btVehicleRaycasterResult &result)
Definition: btRaycastVehicle.cpp:749
btRaycastVehicle::updateAction
virtual void updateAction(btCollisionWorld *collisionWorld, btScalar step)
btActionInterface interface
Definition: btRaycastVehicle.h:85
btRaycastVehicle::getForwardVector
btVector3 getForwardVector() const
Worldspace forward vector.
Definition: btRaycastVehicle.h:172
btRaycastVehicle::defaultInit
void defaultInit(const btVehicleTuning &tuning)
Definition: btRaycastVehicle.cpp:47
btRaycastVehicle::setUserConstraintId
void setUserConstraintId(int uid)
Definition: btRaycastVehicle.h:209
btRaycastVehicle::setPitchControl
void setPitchControl(btScalar pitch)
Definition: btRaycastVehicle.h:135
btRaycastVehicle::getCurrentSpeedKmHour
btScalar getCurrentSpeedKmHour() const
Velocity of vehicle (positive if velocity vector has same direction as foward vector) ...
Definition: btRaycastVehicle.h:185
btRaycastVehicle::m_currentVehicleSpeedKmHour
btScalar m_currentVehicleSpeedKmHour
Definition: btRaycastVehicle.h:66
btRaycastVehicle::m_wheelInfo
btAlignedObjectArray< btWheelInfo > m_wheelInfo
Definition: btRaycastVehicle.h:123
btDynamicsWorld
The btDynamicsWorld is the interface class for several dynamics implementation, basic, discrete, parallel, and continuous etc.
Definition: btDynamicsWorld.h:41
btActionInterface.h
btRaycastVehicle::m_vehicleRaycaster
btVehicleRaycaster * m_vehicleRaycaster
Definition: btRaycastVehicle.h:63
btRaycastVehicle::applyEngineForce
void applyEngineForce(btScalar force, int wheel)
Definition: btRaycastVehicle.cpp:383
btRaycastVehicle::btVehicleTuning::m_maxSuspensionForce
btScalar m_maxSuspensionForce
Definition: btRaycastVehicle.h:56
btActionInterface
Basic interface to allow actions such as vehicles and characters to be updated inside a btDynamicsWor...
Definition: btActionInterface.h:26
btRaycastVehicle::debugDraw
void debugDraw(btIDebugDraw *debugDrawer)
btActionInterface interface
Definition: btRaycastVehicle.cpp:720
btRaycastVehicle::btVehicleTuning::btVehicleTuning
btVehicleTuning()
Definition: btRaycastVehicle.h:42
btRaycastVehicle::resetSuspension
void resetSuspension()
Definition: btRaycastVehicle.cpp:136
btRigidBody.h
btRaycastVehicle::m_tau
btScalar m_tau
Definition: btRaycastVehicle.h:61
btWheelInfo
btWheelInfo contains information per wheel about friction and suspension.
Definition: btWheelInfo.h:38
btRaycastVehicle::updateVehicle
virtual void updateVehicle(btScalar step)
Definition: btRaycastVehicle.cpp:268
btRaycastVehicle::btVehicleTuning::m_suspensionStiffness
btScalar m_suspensionStiffness
Definition: btRaycastVehicle.h:51
btRaycastVehicle::getChassisWorldTransform
const btTransform & getChassisWorldTransform() const
Definition: btRaycastVehicle.cpp:253
btTypedConstraint.h
btRaycastVehicle::btVehicleTuning::m_frictionSlip
btScalar m_frictionSlip
Definition: btRaycastVehicle.h:55
btRaycastVehicle::getWheelInfo
const btWheelInfo & getWheelInfo(int index) const
Definition: btRaycastVehicle.cpp:391
btAlignedObjectArray::size
int size() const
return the number of elements in the array
Definition: btAlignedObjectArray.h:149
btRaycastVehicle::rayCast
btScalar rayCast(btWheelInfo &wheel)
Definition: btRaycastVehicle.cpp:167
btRaycastVehicle::btVehicleTuning
Definition: btRaycastVehicle.h:38
btRaycastVehicle::btVehicleTuning::m_suspensionDamping
btScalar m_suspensionDamping
Definition: btRaycastVehicle.h:53
btRaycastVehicle::getRigidBody
const btRigidBody * getRigidBody() const
Definition: btRaycastVehicle.h:151
btRaycastVehicle::getUpAxis
int getUpAxis() const
Definition: btRaycastVehicle.h:160
btRaycastVehicle::updateWheelTransformsWS
void updateWheelTransformsWS(btWheelInfo &wheel, bool interpolatedTransform=true)
Definition: btRaycastVehicle.cpp:152
btTransform::getBasis
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:29
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:62
btRaycastVehicle::setCoordinateSystem
virtual void setCoordinateSystem(int rightIndex, int upIndex, int forwardIndex)
Definition: btRaycastVehicle.h:190
btRaycastVehicle
rayCast vehicle, very special constraint that turn a rigidbody into a vehicle.
Definition: btRaycastVehicle.h:25
btVehicleRaycaster.h
btRaycastVehicle::m_indexUpAxis
int m_indexUpAxis
Definition: btRaycastVehicle.h:71
btRaycastVehicle::m_damping
btScalar m_damping
Definition: btRaycastVehicle.h:62
btRaycastVehicle::updateWheelTransform
void updateWheelTransform(int wheelIndex, bool interpolatedTransform=true)
Definition: btRaycastVehicle.cpp:103
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btRaycastVehicle::btVehicleTuning::m_suspensionCompression
btScalar m_suspensionCompression
Definition: btRaycastVehicle.h:52
btRaycastVehicle::getRigidBody
btRigidBody * getRigidBody()
Definition: btRaycastVehicle.h:146
btRaycastVehicle::m_steeringValue
btScalar m_steeringValue
Definition: btRaycastVehicle.h:65
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btRaycastVehicle::getNumWheels
int getNumWheels() const
Definition: btRaycastVehicle.h:119
btCollisionWorld
CollisionWorld is interface and container for the collision detection.
Definition: btCollisionWorld.h:88
btRaycastVehicle::updateSuspension
void updateSuspension(btScalar deltaTime)
Definition: btRaycastVehicle.cpp:412
btRaycastVehicle::m_indexForwardAxis
int m_indexForwardAxis
Definition: btRaycastVehicle.h:72
btRaycastVehicle::btRaycastVehicle
btRaycastVehicle(const btVehicleTuning &tuning, btRigidBody *chassis, btVehicleRaycaster *raycaster)
Definition: btRaycastVehicle.cpp:35
btRaycastVehicle::setUserConstraintType
void setUserConstraintType(int userConstraintType)
Definition: btRaycastVehicle.h:204
btRaycastVehicle::m_pitchControl
btScalar m_pitchControl
Definition: btRaycastVehicle.h:64
btVehicleRaycaster
btVehicleRaycaster is provides interface for between vehicle simulation and raycasting ...
Definition: btVehicleRaycaster.h:17
btAlignedObjectArray.h
btRaycastVehicle::m_chassisBody
btRigidBody * m_chassisBody
Definition: btRaycastVehicle.h:68
btDefaultVehicleRaycaster::m_dynamicsWorld
btDynamicsWorld * m_dynamicsWorld
Definition: btRaycastVehicle.h:223
btRaycastVehicle::getForwardAxis
int getForwardAxis() const
Definition: btRaycastVehicle.h:165
btRaycastVehicle::getUserConstraintType
int getUserConstraintType() const
backwards compatibility
Definition: btRaycastVehicle.h:199
btRaycastVehicle::getRightAxis
int getRightAxis() const
Definition: btRaycastVehicle.h:156
btRaycastVehicle::m_forwardImpulse
btAlignedObjectArray< btScalar > m_forwardImpulse
Definition: btRaycastVehicle.h:30
btWheelInfo.h
btRaycastVehicle::m_axle
btAlignedObjectArray< btVector3 > m_axle
Definition: btRaycastVehicle.h:29
btRaycastVehicle::setBrake
void setBrake(btScalar brake, int wheelIndex)
Definition: btRaycastVehicle.cpp:405
btRaycastVehicle::updateFriction
virtual void updateFriction(btScalar timeStep)
Definition: btRaycastVehicle.cpp:527
btDefaultVehicleRaycaster::btDefaultVehicleRaycaster
btDefaultVehicleRaycaster(btDynamicsWorld *world)
Definition: btRaycastVehicle.h:225
btDefaultVehicleRaycaster
Definition: btRaycastVehicle.h:221
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278
btRaycastVehicle::addWheel
btWheelInfo & addWheel(const btVector3 &connectionPointCS0, const btVector3 &wheelDirectionCS0, const btVector3 &wheelAxleCS, btScalar suspensionRestLength, btScalar wheelRadius, const btVehicleTuning &tuning, bool isFrontWheel)
Definition: btRaycastVehicle.cpp:65
btRaycastVehicle::m_forwardWS
btAlignedObjectArray< btVector3 > m_forwardWS
Definition: btRaycastVehicle.h:28
btRaycastVehicle::getSteeringValue
btScalar getSteeringValue(int wheel) const
Definition: btRaycastVehicle.cpp:377
btRaycastVehicle::btVehicleTuning::m_maxSuspensionTravelCm
btScalar m_maxSuspensionTravelCm
Definition: btRaycastVehicle.h:54