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