SuperTuxKart
Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | 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. More...
 
void addKart (const AbstractKart *k)
 Adds a kart to the physics engine. More...
 
void addBody (btRigidBody *b)
 
void removeKart (const AbstractKart *k)
 Removes a kart from the physics engine. More...
 
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. More...
 
void update (int ticks)
 Updates the physics simulation and handles all collisions. More...
 
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. More...
 
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. More...
 

Private Member Functions

 Physics ()
 Initialise physics. More...
 

Private Attributes

bool m_physics_loop_active
 This flag is set while bullets time step processing is taking place. More...
 
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. More...
 
STKDynamicsWorldm_dynamics_world
 Pointer to the physics dynamics world. More...
 
IrrDebugDrawerm_debug_drawer
 Used in physics debugging to draw the physics world. More...
 
btCollisionDispatcher * m_dispatcher
 
btBroadphaseInterface * m_axis_sweep
 
btDefaultCollisionConfiguration * m_collision_conf
 
CollisionList m_all_collisions
 

Static Private Attributes

static Physicsm_physics
 Singleton. More...
 

Friends

class AbstractSingleton< Physics >
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractSingleton< Physics >
static S * getInstance ()
 Used to get the instance, after a dynamic cast. This is important when making a double-inheritance of this class. For example, if A is a singleton inherited by B, you can call B::getInstance<A>() to have the instance returned as a A*. If the cast fails, a log message will notify it.
 
static PhysicsgetInstance ()
 Used to get the instance.
 
static void kill ()
 Used to kill the singleton, if needed.
 
- Protected Member Functions inherited from AbstractSingleton< Physics >
 AbstractSingleton ()
 Constructor.
 
virtual ~AbstractSingleton ()
 Destructor.
 

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.

◆ isDebug()

bool Physics::isDebug ( ) const
inline

Returns true if the debug drawer is enabled.

◆ 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_debug_drawer

IrrDebugDrawer* Physics::m_debug_drawer
private

Used in physics debugging to draw the physics world.

◆ m_dynamics_world

STKDynamicsWorld* Physics::m_dynamics_world
private

Pointer to the physics dynamics world.

◆ m_karts_to_delete

std::vector<const AbstractKart*> Physics::m_karts_to_delete
private

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.

◆ m_physics

Physics* Physics::m_physics
staticprivate

◆ 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: