Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
PhysicsComponent.h
Go to the documentation of this file.
1/**
2 * @file PhysicsComponent.h
3 * @ingroup mnd_components
4 * @brief Attaches a @ref RigidBody to a GameObject and syncs its transform.
5 */
6
7#pragma once
8#include "physics/RigidBody.h"
9#include "scene/Component.h"
10
11namespace mnd
12{
13/**
14 * @ingroup mnd_components
15 * @brief Component bridge between a @ref GameObject and the physics world.
16 *
17 * Reads `collider` and `body` blocks from its JSON definition in a scene file,
18 * registers the resulting @ref RigidBody with the engine's @ref PhysicsManager,
19 * and each frame copies the simulated transform back onto the owning GameObject.
20 */
22{
24public:
25 PhysicsComponent() = default;
26
27 /// Construct from an already-built rigid body (skips JSON parsing).
28 PhysicsComponent(const std::shared_ptr<RigidBody> &body);
29
30 /// Parse `collider` + `body` sub-objects and build the @ref RigidBody.
31 void LoadProperties(const nlohmann::json &json) override;
32
33 /// Register the rigid body with the PhysicsManager.
34 void Init() override;
35
36 /// Copy the simulated pose onto the owning GameObject.
37 void Update(float deltaTime) override;
38
39 /// Replace the component's rigid body at runtime.
40 void SetRigidBody(const std::shared_ptr<RigidBody> &body);
41 const std::shared_ptr<RigidBody> &GetRigidBody();
42
43private:
44 std::shared_ptr<RigidBody> m_rigidBody;
45};
46} // namespace mnd
Component bridge between a GameObject and the physics world.
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.
#define COMPONENT(ComponentClass)
Definition Component.h:105