Dura2D
v0.1.0
An educational 2D game physics library
|
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. | |
d2Body * | CreateBody (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. | |
d2Constraint * | CreateJoint (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. | |
d2Body * | GetBodies () 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 | |
d2World & | operator= (const d2World &other)=delete |
Public Attributes | |
d2Vec2 | m_gravity {0.0f, -9.8f } |
d2Broadphase * | broadphase |
d2BlockAllocator | m_blockAllocator |
d2Body * | m_bodiesList { nullptr } |
int32 | m_bodyCount { 0 } |
d2Constraint * | m_constraints { nullptr } |
int32 | m_constraintCount { 0 } |
d2Draw * | m_debugDraw { nullptr } |
Represents a 2D physics world.
|
explicit |
Constructor that initializes the world with specified gravity.
gravity | The gravitational acceleration. |
d2World::~d2World | ( | ) |
Destructor to clean up resources.
|
delete |
void d2World::AddForce | ( | const d2Vec2 & | force | ) |
Add an external force to be applied to m_bodiesList.
force | The force to be applied. |
void d2World::AddTorque | ( | real | torque | ) |
Add an external torque to be applied to m_bodiesList.
torque | The torque to be applied. |
void d2World::CheckCollisions | ( | ) |
Check for collisions between m_bodiesList.
Create a new rigid body with given shape, position, and mass.
shape | The shape of the body. |
position | The initial position of the body. |
mass | The mass of the body. |
d2Constraint * d2World::CreateJoint | ( | d2Body * | bodyA, |
d2Body * | bodyB, | ||
d2Vec2 | anchorPoint ) |
Create a joint between two bodies.
bodyA | The first body. |
bodyB | The second body. |
anchorPoint | The anchor point for the joint. |
void d2World::DebugDraw | ( | ) |
Debug draw the world.
void d2World::DestroyBody | ( | d2Body * | body | ) |
Destroy a body.
body | The body to destroy. |
void d2World::DestroyJoint | ( | d2Constraint * | joint | ) |
Destroy a joint.
joint | The joint to destroy. |
Draw a shape.
|
inline |
Get pointer to the array of m_bodiesList.
|
inline |
Get the number of m_bodiesList in the world.
|
inline |
Get the number of constraints in the world.
|
inline |
Get a reference to the list of constraints.
void d2World::SetDebugDraw | ( | d2Draw * | debugDraw | ) |
Set the debug draw object.
debugDraw | The debug draw object. |
void d2World::Solve | ( | real | dt | ) |
Solve the world simulation by a specified time step.
dt | The time step for the solve. |
Update the world simulation by a specified time step.
dt | The time step for the update. |
posIterations | The number of position iterations for the update. |
d2Broadphase* d2World::broadphase |
Broad-phase collision detection algorithm.
d2BlockAllocator d2World::m_blockAllocator |
Memory m_blockAllocator for small objects.
d2Body* d2World::m_bodiesList { nullptr } |
Array of m_bodiesList in the world.
int32 d2World::m_bodyCount { 0 } |
Number of m_bodiesList in the world.
int32 d2World::m_constraintCount { 0 } |
Number of constraints in the world.
d2Constraint* d2World::m_constraints { nullptr } |
List of constraints in the world.
d2Draw* d2World::m_debugDraw { nullptr } |
Debug draw object.
d2Vec2 d2World::m_gravity {0.0f, -9.8f } |
Acceleration due to gravity.