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