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 
67 
69 
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 
96 
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 
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 
136  {
137  m_pitchControl = pitch;
138  }
139 
140  void updateSuspension(btScalar deltaTime);
141 
142  virtual void updateFriction(btScalar timeStep);
143 
144 
145 
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 
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 
186  {
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 
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 
215  {
216  return m_userConstraintId;
217  }
218 
219 };
220 
222 {
224 public:
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 
virtual ~btRaycastVehicle()
void setSteeringValue(btScalar steering, int wheel)
int getUserConstraintId() const
const btTransform & getWheelTransformWS(int wheelIndex) const
btAlignedObjectArray< btScalar > m_sideImpulse
int m_userConstraintType
backwards compatibility
virtual void * castRay(const btVector3 &from, const btVector3 &to, btVehicleRaycasterResult &result)
virtual void updateAction(btCollisionWorld *collisionWorld, btScalar step)
btActionInterface interface
btVector3 getForwardVector() const
Worldspace forward vector.
void defaultInit(const btVehicleTuning &tuning)
void setUserConstraintId(int uid)
void setPitchControl(btScalar pitch)
btScalar getCurrentSpeedKmHour() const
Velocity of vehicle (positive if velocity vector has same direction as foward vector) ...
btScalar m_currentVehicleSpeedKmHour
btAlignedObjectArray< btWheelInfo > m_wheelInfo
The btDynamicsWorld is the interface class for several dynamics implementation, basic, discrete, parallel, and continuous etc.
btVehicleRaycaster * m_vehicleRaycaster
void applyEngineForce(btScalar force, int wheel)
Basic interface to allow actions such as vehicles and characters to be updated inside a btDynamicsWor...
void debugDraw(btIDebugDraw *debugDrawer)
btActionInterface interface
btWheelInfo contains information per wheel about friction and suspension.
Definition: btWheelInfo.h:38
virtual void updateVehicle(btScalar step)
const btTransform & getChassisWorldTransform() const
const btWheelInfo & getWheelInfo(int index) const
int size() const
return the number of elements in the array
btScalar rayCast(btWheelInfo &wheel)
const btRigidBody * getRigidBody() const
int getUpAxis() const
void updateWheelTransformsWS(btWheelInfo &wheel, bool interpolatedTransform=true)
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:28
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:59
virtual void setCoordinateSystem(int rightIndex, int upIndex, int forwardIndex)
rayCast vehicle, very special constraint that turn a rigidbody into a vehicle.
void updateWheelTransform(int wheelIndex, bool interpolatedTransform=true)
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btRigidBody * getRigidBody()
btScalar m_steeringValue
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
int getNumWheels() const
CollisionWorld is interface and container for the collision detection.
void updateSuspension(btScalar deltaTime)
btRaycastVehicle(const btVehicleTuning &tuning, btRigidBody *chassis, btVehicleRaycaster *raycaster)
void setUserConstraintType(int userConstraintType)
btVehicleRaycaster is provides interface for between vehicle simulation and raycasting ...
btRigidBody * m_chassisBody
btDynamicsWorld * m_dynamicsWorld
int getForwardAxis() const
int getUserConstraintType() const
backwards compatibility
int getRightAxis() const
btAlignedObjectArray< btScalar > m_forwardImpulse
btAlignedObjectArray< btVector3 > m_axle
void setBrake(btScalar brake, int wheelIndex)
virtual void updateFriction(btScalar timeStep)
btDefaultVehicleRaycaster(btDynamicsWorld *world)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266
btWheelInfo & addWheel(const btVector3 &connectionPointCS0, const btVector3 &wheelDirectionCS0, const btVector3 &wheelAxleCS, btScalar suspensionRestLength, btScalar wheelRadius, const btVehicleTuning &tuning, bool isFrontWheel)
btAlignedObjectArray< btVector3 > m_forwardWS
btScalar getSteeringValue(int wheel) const