Dura2D  v0.1.0
An educational 2D game physics library
Loading...
Searching...
No Matches
d2World Class Reference

Represents a 2D physics world. More...

#include <d2World.h>

Public Member Functions

 d2World (const d2Vec2 &gravity)
 Constructor that initializes the world with specified gravity.
 
 ~d2World ()
 Destructor to clean up resources.
 
d2BodyCreateBody (const d2Shape &shape, d2Vec2 position, real mass)
 Create a new rigid body with given shape, position, and mass.
 
void DestroyBody (d2Body *body)
 Destroy a body.
 
d2ConstraintCreateJoint (d2Body *bodyA, d2Body *bodyB, d2Vec2 anchorPoint)
 Create a joint between two bodies.
 
void DestroyJoint (d2Constraint *joint)
 Destroy a joint.
 
d2Constraint *& GetConstraints ()
 Get a reference to the list of constraints.
 
int32 GetConstraintCount () const
 Get the number of constraints in the world.
 
void AddForce (const d2Vec2 &force)
 Add an external force to be applied to m_bodiesList.
 
void AddTorque (real torque)
 Add an external torque to be applied to m_bodiesList.
 
void Step (real dt, int32 posIterations=3)
 Update the world simulation by a specified time step.
 
void Solve (real dt)
 Solve the world simulation by a specified time step.
 
void CheckCollisions ()
 Check for collisions between m_bodiesList.
 
d2BodyGetBodies () const
 Get pointer to the array of m_bodiesList.
 
int32 GetBodyCount () const
 Get the number of m_bodiesList in the world.
 
void SetDebugDraw (d2Draw *debugDraw)
 Set the debug draw object.
 
void DrawShape (const d2Body *body, const bool &mesh, const d2Color &color)
 Draw a shape.
 
void DebugDraw ()
 Debug draw the world.
 
 d2World (const d2World &other)=delete
 
d2Worldoperator= (const d2World &other)=delete
 

Public Attributes

d2Vec2 m_gravity {0.0f, -9.8f }
 
d2Broadphasebroadphase
 
d2BlockAllocator m_blockAllocator
 
d2Bodym_bodiesList { nullptr }
 
int32 m_bodyCount { 0 }
 
d2Constraintm_constraints { nullptr }
 
int32 m_constraintCount { 0 }
 
d2Drawm_debugDraw { nullptr }
 

Detailed Description

Represents a 2D physics world.

Constructor & Destructor Documentation

◆ d2World() [1/2]

d2World::d2World ( const d2Vec2 & gravity)
explicit

Constructor that initializes the world with specified gravity.

Parameters
gravityThe gravitational acceleration.

◆ ~d2World()

d2World::~d2World ( )

Destructor to clean up resources.

◆ d2World() [2/2]

d2World::d2World ( const d2World & other)
delete

Member Function Documentation

◆ AddForce()

void d2World::AddForce ( const d2Vec2 & force)

Add an external force to be applied to m_bodiesList.

Parameters
forceThe force to be applied.

◆ AddTorque()

void d2World::AddTorque ( real torque)

Add an external torque to be applied to m_bodiesList.

Parameters
torqueThe torque to be applied.

◆ CheckCollisions()

void d2World::CheckCollisions ( )

Check for collisions between m_bodiesList.

◆ CreateBody()

d2Body * d2World::CreateBody ( const d2Shape & shape,
d2Vec2 position,
real mass )

Create a new rigid body with given shape, position, and mass.

Parameters
shapeThe shape of the body.
positionThe initial position of the body.
massThe mass of the body.
Returns
Pointer to the created body.

◆ CreateJoint()

d2Constraint * d2World::CreateJoint ( d2Body * bodyA,
d2Body * bodyB,
d2Vec2 anchorPoint )

Create a joint between two bodies.

Parameters
bodyAThe first body.
bodyBThe second body.
anchorPointThe anchor point for the joint.
Returns
Pointer to the created joint.

◆ DebugDraw()

void d2World::DebugDraw ( )

Debug draw the world.

◆ DestroyBody()

void d2World::DestroyBody ( d2Body * body)

Destroy a body.

Parameters
bodyThe body to destroy.
Warning
This will automatically remove the body from the world, along with its shape.

◆ DestroyJoint()

void d2World::DestroyJoint ( d2Constraint * joint)

Destroy a joint.

Parameters
jointThe joint to destroy.
Warning
This will automatically remove the joint from the world.

◆ DrawShape()

void d2World::DrawShape ( const d2Body * body,
const bool & mesh,
const d2Color & color )

Draw a shape.

◆ GetBodies()

d2Body * d2World::GetBodies ( ) const
inline

Get pointer to the array of m_bodiesList.

Returns
Pointer to the array of m_bodiesList.

◆ GetBodyCount()

int32 d2World::GetBodyCount ( ) const
inline

Get the number of m_bodiesList in the world.

Returns
The number of m_bodiesList in the world.

◆ GetConstraintCount()

int32 d2World::GetConstraintCount ( ) const
inline

Get the number of constraints in the world.

Returns
The number of constraints in the world.

◆ GetConstraints()

d2Constraint *& d2World::GetConstraints ( )
inline

Get a reference to the list of constraints.

Returns
Reference to the list of constraints.

◆ operator=()

d2World & d2World::operator= ( const d2World & other)
delete

◆ SetDebugDraw()

void d2World::SetDebugDraw ( d2Draw * debugDraw)

Set the debug draw object.

Parameters
debugDrawThe debug draw object.

◆ Solve()

void d2World::Solve ( real dt)

Solve the world simulation by a specified time step.

Parameters
dtThe time step for the solve.

◆ Step()

void d2World::Step ( real dt,
int32 posIterations = 3 )

Update the world simulation by a specified time step.

Parameters
dtThe time step for the update.
posIterationsThe number of position iterations for the update.

Member Data Documentation

◆ broadphase

d2Broadphase* d2World::broadphase

Broad-phase collision detection algorithm.

◆ m_blockAllocator

d2BlockAllocator d2World::m_blockAllocator

Memory m_blockAllocator for small objects.

◆ m_bodiesList

d2Body* d2World::m_bodiesList { nullptr }

Array of m_bodiesList in the world.

◆ m_bodyCount

int32 d2World::m_bodyCount { 0 }

Number of m_bodiesList in the world.

◆ m_constraintCount

int32 d2World::m_constraintCount { 0 }

Number of constraints in the world.

◆ m_constraints

d2Constraint* d2World::m_constraints { nullptr }

List of constraints in the world.

◆ m_debugDraw

d2Draw* d2World::m_debugDraw { nullptr }

Debug draw object.

◆ m_gravity

d2Vec2 d2World::m_gravity {0.0f, -9.8f }

Acceleration due to gravity.


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