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

A class representing a 2D rigid body. More...

#include <d2Body.h>

Public Member Functions

 d2Body (const d2Shape &shape, real x, real y, real mass, d2World *world)
 Constructor for the d2Body class.
 
 ~d2Body ()
 Destructor for the d2Body class.
 
void ComputeAABB ()
 Computes the Axis-Aligned Bounding Box of the body.
 
void AddForce (const d2Vec2 &force)
 Adds a force to the body.
 
void AddTorque (real torque)
 Adds a torque to the body.
 
void ClearForces ()
 Clears all forces applied to the body.
 
void ClearTorque ()
 Clears all torques applied to the body.
 
d2Vec2 LocalSpaceToWorldSpace (const d2Vec2 &point) const
 Converts a point from local space to world space.
 
d2Vec2 WorldSpaceToLocalSpace (const d2Vec2 &point) const
 Converts a point from world space to local space.
 
void ApplyImpulseLinear (const d2Vec2 &j)
 Applies a linear impulse to the body.
 
void ApplyImpulseAngular (const real j)
 Applies an angular impulse to the body.
 
void ApplyImpulseAtPoint (const d2Vec2 &j, const d2Vec2 &r)
 Applies an impulse at a specific point on the body.
 
void IntegrateLinear (real dt)
 Integrates the linear motion of the body over a time step.
 
void IntegrateAngular (real dt)
 Integrates the angular motion of the body over a time step.
 
void IntegrateForces (const real dt)
 Integrates the forces applied to the body over a time step.
 
void IntegrateVelocities (const real dt)
 Integrates the velocities of the body over a time step.
 
const d2Vec2GetPosition () const
 Gets the position of the body.
 
void SetPosition (const d2Vec2 &position)
 Sets the position of the body.
 
const d2Vec2GetVelocity () const
 Gets the velocity of the body.
 
void SetAcceleration (const d2Vec2 &acceleration)
 Set acceleration of the body.
 
void SetAngularVelocity (real angularVelocity)
 Sets the angular velocity of the body.
 
real GetAngularVelocity () const
 Gets the angular velocity of the body.
 
real GetRotation () const
 Gets the rotation angle of the body.
 
real GetMass () const
 Gets the mass of the body.
 
real GetInvMass () const
 Gets the inverse mass of the body.
 
real GetI () const
 Gets the moment of inertia of the body.
 
real GetInvI () const
 Gets the inverse moment of inertia of the body.
 
void SetFriction (real friction)
 Sets the coefficient of friction of the body.
 
real GetFriction () const
 Gets the coefficient of friction of the body.
 
void SetRestitution (real restitution)
 Sets the coefficient of restitution of the body.
 
real GetRestitution () const
 Gets the coefficient of restitution of the body.
 
d2ShapeGetShape () const
 Gets the shape/geometry of the body.
 
d2AABBGetAABB () const
 Gets the Axis-Aligned Bounding Box of the body.
 
d2BodyGetNext ()
 Gets the next body in a linked list of bodies.
 
const d2BodyGetNext () const
 
d2BodyGetPrev ()
 Gets the previous body in a linked list of bodies.
 
const d2BodyGetPrev () const
 
real GetSleepTime () const
 Gets wake-up time of the body.
 
bool IsAwake () const
 Gets the wake state of the body.
 
void SetAwake (bool awake)
 Sets the wake state of the body.
 
real GetGravityScale () const
 Gets the gravity scale of the body.
 
void SetGravityScale (real gravityScale)
 Sets the gravity scale of the body.
 

Friends

class d2World
 

Detailed Description

A class representing a 2D rigid body.

This class encapsulates the properties and behaviors of a 2D rigid body.

Constructor & Destructor Documentation

◆ d2Body()

d2Body::d2Body ( const d2Shape & shape,
real x,
real y,
real mass,
d2World * world )

Constructor for the d2Body class.

Parameters
shapeThe shape/geometry of the body.
xThe initial x-coordinate of the body.
yThe initial y-coordinate of the body.
massThe mass of the body.

◆ ~d2Body()

d2Body::~d2Body ( )

Destructor for the d2Body class.

Member Function Documentation

◆ AddForce()

void d2Body::AddForce ( const d2Vec2 & force)

Adds a force to the body.

Parameters
forceThe force to be added.

◆ AddTorque()

void d2Body::AddTorque ( real torque)

Adds a torque to the body.

Parameters
torqueThe torque to be added.

◆ ApplyImpulseAngular()

void d2Body::ApplyImpulseAngular ( const real j)

Applies an angular impulse to the body.

Parameters
jThe impulse to be applied.

◆ ApplyImpulseAtPoint()

void d2Body::ApplyImpulseAtPoint ( const d2Vec2 & j,
const d2Vec2 & r )

Applies an impulse at a specific point on the body.

Parameters
jThe impulse to be applied.
rThe point at which the impulse is applied.

◆ ApplyImpulseLinear()

void d2Body::ApplyImpulseLinear ( const d2Vec2 & j)

Applies a linear impulse to the body.

Parameters
jThe impulse to be applied.

◆ ClearForces()

void d2Body::ClearForces ( )

Clears all forces applied to the body.

◆ ClearTorque()

void d2Body::ClearTorque ( )

Clears all torques applied to the body.

