Bullet Collision Detection & Physics Library
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
16#include "btVehicleRaycaster.h"
17class btDynamicsWorld;
19#include "btWheelInfo.h"
21
22//class btVehicleTuning;
23
26{
31
35
36public:
38 {
39 public:
47 {
48 }
55 };
56
57private:
62
64
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
88
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
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
125 {
126 m_pitchControl = pitch;
127 }
128
129 void updateSuspension(btScalar deltaTime);
130
131 virtual void updateFriction(btScalar timeStep);
132
134 {
135 return m_chassisBody;
136 }
137
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
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
172 {
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
185 {
187 }
188
189 void setUserConstraintType(int userConstraintType)
190 {
191 m_userConstraintType = userConstraintType;
192 };
193
195 {
196 m_userConstraintId = uid;
197 }
198
200 {
201 return m_userConstraintId;
202 }
203};
204
206{
208
209public:
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
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
Basic interface to allow actions such as vehicles and characters to be updated inside a btDynamicsWor...
int size() const
return the number of elements in the array
CollisionWorld is interface and container for the collision detection.
virtual void * castRay(const btVector3 &from, const btVector3 &to, btVehicleRaycasterResult &result)
btDefaultVehicleRaycaster(btDynamicsWorld *world)
btDynamicsWorld * m_dynamicsWorld
The btDynamicsWorld is the interface class for several dynamics implementation, basic,...
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:27
rayCast vehicle, very special constraint that turn a rigidbody into a vehicle.
btAlignedObjectArray< btVector3 > m_forwardWS
virtual void updateFriction(btScalar timeStep)
void defaultInit(const btVehicleTuning &tuning)
void updateWheelTransformsWS(btWheelInfo &wheel, bool interpolatedTransform=true)
int getUserConstraintType() const
backwards compatibility
virtual void updateAction(btCollisionWorld *collisionWorld, btScalar step)
btActionInterface interface
btVector3 getForwardVector() const
Worldspace forward vector.
int getUpAxis() const
btRigidBody * getRigidBody()
btAlignedObjectArray< btScalar > m_sideImpulse
const btTransform & getWheelTransformWS(int wheelIndex) const
int getNumWheels() const
int getUserConstraintId() const
virtual void setCoordinateSystem(int rightIndex, int upIndex, int forwardIndex)
btScalar m_currentVehicleSpeedKmHour
btScalar rayCast(btWheelInfo &wheel)
int m_userConstraintType
backwards compatibility
void setUserConstraintType(int userConstraintType)
btScalar getSteeringValue(int wheel) const
const btRigidBody * getRigidBody() const
void setBrake(btScalar brake, int wheelIndex)
void updateSuspension(btScalar deltaTime)
virtual ~btRaycastVehicle()
btAlignedObjectArray< btVector3 > m_axle
btRaycastVehicle(const btVehicleTuning &tuning, btRigidBody *chassis, btVehicleRaycaster *raycaster)
int getRightAxis() const
btVehicleRaycaster * m_vehicleRaycaster
virtual void updateVehicle(btScalar step)
btScalar m_steeringValue
btAlignedObjectArray< btScalar > m_forwardImpulse
btAlignedObjectArray< btWheelInfo > m_wheelInfo
btRigidBody * m_chassisBody
void applyEngineForce(btScalar force, int wheel)
void setPitchControl(btScalar pitch)
btWheelInfo & addWheel(const btVector3 &connectionPointCS0, const btVector3 &wheelDirectionCS0, const btVector3 &wheelAxleCS, btScalar suspensionRestLength, btScalar wheelRadius, const btVehicleTuning &tuning, bool isFrontWheel)
void debugDraw(btIDebugDraw *debugDrawer)
btActionInterface interface
int getForwardAxis() const
void setUserConstraintId(int uid)
const btTransform & getChassisWorldTransform() const
void updateWheelTransform(int wheelIndex, bool interpolatedTransform=true)
const btWheelInfo & getWheelInfo(int index) const
btScalar getCurrentSpeedKmHour() const
Velocity of vehicle (positive if velocity vector has same direction as foward vector)
void setSteeringValue(btScalar steering, int wheel)
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:60
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:109
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btVehicleRaycaster is provides interface for between vehicle simulation and raycasting
btWheelInfo contains information per wheel about friction and suspension.
Definition: btWheelInfo.h:38