1#include "scene/components/PhysicsComponent.h"
4#include "scene/GameObject.h"
15 std::shared_ptr<Collider> collider;
18 if (json.contains(
"collider"))
20 const auto &col = json[
"collider"];
21 std::string type = col.value(
"type",
"");
25 glm::vec3 extents(col.value(
"x", 1.0f), col.value(
"y", 1.0f), col.value(
"z", 1.0f));
26 collider = std::make_shared<BoxCollider>(extents);
28 }
else if (type ==
"sphere")
30 float radius = col.value(
"r", 1.0f);
31 collider = std::make_shared<SphereCollider>(radius);
33 }
else if (type ==
"capsule")
35 float radius = col.value(
"r", 1.0f);
36 float height = col.value(
"h", 1.0f);
37 collider = std::make_shared<CapsuleCollider>(radius, height);
47 std::shared_ptr<RigidBody> rigidbody;
48 if (json.contains(
"body"))
50 const auto &body = json[
"body"];
52 float mass = body.value(
"mass", 0.0f);
53 float friction = body.value(
"friction", 0.5f);
54 std::string typeStr = body.value(
"type",
"static");
57 if (typeStr ==
"dynamic")
60 }
else if (typeStr ==
"kinematic")
65 rigidbody = std::make_shared<RigidBody>(type, collider, mass, friction);
84 m_rigidBody->SetPosition(pos);
85 m_rigidBody->SetRotation(rot);
static Engine & GetInstance()
Returns the single Engine instance (created on first call).
PhysicsManager & GetPhysicsManager()
vec3 GetWorldPosition() const
Extract the world-space position from GetWorldTransform().
void SetWorldRotation(const quat &rot)
void SetWorldPosition(const vec3 &pos)
const std::shared_ptr< RigidBody > & GetRigidBody()
void LoadProperties(const nlohmann::json &json) override
Parse collider + body sub-objects and build the RigidBody.
void Update(float deltaTime) override
Copy the simulated pose onto the owning GameObject.
void SetRigidBody(const std::shared_ptr< RigidBody > &body)
Replace the component's rigid body at runtime.
PhysicsComponent()=default
void Init() override
Register the rigid body with the PhysicsManager.
void AddRigidBody(RigidBody *body)
Register a rigid body so it participates in simulation and collision.
BodyType
Simulation category for a RigidBody.