14#include "BulletDynamics/Dynamics/btRigidBody.h"
15#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
16#include "physics/btKartRaycast.hpp"
18#include "LinearMath/btAlignedObjectArray.h"
19#include "BulletDynamics/Vehicle/btWheelInfo.h"
20#include "BulletDynamics/Dynamics/btActionInterface.h"
22#include "config/stk_config.hpp"
31class btKart :
public btActionInterface
39 :m_suspensionStiffness(btScalar(5.88)),
40 m_suspensionCompression(btScalar(0.83)),
41 m_suspensionDamping(btScalar(0.88)),
42 m_maxSuspensionTravel(btScalar(5.)),
43 m_frictionSlip(btScalar(10.5)),
44 m_maxSuspensionForce(btScalar(6000.))
48 btScalar m_suspensionStiffness;
49 btScalar m_suspensionCompression;
50 btScalar m_suspensionDamping;
51 btScalar m_maxSuspensionTravel;
52 btScalar m_frictionSlip;
53 btScalar m_maxSuspensionForce;
59 btAlignedObjectArray<btVector3> m_forwardWS;
60 btAlignedObjectArray<btVector3> m_axle;
61 btAlignedObjectArray<btScalar> m_forwardImpulse;
62 btAlignedObjectArray<btScalar> m_sideImpulse;
66 int m_userConstraintId;
68 static btRigidBody& getFixedBody();
72 btVehicleRaycaster *m_vehicleRaycaster;
125 btAlignedObjectArray<btWheelInfo> m_wheelInfo;
128 btScalar rayCast(btWheelInfo& wheel,
const btVector3& ray);
129 void updateWheelTransformsWS(btWheelInfo& wheel,
130 btTransform chassis_trans,
131 bool interpolatedTransform=
true,
132 float fraction = 1.0f);
142 btKart(btRigidBody* chassis,
143 btVehicleRaycaster* raycaster,
147 void debugDraw(btIDebugDraw* debugDrawer);
148 const btTransform& getChassisWorldTransform()
const;
149 btScalar rayCast(
unsigned int index,
float fraction=1.0f);
150 virtual void updateVehicle(btScalar step);
151 void resetSuspension();
152 btScalar getSteeringValue(
int wheel)
const;
153 void setSteeringValue(btScalar steering,
int wheel);
154 void applyEngineForce(btScalar force,
int wheel);
155 const btTransform& getWheelTransformWS(
int wheelIndex )
const;
156 void updateWheelTransform(
int wheelIndex,
157 bool interpolatedTransform=
true);
158 btWheelInfo& addWheel(
const btVector3& connectionPointCS0,
159 const btVector3& wheelDirectionCS0,
160 const btVector3& wheelAxleCS,
161 btScalar suspensionRestLength,
162 btScalar wheelRadius,
165 const btWheelInfo& getWheelInfo(
int index)
const;
166 btWheelInfo& getWheelInfo(
int index);
168 void setAllBrakes(btScalar brake);
169 void updateSuspension(btScalar deltaTime);
170 virtual void updateFriction(btScalar timeStep);
172 void instantSpeedIncreaseTo(btScalar speed);
173 void adjustSpeed(btScalar min_speed, btScalar max_speed);
174 void updateAllWheelPositions();
176 btVector3 *left, btVector3 *right);
188 (void) collisionWorld;
213 void setUserConstraintType(
int userConstraintType)
218 void setUserConstraintId(
int uid) { m_userConstraintId = uid; }
220 int getUserConstraintId()
const {
return m_userConstraintId; }
241 const btVector3& getAdditionalImpulse()
const
260 uint16_t getTimedRotationTicks()
const
271 if(m_max_speed <0 || m_max_speed > new_max_speed)
The main kart class.
Definition: kart.hpp:69
float ticks2Time(int ticks)
Converts a tick value (in physics time step size) into seconds.
Definition: stk_config.hpp:313
Definition: btKart.hpp:35
rayCast vehicle, very special constraint that turn a rigidbody into a vehicle.
Definition: btKart.hpp:32
btRigidBody * m_chassisBody
The rigid body that is the chassis of the kart.
Definition: btKart.hpp:93
btScalar m_max_speed
Maximum speed for the kart.
Definition: btKart.hpp:120
virtual void updateAction(btCollisionWorld *collisionWorld, btScalar step)
btActionInterface interface.
Definition: btKart.hpp:185
btScalar getMinSpeed() const
Returns the minimum speed for this kart.
Definition: btKart.hpp:286
void setTimedRotation(uint16_t t, float rot_in_y_axis)
Sets a rotation that is applied over a certain amount of time (to avoid a too rapid changes in the ka...
Definition: btKart.hpp:248
void setMaxSpeed(float new_max_speed)
Sets the maximum speed for this kart.
Definition: btKart.hpp:264
void reset()
Resets the kart before a (re)start, to make sure all physics variable are properly defined.
Definition: btKart.cpp:105
btRigidBody m_fixed_body
Used to replace the ground object.
Definition: btKart.hpp:96
int getRightAxis() const
Returns the index of the right axis.
Definition: btKart.hpp:202
bool m_visual_wheels_touch_ground
True if the visual wheels touch the ground.
Definition: btKart.hpp:123
btScalar m_min_speed
Minimum speed for the kart.
Definition: btKart.hpp:116
Kart * m_kart
The STK kart object which uses this vehicle.
Definition: btKart.hpp:111
void updateAllWheelTransformsWS()
Updates all wheel transform informations.
Definition: btKart.cpp:212
int m_userConstraintType
backwards compatibility
Definition: btKart.hpp:65
uint16_t getCentralImpulseTicks() const
Returns the time an additional impulse is activated.
Definition: btKart.hpp:238
int getNumWheels() const
Returns the number of wheels of this vehicle.
Definition: btKart.hpp:193
void getVisualContactPoint(const btTransform &chassis_trans, btVector3 *left, btVector3 *right)
Returns the contact point of a visual wheel.
Definition: btKart.cpp:366
bool visualWheelsTouchGround() const
Returns true if both rear visual wheels touch the ground.
Definition: btKart.hpp:179
uint16_t m_ticks_additional_rotation
Duration over which the additional rotation is applied.
Definition: btKart.hpp:90
void setTimedCentralImpulse(uint16_t t, const btVector3 &imp, bool rewind=false)
Sets an impulse that is applied for a certain amount of time.
Definition: btKart.hpp:228
virtual void resetMaxSpeed()
Resets the maximum so any new maximum value from the application will be accepted.
Definition: btKart.hpp:277
btRigidBody * getRigidBody()
Returns the chassis (rigid) body.
Definition: btKart.hpp:196
const btRigidBody * getRigidBody() const
Returns the chassis (rigid) body.
Definition: btKart.hpp:199
int getForwardAxis() const
Returns the index of the forward axis.
Definition: btKart.hpp:208
int m_indexRightAxis
Index of the right axis.
Definition: btKart.hpp:102
void setMinSpeed(float s)
Sets the minimum speed for this kart.
Definition: btKart.hpp:280
int m_indexUpAxis
Index of the up axis.
Definition: btKart.hpp:104
float m_additional_rotation
Additional rotation in y-axis that is applied over a certain amount of time.
Definition: btKart.hpp:87
int getUserConstraintType() const
Backwards compatibility.
Definition: btKart.hpp:211
uint16_t m_ticks_additional_impulse
The time the additional impulse should be applied.
Definition: btKart.hpp:84
int m_num_wheels_on_ground
Number of wheels that touch the ground.
Definition: btKart.hpp:99
int m_indexForwardAxis
Index of the forward axis.
Definition: btKart.hpp:106
btVector3 m_additional_impulse
An additional impulse that is applied for a certain amount of time.
Definition: btKart.hpp:81
unsigned int getNumWheelsOnGround() const
Returns the number of wheels on the ground.
Definition: btKart.hpp:223
void adjustSpeed(btScalar min_speed, btScalar max_speed)
Adjusts the velocity of this kart to be at least the specified minimum, and less than or equal to the...
Definition: btKart.cpp:963
bool m_allow_sliding
Sliding (skidding) will only be permited when this is true.
Definition: btKart.hpp:78
void setSliding(bool active)
Enables or disables sliding.
Definition: btKart.cpp:951
int getUpAxis() const
Returns the index of the up axis.
Definition: btKart.hpp:205