Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
RigidBody.h
Go to the documentation of this file.
1/**
2 * @file RigidBody.h
3 * @ingroup mnd_physics
4 * @brief Bullet `btRigidBody` wrapper pairing a @ref Collider with mass and type.
5 */
6
7#pragma once
8#include <memory>
9
10#include <glm/gtc/quaternion.hpp>
11
12#include "Types.h"
13#include "physics/Collider.h"
14#include "physics/CollisionObject.h"
15
16class btRigidBody;
17
18namespace mnd
19{
20/**
21 * @ingroup mnd_physics
22 * @brief Simulation category for a @ref RigidBody.
23 *
24 * - **Static** — never moves; contributes collision only (mass ignored).
25 * - **Dynamic** — fully simulated, driven by forces and gravity.
26 * - **Kinematic** — moved by game code; pushes dynamic bodies but is not itself affected.
27 */
28enum class BodyType
29{
30 Static,
31 Dynamic,
33};
34
35/**
36 * @ingroup mnd_physics
37 * @brief Owning wrapper around `btRigidBody`; holds a shared @ref Collider,
38 * mass, friction, and body type.
39 */
41{
42 public:
43 /**
44 * @param type Simulation category.
45 * @param collider Shape used for collision (shared — the same Collider may
46 * back several bodies).
47 * @param mass Kilograms; ignored for Static bodies.
48 * @param friction Bullet friction coefficient in [0, 1].
49 */
50 RigidBody(BodyType type, const std::shared_ptr<Collider> &collider, float mass, float friction);
51 ~RigidBody();
52
53 /// Underlying Bullet body (borrowed, do not delete).
54 btRigidBody *GetBody();
55
56 /// Track whether this body is currently registered with a PhysicsManager.
57 void SetAddedToWorld(bool added);
58 bool IsAddedToWorld() const;
59
60 BodyType GetType() const;
61
62 /// Teleport the body (bypasses the solver — use sparingly on Dynamic bodies).
63 void SetPosition(const glm::vec3 &pos);
64 glm::vec3 GetPosition() const;
65 void SetRotation(const glm::quat &rot);
66 glm::quat GetRotation() const;
67
68 void ApplyImpulse(const vec3 &impulse);
69
70 /// Enable continuous collision detection (prevents tunneling for fast bodies).
71 /// motionThreshold: velocity per step above which CCD kicks in (set < expected step distance).
72 /// sweptRadius: embedded sphere radius used for the swept test (typically ~0.2× shape radius).
73 void EnableCcd(float motionThreshold, float sweptRadius);
74
75 private:
76 std::unique_ptr<btRigidBody> m_body;
78 std::shared_ptr<Collider> m_collider;
79 float m_mass = 0.0f;
80 float m_friction = 0.5f;
81 bool m_addedToWorld = false;
82};
83} // namespace mnd
Engine-wide primitive type aliases and GLM math imports.
Owning wrapper around btRigidBody; holds a shared Collider, mass, friction, and body type.
Definition RigidBody.h:41
glm::quat GetRotation() const
glm::vec3 GetPosition() const
Definition RigidBody.cpp:94
void EnableCcd(float motionThreshold, float sweptRadius)
void SetPosition(const glm::vec3 &pos)
Teleport the body (bypasses the solver — use sparingly on Dynamic bodies).
Definition RigidBody.cpp:78
bool IsAddedToWorld() const
Definition RigidBody.cpp:68
void SetRotation(const glm::quat &rot)
btRigidBody * GetBody()
Underlying Bullet body (borrowed, do not delete).
Definition RigidBody.cpp:58
BodyType GetType() const
Definition RigidBody.cpp:73
void ApplyImpulse(const vec3 &impulse)
void SetAddedToWorld(bool added)
Track whether this body is currently registered with a PhysicsManager.
Definition RigidBody.cpp:63
glm::vec3 vec3
3-component float vector (e.g. world position, RGB colour, normals).
Definition Types.h:51
BodyType
Simulation category for a RigidBody.
Definition RigidBody.h:29