galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::components::RigidBody Class Referencefinal

Box2D physics body. More...

#include <RigidBody.hpp>

+ Inheritance diagram for galaxy::components::RigidBody:
+ Collaboration diagram for galaxy::components::RigidBody:

Public Member Functions

 RigidBody ()
 Constructor.
 
 RigidBody (const nlohmann::json &json)
 JSON constructor.
 
 RigidBody (RigidBody &&)
 Move constructor.
 
RigidBodyoperator= (RigidBody &&)
 Move assignment operator.
 
virtual ~RigidBody ()
 Destructor.
 
void set_shape (const float hw, const float hh)
 Set new box2d collider shape.
 
void set_type (const b2BodyType type)
 Set body type.
 
void set_density (const float density)
 Set body density.
 
void set_friction (const float friction)
 Set friction of body.
 
void set_restitution (const float restitution)
 Set restitution of body.
 
void set_restitution_threshold (const float restitution_threshold)
 Set restitution threshold.
 
void set_bullet (const bool is_bullet)
 Set if body is a bullet type.
 
void set_fixed_rotation (const bool fixed_rotation)
 Set rotation status of body.
 
const glm::vec2 & get_shape () const
 Get body shape.
 
b2BodyType get_type () const
 Get body type.
 
float get_density () const
 Get body density.
 
float get_friction () const
 Get body friction.
 
float get_restitution () const
 Get body restitution.
 
float get_restitution_threshold () const
 Get restitution threshold.
 
bool is_bullet () const
 Is this a bullet style body.
 
bool is_rotation_fixed () const
 Get rotation status.
 
nlohmann::json serialize () override
 Serializes object.
 
void deserialize (const nlohmann::json &json) override
 Deserializes from object.
 
- Public Member Functions inherited from galaxy::fs::Serializable
virtual ~Serializable ()
 Destructor.
 
virtual Serializableoperator= (Serializable &&)=default
 Move assignment operator.
 
virtual Serializableoperator= (const Serializable &)=default
 Copy assignment operator.
 

Private Member Functions

RigidBodyoperator= (const RigidBody &)=delete
 Copy assignment operator.
 
 RigidBody (const RigidBody &)=delete
 Copy constructor.
 

Private Attributes

glm::vec2 m_shape
 Box2D body shape.
 
b2BodyType m_type
 Body type.
 
float m_density
 How heavy it is in relation to its area.
 
float m_friction
 How slippery it is.
 
float m_restitution
 How bouncy the fixture is.
 
float m_restitution_threshold
 Restitution velocity threshold.
 
bool m_bullet
 Is this a bullet? Does continous collision checking.
 
bool m_fixed_rotation
 Can this body rotate?
 
b2Body * m_body
 Pointer to Box2D body.
 
b2World * m_world
 Pointer to the Box2D world.
 

Additional Inherited Members

- Protected Member Functions inherited from galaxy::fs::Serializable
 Serializable ()
 Constructor.
 

Detailed Description

Box2D physics body.

Definition at line 33 of file RigidBody.hpp.

Constructor & Destructor Documentation

◆ RigidBody() [1/4]

galaxy::components::RigidBody::RigidBody ( )

Constructor.

Definition at line 21 of file RigidBody.cpp.

◆ RigidBody() [2/4]

galaxy::components::RigidBody::RigidBody ( const nlohmann::json & json)

JSON constructor.

Parameters
jsonJSON defining object.

Definition at line 36 of file RigidBody.cpp.

+ Here is the call graph for this function:

◆ RigidBody() [3/4]

galaxy::components::RigidBody::RigidBody ( RigidBody && rb)

Move constructor.

Definition at line 42 of file RigidBody.cpp.

◆ ~RigidBody()

galaxy::components::RigidBody::~RigidBody ( )
virtual

Destructor.

Definition at line 82 of file RigidBody.cpp.

◆ RigidBody() [4/4]

galaxy::components::RigidBody::RigidBody ( const RigidBody & )
privatedelete

Copy constructor.

Member Function Documentation

◆ operator=() [1/2]

RigidBody & galaxy::components::RigidBody::operator= ( RigidBody && rb)

Move assignment operator.

Definition at line 60 of file RigidBody.cpp.

◆ set_shape()

void galaxy::components::RigidBody::set_shape ( const float hw,
const float hh )

Set new box2d collider shape.

Parameters
hwHalf extant width.
hhHalf extant height.

Definition at line 87 of file RigidBody.cpp.

◆ set_type()

void galaxy::components::RigidBody::set_type ( const b2BodyType type)

Set body type.

Parameters
typeBox2d body enum type.

Definition at line 97 of file RigidBody.cpp.

◆ set_density()

void galaxy::components::RigidBody::set_density ( const float density)

Set body density.

Parameters
densityAffects mass of body.

Definition at line 102 of file RigidBody.cpp.

◆ set_friction()

void galaxy::components::RigidBody::set_friction ( const float friction)

Set friction of body.

Parameters
frictionAffects movement against other bodies during collision.

Definition at line 112 of file RigidBody.cpp.

◆ set_restitution()