◆ ComputeAABB()

void d2Body::ComputeAABB ( )

Computes the Axis-Aligned Bounding Box of the body.

◆ GetAABB()

d2AABB * d2Body::GetAABB ( ) const
inline

Gets the Axis-Aligned Bounding Box of the body.

Returns
A pointer to the Axis-Aligned Bounding Box of the body.

◆ GetAngularVelocity()

real d2Body::GetAngularVelocity ( ) const
inline

Gets the angular velocity of the body.

Returns
The angular velocity of the body.

◆ GetFriction()

real d2Body::GetFriction ( ) const
inline

Gets the coefficient of friction of the body.

Returns
The coefficient of friction of the body.

◆ GetGravityScale()

real d2Body::GetGravityScale ( ) const
inline

Gets the gravity scale of the body.

◆ GetI()

real d2Body::GetI ( ) const
inline

Gets the moment of inertia of the body.

Returns
The moment of inertia of the body.

◆ GetInvI()

real d2Body::GetInvI ( ) const
inline

Gets the inverse moment of inertia of the body.

Returns
The inverse moment of inertia of the body.

◆ GetInvMass()

real d2Body::GetInvMass ( ) const
inline

Gets the inverse mass of the body.

Returns
The inverse mass of the body.

◆ GetMass()

real d2Body::GetMass ( ) const
inline

Gets the mass of the body.

Returns
The mass of the body.

◆ GetNext() [1/2]

d2Body * d2Body::GetNext ( )
inline

Gets the next body in a linked list of bodies.

Returns
A pointer to the next body in a linked list of bodies.

◆ GetNext() [2/2]

const d2Body * d2Body::GetNext ( ) const
inline

◆ GetPosition()

const d2Vec2 & d2Body::GetPosition ( ) const
inline

Gets the position of the body.

Returns
The position of the body.

◆ GetPrev() [1/2]

d2Body * d2Body::GetPrev ( )
inline

Gets the previous body in a linked list of bodies.

Returns
A pointer to the previous body in a linked list of bodies.

◆ GetPrev() [2/2]

const d2Body * d2Body::GetPrev ( ) const
inline

◆ GetRestitution()

real d2Body::GetRestitution ( ) const
inline

Gets the coefficient of restitution of the body.

Returns
The coefficient of restitution of the body.

◆ GetRotation()

real d2Body::GetRotation ( ) const
inline

Gets the rotation angle of the body.

Returns
The rotation angle of the body.

◆ GetShape()

d2Shape * d2Body::GetShape ( ) const
inline

Gets the shape/geometry of the body.

Returns
A pointer to the shape/geometry of the body.

◆ GetSleepTime()

real d2Body::GetSleepTime ( ) const
inline

Gets wake-up time of the body.

Returns
The wake-up time of the body.

◆ GetVelocity()

const d2Vec2 & d2Body::GetVelocity ( ) const
inline

Gets the velocity of the body.

Returns
The velocity of the body.

◆ IntegrateAngular()

void d2Body::IntegrateAngular ( real dt)

Integrates the angular motion of the body over a time step.

Parameters
dtThe time step.

◆ IntegrateForces()

void d2Body::IntegrateForces ( const real dt)

Integrates the forces applied to the body over a time step.

Parameters
dtThe time step.

◆ IntegrateLinear()

void d2Body::IntegrateLinear ( real dt)

Integrates the linear motion of the body over a time step.

Parameters
dtThe time step.

◆ IntegrateVelocities()

void d2Body::IntegrateVelocities ( const real dt)

Integrates the velocities of the body over a time step.

Parameters
dtThe time step.

◆ IsAwake()

bool d2Body::IsAwake ( ) const
inline

Gets the wake state of the body.

Returns
The wake state of the body.

◆ LocalSpaceToWorldSpace()

d2Vec2 d2Body::LocalSpaceToWorldSpace ( const d2Vec2 & point) const

Converts a point from local space to world space.

Parameters
pointThe point in local space.
Returns
The point in world space.

◆ SetAcceleration()

void d2Body::SetAcceleration ( const d2Vec2 & acceleration)
inline

Set acceleration of the body.

◆ SetAngularVelocity()

void d2Body::SetAngularVelocity ( real angularVelocity)
inline

Sets the angular velocity of the body.

◆ SetAwake()

void d2Body::SetAwake ( bool awake)
inline

Sets the wake state of the body.

Parameters
awakeThe wake state of the body.

◆ SetFriction()

void d2Body::SetFriction ( real friction)
inline

Sets the coefficient of friction of the body.

◆ SetGravityScale()

void d2Body::SetGravityScale ( real gravityScale)
inline

Sets the gravity scale of the body.

◆ SetPosition()

void d2Body::SetPosition ( const d2Vec2 & position)
inline

Sets the position of the body.

Parameters
positionThe position of the body.

◆ SetRestitution()

void d2Body::SetRestitution ( real restitution)
inline

Sets the coefficient of restitution of the body.

◆ WorldSpaceToLocalSpace()

d2Vec2 d2Body::WorldSpaceToLocalSpace ( const d2Vec2 & point) const

Converts a point from world space to local space.

Parameters
pointThe point in world space.
Returns
The point in local space.

Friends And Related Symbol Documentation

◆ d2World

friend class d2World
friend

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