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
RigidBody.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_COMPONENTS_RIGIDBODY_HPP_
9#define GALAXY_COMPONENTS_RIGIDBODY_HPP_
10
11#include <box2d/b2_body.h>
12#include <glm/vec2.hpp>
13
15
16namespace galaxy
17{
18 namespace core
19 {
20 class Registry;
21 } // namespace core
22
23 namespace systems
24 {
25 class PhysicsSystem;
26 } // namespace systems
27
28 namespace components
29 {
33 class RigidBody final : public fs::Serializable
34 {
35 friend class core::Registry;
37
38 public:
42 RigidBody();
43
49 RigidBody(const nlohmann::json& json);
50
55
60
64 virtual ~RigidBody();
65
72 void set_shape(const float hw, const float hh);
73
79 void set_type(const b2BodyType type);
80
86 void set_density(const float density);
87
93 void set_friction(const float friction);
94
100 void set_restitution(const float restitution);
101
107 void set_restitution_threshold(const float restitution_threshold);
108
114 void set_bullet(const bool is_bullet);
115
121 void set_fixed_rotation(const bool fixed_rotation);
122
128 [[nodiscard]]
129 const glm::vec2& get_shape() const;
130
136 [[nodiscard]]
137 b2BodyType get_type() const;
138
144 [[nodiscard]]
145 float get_density() const;
146
152 [[nodiscard]]
153 float get_friction() const;
154
160 [[nodiscard]]
161 float get_restitution() const;
162
168 [[nodiscard]]
169 float get_restitution_threshold() const;
170
176 [[nodiscard]]
177 bool is_bullet() const;
178
184 [[nodiscard]]
185 bool is_rotation_fixed() const;
186
192 [[nodiscard]]
193 nlohmann::json serialize() override;
194
200 void deserialize(const nlohmann::json& json) override;
201
202 private:
206 RigidBody& operator=(const RigidBody&) = delete;
207
211 RigidBody(const RigidBody&) = delete;
212
213 private:
217 glm::vec2 m_shape;
218
222 b2BodyType m_type;
223
228
233
238
243
248
253
257 b2Body* m_body;
258
262 b2World* m_world;
263 };
264 } // namespace components
265} // namespace galaxy
266
267#endif
Box2D physics body.
Definition RigidBody.hpp:34
RigidBody(const RigidBody &)=delete
Copy constructor.
float m_friction
How slippery it is.
float get_friction() const
Get body friction.
void set_friction(const float friction)
Set friction of body.
float m_restitution
How bouncy the fixture is.
b2BodyType m_type
Body type.
b2Body * m_body
Pointer to Box2D body.
bool m_fixed_rotation
Can this body rotate?
void set_type(const b2BodyType type)
Set body type.
Definition RigidBody.cpp:97
b2BodyType get_type() const
Get body type.
RigidBody & operator=(const RigidBody &)=delete
Copy assignment operator.
void set_restitution_threshold(const float restitution_threshold)
Set restitution threshold.
glm::vec2 m_shape
Box2D body shape.
void set_restitution(const float restitution)
Set restitution of body.
void set_fixed_rotation(const bool fixed_rotation)
Set rotation status of body.
void set_bullet(const bool is_bullet)
Set if body is a bullet type.
bool is_bullet() const
Is this a bullet style body.
const glm::vec2 & get_shape() const
Get body shape.
float get_density() const
Get body density.
void set_density(const float density)
Set body density.
float get_restitution_threshold() const
Get restitution threshold.
void deserialize(const nlohmann::json &json) override
Deserializes from object.
bool m_bullet
Is this a bullet? Does continous collision checking.
float m_density
How heavy it is in relation to its area.
float get_restitution() const
Get body restitution.
virtual ~RigidBody()
Destructor.
Definition RigidBody.cpp:82
b2World * m_world
Pointer to the Box2D world.
void set_shape(const float hw, const float hh)
Set new box2d collider shape.
Definition RigidBody.cpp:87
RigidBody & operator=(RigidBody &&)
Move assignment operator.
Definition RigidBody.cpp:60
float m_restitution_threshold
Restitution velocity threshold.
bool is_rotation_fixed() const
Get rotation status.
nlohmann::json serialize() override
Serializes object.
Wrapper around entt::registry to expand functionality.
Definition Registry.hpp:21
Allows a class to be serialized.
Update entities with a rigid body component.
Timer.hpp galaxy.
Definition Async.hpp:17