8#include <box2d/b2_fixture.h>
9#include <box2d/b2_polygon_shape.h>
10#include <magic_enum/magic_enum.hpp>
11#include <nlohmann/json.hpp>
13#include "galaxy/core/ServiceLocator.hpp"
24 , m_type {b2_staticBody}
27 , m_restitution {0.0f}
28 , m_restitution_threshold {0.0f}
30 , m_fixed_rotation {true}
45 this->
m_shape = std::move(rb.m_shape);
64 this->
m_shape = std::move(rb.m_shape);
92 auto fixture =
m_body->GetFixtureList();
93 auto shape =
dynamic_cast<b2PolygonShape*
>(fixture->GetShape());
106 auto fixture =
m_body->GetFixtureList();
116 auto fixture =
m_body->GetFixtureList();
124 auto fixture =
m_body->GetFixtureList();
132 auto fixture =
m_body->GetFixtureList();
143 m_body->SetFixedRotation(fixed_rotation);
188 nlohmann::json json =
"{}"_json;
189 json[
"shape"][
"hw"] =
m_shape.x;
190 json[
"shape"][
"hh"] =
m_shape.y;
191 json[
"type"] = magic_enum::enum_name(
m_type);
204 const auto& shape = json.at(
"shape");
208 const auto type = magic_enum::enum_cast<b2BodyType>(json.at(
"type").get<std::string>());
209 if (type.has_value())
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.
b2BodyType get_type() const
Get body type.
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.
b2World * m_world
Pointer to the Box2D world.
void set_shape(const float hw, const float hh)
Set new box2d collider shape.
RigidBody & operator=(RigidBody &&)
Move assignment operator.
float m_restitution_threshold
Restitution velocity threshold.
bool is_rotation_fixed() const
Get rotation status.
nlohmann::json serialize() override
Serializes object.