Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
PhysicsManager.h
Go to the documentation of this file.
1/**
2 * @file PhysicsManager.h
3 * @ingroup mnd_physics
4 * @brief Owns the Bullet dynamics world and steps it each frame.
5 */
6
7#pragma once
8
9#include <memory>
10
11#include "Types.h"
12
13class btBroadphaseInterface;
14class btDefaultCollisionConfiguration;
15class btCollisionDispatcher;
16class btSequentialImpulseConstraintSolver;
17class btDiscreteDynamicsWorld;
18
19namespace mnd
20{
21class RigidBody;
22struct RayHit;
23
24/**
25 * @ingroup mnd_physics
26 * @brief Owns the Bullet `btDiscreteDynamicsWorld` and all auxiliary collision
27 * structures (broadphase, dispatcher, solver).
28 *
29 * One instance lives on the Engine singleton. `PhysicsComponent` pushes its
30 * `RigidBody` here via @ref AddRigidBody; `Engine::Run` calls @ref Update once
31 * per frame to step the simulation.
32 */
34{
35public:
38
39 /// Allocate broadphase, dispatcher, solver, and dynamics world. Call once.
40 void Init();
41
42 /// Step the simulation by @p deltaTime seconds.
43 void Update(float deltaTime);
44
45 /// Register a rigid body so it participates in simulation and collision.
46 void AddRigidBody(RigidBody *body);
47
48 /// Unregister a rigid body (e.g. when its owning component is destroyed).
49 void RemoveRigidBody(RigidBody *body);
50
51 /// Cast a ray from @p from to @p to and fill @p out with the closest hit.
52 /// `out.object` is the GameObject behind the hit collision object, when one
53 /// has been set via CollisionObject::SetOwner; otherwise null.
54 /// @return true if any collider was hit.
55 bool Raycast(const vec3 &from, const vec3 &to, RayHit &out);
56
57 /// Raw pointer to the underlying Bullet world (for advanced/internal use).
58 btDiscreteDynamicsWorld *GetWorld();
59
60private:
61 std::unique_ptr<btBroadphaseInterface> m_broadphase;
62 std::unique_ptr<btDefaultCollisionConfiguration> m_collisionConfig;
63 std::unique_ptr<btCollisionDispatcher> m_dispatcher;
64 std::unique_ptr<btSequentialImpulseConstraintSolver> m_solver;
65 std::unique_ptr<btDiscreteDynamicsWorld> m_world;
66};
67} // namespace mnd
68
Engine-wide primitive type aliases and GLM math imports.
Owns the Bullet btDiscreteDynamicsWorld and all auxiliary collision structures (broadphase,...
bool Raycast(const vec3 &from, const vec3 &to, RayHit &out)
void AddRigidBody(RigidBody *body)
Register a rigid body so it participates in simulation and collision.
btDiscreteDynamicsWorld * GetWorld()
Raw pointer to the underlying Bullet world (for advanced/internal use).
void Update(float deltaTime)
Step the simulation by deltaTime seconds.
void Init()
Allocate broadphase, dispatcher, solver, and dynamics world. Call once.
void RemoveRigidBody(RigidBody *body)
Unregister a rigid body (e.g. when its owning component is destroyed).
Owning wrapper around btRigidBody; holds a shared Collider, mass, friction, and body type.
Definition RigidBody.h:41
glm::vec3 vec3
3-component float vector (e.g. world position, RGB colour, normals).
Definition Types.h:51
Hit information returned by PhysicsManager::Raycast.
Definition Raycast.h:23