void galaxy::components::RigidBody::set_restitution ( const float restitution)

Set restitution of body.

Parameters
restitutionAffects bounce of body.

Definition at line 120 of file RigidBody.cpp.

◆ set_restitution_threshold()

void galaxy::components::RigidBody::set_restitution_threshold ( const float restitution_threshold)

Set restitution threshold.

Parameters
restitution_thresholdAffects bounce threshold of body.

Definition at line 128 of file RigidBody.cpp.

◆ set_bullet()

void galaxy::components::RigidBody::set_bullet ( const bool is_bullet)

Set if body is a bullet type.

Parameters
is_bulletEnables continous collision.

Definition at line 136 of file RigidBody.cpp.

+ Here is the call graph for this function:

◆ set_fixed_rotation()

void galaxy::components::RigidBody::set_fixed_rotation ( const bool fixed_rotation)

Set rotation status of body.

Parameters
fixed_rotationCan body rotate.

Definition at line 141 of file RigidBody.cpp.

◆ get_shape()

const glm::vec2 & galaxy::components::RigidBody::get_shape ( ) const
nodiscard

Get body shape.

Returns
Const glm::vec2 reference.

Definition at line 146 of file RigidBody.cpp.

◆ get_type()

b2BodyType galaxy::components::RigidBody::get_type ( ) const
nodiscard

Get body type.

Returns
Box2d enum body type.

Definition at line 151 of file RigidBody.cpp.

◆ get_density()

float galaxy::components::RigidBody::get_density ( ) const
nodiscard

Get body density.

Returns
Float.

Definition at line 156 of file RigidBody.cpp.

◆ get_friction()

float galaxy::components::RigidBody::get_friction ( ) const
nodiscard

Get body friction.

Returns
Float.

Definition at line 161 of file RigidBody.cpp.

◆ get_restitution()

float galaxy::components::RigidBody::get_restitution ( ) const
nodiscard

Get body restitution.

Returns
Float.

Definition at line 166 of file RigidBody.cpp.

◆ get_restitution_threshold()

float galaxy::components::RigidBody::get_restitution_threshold ( ) const
nodiscard

Get restitution threshold.

Returns
Float.

Definition at line 171 of file RigidBody.cpp.

◆ is_bullet()

bool galaxy::components::RigidBody::is_bullet ( ) const
nodiscard

Is this a bullet style body.

Returns
True if continously colliding.

Definition at line 176 of file RigidBody.cpp.

+ Here is the caller graph for this function:

◆ is_rotation_fixed()

bool galaxy::components::RigidBody::is_rotation_fixed ( ) const
nodiscard

Get rotation status.

Returns
True if body can't rotate.

Definition at line 181 of file RigidBody.cpp.

◆ serialize()

nlohmann::json galaxy::components::RigidBody::serialize ( )
nodiscardoverridevirtual

Serializes object.

Returns
JSON object containing data to be serialized.

Implements galaxy::fs::Serializable.

Definition at line 186 of file RigidBody.cpp.

◆ deserialize()

void galaxy::components::RigidBody::deserialize ( const nlohmann::json & json)
overridevirtual

Deserializes from object.

Parameters
jsonJson object to retrieve data from.

Implements galaxy::fs::Serializable.

Definition at line 202 of file RigidBody.cpp.

+ Here is the caller graph for this function:

◆ operator=() [2/2]

RigidBody & galaxy::components::RigidBody::operator= ( const RigidBody & )
privatedelete

Copy assignment operator.

Member Data Documentation

◆ m_shape

glm::vec2 galaxy::components::RigidBody::m_shape
private

Box2D body shape.

Definition at line 217 of file RigidBody.hpp.

◆ m_type

b2BodyType galaxy::components::RigidBody::m_type
private

Body type.

Definition at line 222 of file RigidBody.hpp.

◆ m_density

float galaxy::components::RigidBody::m_density
private

How heavy it is in relation to its area.

Definition at line 227 of file RigidBody.hpp.

◆ m_friction

float galaxy::components::RigidBody::m_friction
private

How slippery it is.

Definition at line 232 of file RigidBody.hpp.

◆ m_restitution

float galaxy::components::RigidBody::m_restitution
private

How bouncy the fixture is.

Definition at line 237 of file RigidBody.hpp.

◆ m_restitution_threshold

float galaxy::components::RigidBody::m_restitution_threshold
private

Restitution velocity threshold.

Definition at line 242 of file RigidBody.hpp.

◆ m_bullet

bool galaxy::components::RigidBody::m_bullet
private

Is this a bullet? Does continous collision checking.

Definition at line 247 of file RigidBody.hpp.

◆ m_fixed_rotation

bool galaxy::components::RigidBody::m_fixed_rotation
private

Can this body rotate?

Definition at line 252 of file RigidBody.hpp.

◆ m_body

b2Body* galaxy::components::RigidBody::m_body
private

Pointer to Box2D body.

Definition at line 257 of file RigidBody.hpp.

◆ m_world

b2World* galaxy::components::RigidBody::m_world
private

Pointer to the Box2D world.

Definition at line 262 of file RigidBody.hpp.


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