SuperTuxKart
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Physics Class Reference
Inheritance diagram for Physics:
Inheritance graph
[legend]

Classes

class  CollisionList
 
class  CollisionPair
 Bullet can report the same collision more than once (up to 4 contact points per collision. More...
 

Public Member Functions

void init (const Vec3 &min_world, const Vec3 &max_world)
 The actual initialisation of the physics, which is called after the track model is loaded.
 
void addKart (const AbstractKart *k)
 Adds a kart to the physics engine.
 
void addBody (btRigidBody *b)
 
void removeKart (const AbstractKart *k)
 Removes a kart from the physics engine.
 
void removeBody (btRigidBody *b)
 
void KartKartCollision (AbstractKart *ka, const Vec3 &contact_point_a, AbstractKart *kb, const Vec3 &contact_point_b)
 Handles the special case of two karts colliding with each other, which means that bombs must be passed on.
 
void update (int ticks)
 Updates the physics simulation and handles all collisions.
 
void draw ()
 A debug draw function to show the track and all karts.
 
STKDynamicsWorldgetPhysicsWorld () const
 
void nextDebugMode ()
 Activates the next debug mode (or switches it off again).
 
void setDebugMode (IrrDebugDrawer::DebugModeType mode)
 
bool isDebug () const
 Returns true if the debug drawer is enabled.
 
IrrDebugDrawergetDebugDrawer ()
 
virtual btScalar solveGroup (btCollisionObject **bodies, int numBodies, btPersistentManifold **manifold, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &info, btIDebugDraw *debugDrawer, btStackAlloc *stackAlloc, btDispatcher *dispatcher)
 This function is called at each internal bullet timestep.
 

Static Public Member Functions

static Physicsget ()
 
static void create ()
 
static void destroy ()
 

Private Member Functions

 Physics ()
 Initialise physics.
 

Private Attributes

bool m_physics_loop_active
 This flag is set while bullets time step processing is taking place.
 
std::vector< const AbstractKart * > m_karts_to_delete
 If kart need to be removed from the physics world while physics processing is taking place, store the pointers to the karts to be removed here, and remove them once the physics processing is finished.
 
STKDynamicsWorldm_dynamics_world
 Pointer to the physics dynamics world.
 
IrrDebugDrawerm_debug_drawer
 Used in physics debugging to draw the physics world.
 
btCollisionDispatcher * m_dispatcher
 
btBroadphaseInterface * m_axis_sweep
 
btDefaultCollisionConfiguration * m_collision_conf
 
CollisionList m_all_collisions
 

Constructor & Destructor Documentation

◆ Physics()

Physics::Physics ( )
private

Initialise physics.

Create the bullet dynamics world.

Member Function Documentation

◆ addKart()

void Physics::addKart ( const AbstractKart kart)

Adds a kart to the physics engine.

This adds the rigid body and the vehicle but only if the kart is not already in the physics world.

Parameters
kartThe kart to add.
vehicleThe raycast vehicle object.

◆ init()

void Physics::init ( const Vec3 world_min,
const Vec3 world_max 
)

The actual initialisation of the physics, which is called after the track model is loaded.

This allows the physics to use the actual track dimension for the axis sweep.

◆ KartKartCollision()

void Physics::KartKartCollision ( AbstractKart kart_a,
const Vec3 contact_point_a,
AbstractKart kart_b,
const Vec3 contact_point_b 
)

Handles the special case of two karts colliding with each other, which means that bombs must be passed on.

If both karts have a bomb, they'll explode immediately. This function is called from physics::update() on the server and if no networking is used, and from race_state on the client to replay what happened on the server.

Parameters
kart_aFirst kart involved in the collision.
contact_point_aLocation of collision at first kart (in kart coordinates).
kart_bSecond kart involved in the collision.
contact_point_bLocation of collision at second kart (in kart coordinates).

◆ removeKart()

void Physics::removeKart ( const AbstractKart kart)

Removes a kart from the physics engine.

This is used when rescuing a kart (and during cleanup).

Parameters
kartThe kart to remove.

◆ solveGroup()

btScalar Physics::solveGroup ( btCollisionObject **  bodies,
int  numBodies,
btPersistentManifold **  manifold,
int  numManifolds,
btTypedConstraint **  constraints,
int  numConstraints,
const btContactSolverInfo &  info,
btIDebugDraw *  debugDrawer,
btStackAlloc *  stackAlloc,
btDispatcher *  dispatcher 
)
virtual

This function is called at each internal bullet timestep.

It is used here to do the collision handling: using the contact manifolds after a physics time step might miss some collisions (when more than one internal time step was done, and the collision is added and removed). So this function stores all collisions in a list, which is then handled after the actual physics timestep. This list only stores a collision if it's not already in the list, so a collisions which is reported more than once is nevertheless only handled once. The list of collision Parameters: see bullet documentation for details.

◆ update()

void Physics::update ( int  ticks)

Updates the physics simulation and handles all collisions.

Parameters
ticksNumber of physics steps to simulate.

Member Data Documentation

◆ m_physics_loop_active

bool Physics::m_physics_loop_active
private

This flag is set while bullets time step processing is taking place.

It is used to avoid altering data structures that might be used (e.g. removing a kart while a loop over all karts is taking place, as can happen in collision handling).


The documentation for this class was generated from the following files: