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