139 inline const d2Vec2& GetPosition()
const;
146 inline void SetPosition(
const d2Vec2& position);
153 inline const d2Vec2& GetVelocity()
const;
156 inline void SetAcceleration(
const d2Vec2& acceleration);
159 inline void SetAngularVelocity(
real angularVelocity);
166 inline real GetAngularVelocity()
const;
173 inline real GetRotation()
const;
180 inline real GetMass()
const;
187 inline real GetInvMass()
const;
194 inline real GetI()
const;
201 inline real GetInvI()
const;
204 inline void SetFriction(
real friction);
211 inline real GetFriction()
const;
214 inline void SetRestitution(
real restitution);
221 inline real GetRestitution()
const;
228 inline d2Shape* GetShape()
const;
235 inline d2AABB* GetAABB()
const;
243 inline const d2Body* GetNext()
const;
251 inline const d2Body* GetPrev()
const;
258 inline real GetSleepTime()
const;
265 inline bool IsAwake()
const;
272 inline void SetAwake(
bool awake);
275 inline real GetGravityScale()
const;
278 inline void SetGravityScale(
real gravityScale);
296 real m_gravityScale{ 1.0f };
298 real angularVelocity {};
299 real angularAcceleration {};
326 return m_transform.
p;
331 m_transform.
p = position;
341 this->acceleration = acceleration;
346 this->angularVelocity = angularVelocity;
351 return angularVelocity;
381 this->friction = friction;
391 this->restitution = restitution;
436 return m_gravityScale;
441 m_gravityScale = gravityScale;
446 return (m_flags & e_awakeFlag) == e_awakeFlag;
453 m_flags |= e_awakeFlag;
458 m_flags &= ~e_awakeFlag;
461 angularVelocity = 0.0f;
A class representing a 2D rigid body.
Definition d2Body.h:28
const d2Vec2 & GetPosition() const
Gets the position of the body.
Definition d2Body.h:324
void IntegrateLinear(real dt)
Integrates the linear motion of the body over a time step.
const d2Vec2 & GetVelocity() const
Gets the velocity of the body.
Definition d2Body.h:334
void SetGravityScale(real gravityScale)
Sets the gravity scale of the body.
Definition d2Body.h:439
real GetMass() const
Gets the mass of the body.
Definition d2Body.h:359
void ClearForces()
Clears all forces applied to the body.
d2Body * GetNext()
Gets the next body in a linked list of bodies.
Definition d2Body.h:409
void ApplyImpulseLinear(const d2Vec2 &j)
Applies a linear impulse to the body.
real GetI() const
Gets the moment of inertia of the body.
Definition d2Body.h:369
void AddTorque(real torque)
Adds a torque to the body.
d2Vec2 LocalSpaceToWorldSpace(const d2Vec2 &point) const
Converts a point from local space to world space.
void SetAwake(bool awake)
Sets the wake state of the body.
Definition d2Body.h:449
real GetAngularVelocity() const
Gets the angular velocity of the body.
Definition d2Body.h:349
real GetRestitution() const
Gets the coefficient of restitution of the body.
Definition d2Body.h:394
real GetRotation() const
Gets the rotation angle of the body.
Definition d2Body.h:354
void SetRestitution(real restitution)
Sets the coefficient of restitution of the body.
Definition d2Body.h:389
void ApplyImpulseAngular(const real j)
Applies an angular impulse to the body.
void IntegrateForces(const real dt)
Integrates the forces applied to the body over a time step.
void IntegrateAngular(real dt)
Integrates the angular motion of the body over a time step.
bool IsAwake() const
Gets the wake state of the body.
Definition d2Body.h:444
real GetFriction() const
Gets the coefficient of friction of the body.
Definition d2Body.h:384
void SetFriction(real friction)
Sets the coefficient of friction of the body.
Definition d2Body.h:379
void ClearTorque()
Clears all torques applied to the body.
void AddForce(const d2Vec2 &force)
Adds a force to the body.
real GetInvI() const
Gets the inverse moment of inertia of the body.
Definition d2Body.h:374
void SetPosition(const d2Vec2 &position)
Sets the position of the body.
Definition d2Body.h:329
void SetAcceleration(const d2Vec2 &acceleration)
Set acceleration of the body.
Definition d2Body.h:339
void IntegrateVelocities(const real dt)
Integrates the velocities of the body over a time step.
d2Body * GetPrev()
Gets the previous body in a linked list of bodies.
Definition d2Body.h:419
d2AABB * GetAABB() const
Gets the Axis-Aligned Bounding Box of the body.
Definition d2Body.h:404
real GetSleepTime() const
Gets wake-up time of the body.
Definition d2Body.h:429
~d2Body()
Destructor for the d2Body class.
d2Vec2 WorldSpaceToLocalSpace(const d2Vec2 &point) const
Converts a point from world space to local space.
real GetGravityScale() const
Gets the gravity scale of the body.
Definition d2Body.h:434
real GetInvMass() const
Gets the inverse mass of the body.
Definition d2Body.h:364
d2Body(const d2Shape &shape, real x, real y, real mass, d2World *world)
Constructor for the d2Body class.
d2Shape * GetShape() const
Gets the shape/geometry of the body.
Definition d2Body.h:399
void SetAngularVelocity(real angularVelocity)
Sets the angular velocity of the body.
Definition d2Body.h:344
void ApplyImpulseAtPoint(const d2Vec2 &j, const d2Vec2 &r)
Applies an impulse at a specific point on the body.
void ComputeAABB()
Computes the Axis-Aligned Bounding Box of the body.
Represents a 2D physics world.
Definition d2World.h:22
d2BodyType
Definition d2Body.h:16
@ d2_staticBody
Definition d2Body.h:17
@ d2_dynamicBody
Definition d2Body.h:18
float real
Definition d2Types.h:10
unsigned short uint16
Definition d2Types.h:8
#define D2_API
Definition d2api.h:27
real GetAngle() const
Get the rotation angle in radians.
Definition d2Math.h:254
Represents a 2D vector.
Definition d2Math.h:22