|
Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
|
Owns the Bullet dynamics world and dispatches engine collision events. More...
#include <PhysicsEngine.h>
Classes | |
| struct | ComponentPairKey |
| struct | PendingActorEvent |
| struct | PendingComponentEvent |
| struct | RuntimeBodySlot |
| struct | RuntimeCollisionSlot |
Public Member Functions | |
| PhysicsEngine () | |
| Creates a physics engine using the active collision profile registry. | |
| PhysicsEngine (Physics::CollisionProfileRegistry *collisionProfileRegistry) | |
| Creates a physics engine with an explicit collision profile registry. | |
| ~PhysicsEngine () | |
| Removes remaining Bullet objects and destroys the Bullet world infrastructure. | |
| void | setCollisionProfileRegistry (Physics::CollisionProfileRegistry *collisionProfileRegistry) |
| Sets the collision profile registry used by collision events and filtered queries. | |
| Physics::CollisionProfileRegistry * | getCollisionProfileRegistry () const |
| Gets the collision profile registry assigned to this physics engine. | |
| void | onPhysicsComponentDestroyed (entt::registry ®istry, entt::entity entity) |
| Cleans up legacy ECS physics data when a SimulatesPhysics component is destroyed. | |
| void | update (double deltaTimeSeconds) |
| Steps the physics simulation and queues collision events. | |
| void | dispatchQueuedCollisionEvents () |
| Dispatches collision events queued by the last PhysicsEngine::update() call. | |
| Physics::PhysicsBodyHandle | registerBody (Components::PhysicsBody *body) |
| Registers a physics body component for handle-based lookup. | |
| void | unregisterBody (Physics::PhysicsBodyHandle handle) |
| Unregisters a physics body handle and queues End events for active pairs that reference it. | |
| Components::PhysicsBody * | resolve (Physics::PhysicsBodyHandle handle) const |
| Resolves a runtime body handle to a physics body component. | |
| Physics::CollisionHandle | registerCollision (Components::Collision *collision) |
| Registers a collision component for handle-based lookup. | |
| void | unregisterCollision (Physics::CollisionHandle handle) |
| Unregisters a collision handle and queues End events for active pairs that reference it. | |
| Components::Collision * | resolve (Physics::CollisionHandle handle) const |
| Resolves a runtime collision handle to a collision component. | |
| btDiscreteDynamicsWorld * | getDynamicsWorld () const |
| Gets the Bullet dynamics world used by this physics engine. | |
| bool | raycastClosest (const glm::vec3 &origin, const glm::vec3 &direction, float maxDistance, Physics::RaycastHit &outHit) const |
| Casts a ray through the physics world and returns the closest hit, if any. | |
| bool | raycastClosest (const glm::vec3 &origin, const glm::vec3 &direction, float maxDistance, const Physics::PhysicsQueryFilter &filter, Physics::RaycastHit &outHit) const |
| Casts a filtered ray through the physics world and returns the closest hit, if any. | |
| bool | sphereSweepClosest (const glm::vec3 &from, const glm::vec3 &to, float radius, Physics::RaycastHit &outHit, const btCollisionObject *ignoredObject=nullptr) const |
| Sweeps a sphere through the physics world and returns the closest overlap hit, if any. | |
| bool | sphereSweepClosest (const glm::vec3 &from, const glm::vec3 &to, float radius, const Physics::PhysicsQueryFilter &filter, Physics::RaycastHit &outHit, const btCollisionObject *ignoredObject=nullptr) const |
| Sweeps a filtered sphere through the physics world and returns the closest hit, if any. | |
| bool | sphereClosest (const glm::vec3 &position, float radius, Physics::RaycastHit &outHit, const btCollisionObject *ignoredObject=nullptr) const |
| Tests a sphere at one position and returns the closest overlapping collision object, if any. | |
| bool | sphereClosest (const glm::vec3 &position, float radius, const Physics::PhysicsQueryFilter &filter, Physics::RaycastHit &outHit, const btCollisionObject *ignoredObject=nullptr) const |
| Tests a filtered sphere and returns the closest overlapping collision object, if any. | |
| btRigidBody * | createRigidBody (const Physics::RigidBodyCreateInfo &info) const |
| Creates and adds a rigid body to the physics world with default Bullet collision filters. | |
| btRigidBody * | createRigidBody (const Physics::RigidBodyCreateInfo &info, std::uint16_t collisionGroup, std::uint16_t collisionMask) const |
| Creates and adds a rigid body to the physics world with explicit Bullet collision filters. | |
| void | removeRigidBody (btRigidBody *body) const |
| Removes a rigid body from the physics world and deletes it. | |
| void | debugDrawAll () const |
| Draws debug visualization of all collision shapes in the world. | |
Static Public Member Functions | |
| static btCollisionShape * | createBoxShape (const glm::vec3 &halfExtents) |
| Creates a box collision shape. | |
| static btCollisionShape * | createSphereShape (float radius) |
| Creates a sphere collision shape. | |
| static btCollisionShape * | createCapsuleShape (float radius, float height) |
| Creates a capsule collision shape aligned to Bullet's Y axis. | |
| static btCollisionShape * | createPlaneShape (const glm::vec3 &surfaceNormal, float distanceFromOrigin) |
| Creates an infinite static plane collision shape. | |
| static btCollisionShape * | createConvexHullShape (const std::vector< glm::vec3 > &vertices) |
| Creates a convex hull collision shape from vertex positions. | |
| static btCollisionShape * | createTriangleMeshShape (const std::vector< glm::vec3 > &vertices, const std::vector< uint32_t > &indices, btTriangleMesh *&triangleMeshOut) |
| Creates a static triangle mesh collision shape from vertices and triangle indices. | |
| static btCompoundShape * | createCompoundShape () |
| Creates an empty compound collision shape. | |
Private Member Functions | |
| void | collectCollisionEvents () |
| void | queueDirectedEvents (const ComponentPairKey &pair, Physics::CollisionEventType eventType) |
| void | queueInvalidationEndEvents (Physics::PhysicsBodyHandle bodyHandle, Physics::CollisionHandle collisionHandle) |
| void | buildActorEvents () |
| bool | bodyMatchesQueryFilter (const Components::PhysicsBody *body, const Physics::PhysicsQueryFilter &filter) const |
Private Attributes | |
| Physics::CollisionProfileRegistry * | collisionProfileRegistry_ = nullptr |
| std::vector< RuntimeBodySlot > | bodySlots_ |
| std::vector< RuntimeCollisionSlot > | collisionSlots_ |
| std::uint32_t | nextBodyId_ = 1 |
| std::uint32_t | nextCollisionId_ = 1 |
| std::set< ComponentPairKey > | previousComponentPairs_ |
| std::vector< PendingComponentEvent > | pendingLifetimeComponentEvents_ |
| std::vector< PendingComponentEvent > | pendingComponentEvents_ |
| std::vector< PendingActorEvent > | pendingActorEvents_ |
| btBroadphaseInterface * | broadphase |
| btCollisionConfiguration * | collisionConfiguration |
| btCollisionDispatcher * | dispatcher |
| btConstraintSolver * | solver |
| btDiscreteDynamicsWorld * | dynamicsWorld |
Owns the Bullet dynamics world and dispatches engine collision events.
PhysicsEngine creates Bullet world infrastructure, steps simulation, runs physics queries, and maps runtime physics handles back to engine components. Collision callbacks are collected during PhysicsEngine::update() and dispatched by PhysicsEngine::dispatchQueuedCollisionEvents().
Definition at line 85 of file PhysicsEngine.h.
| Engine::Core::PhysicsEngine::PhysicsEngine | ( | ) |
Creates a physics engine using the active collision profile registry.
|
explicit |
Creates a physics engine with an explicit collision profile registry.
| collisionProfileRegistry | Registry used for collision responses and query filters. |
| Engine::Core::PhysicsEngine::~PhysicsEngine | ( | ) |
Removes remaining Bullet objects and destroys the Bullet world infrastructure.
|
nodiscardprivate |
|
private |
|
private |
|
static |
Creates a box collision shape.
| halfExtents | Half-size of the box on each local axis, in meters. |
|
static |
Creates a capsule collision shape aligned to Bullet's Y axis.
| radius | Capsule radius in meters. |
| height | Capsule cylinder height in meters. |
|
static |
Creates an empty compound collision shape.
|
static |
Creates a convex hull collision shape from vertex positions.
| vertices | Vertex positions used to build the hull. |
|
static |
Creates an infinite static plane collision shape.
| surfaceNormal | Plane normal. |
| distanceFromOrigin | Plane distance from world origin along surfaceNormal. |
|
nodiscard |
Creates and adds a rigid body to the physics world with default Bullet collision filters.
The created body owns a Bullet motion state. Remove it with PhysicsEngine::removeRigidBody() unless the engine removes it through ECS physics cleanup.
| info | Rigid body creation parameters. |
|
nodiscard |
Creates and adds a rigid body to the physics world with explicit Bullet collision filters.
The created body owns a Bullet motion state. Remove it with PhysicsEngine::removeRigidBody() unless the engine removes it through ECS physics cleanup.
| info | Rigid body creation parameters. |
| collisionGroup | Bullet collision group assigned to the body. |
| collisionMask | Bullet collision mask assigned to the body. |
|
static |
Creates a sphere collision shape.
| radius | Sphere radius in meters. |
|
static |
Creates a static triangle mesh collision shape from vertices and triangle indices.
The returned BVH shape references triangleMeshOut. Keep the triangle mesh alive until the shape is destroyed.
| vertices | Vertex positions used by indexed triangles. |
| indices | Triangle index list. Every three indices define one triangle. |
| triangleMeshOut | Receives the allocated Bullet triangle mesh. The caller owns it. |
| void Engine::Core::PhysicsEngine::debugDrawAll | ( | ) | const |
Draws debug visualization of all collision shapes in the world.
Iterates through all rigid bodies and calls PhysicsBody debug drawing for bodies with engine user data. Does nothing when collision debug drawing is disabled.
| void Engine::Core::PhysicsEngine::dispatchQueuedCollisionEvents | ( | ) |
Dispatches collision events queued by the last PhysicsEngine::update() call.
Component collision callbacks run before actor-level physics body callbacks. Events are copied before dispatch, so callbacks can modify collision subscriptions safely.
|
nodiscard |
Gets the collision profile registry assigned to this physics engine.
|
nodiscard |
Gets the Bullet dynamics world used by this physics engine.
| void Engine::Core::PhysicsEngine::onPhysicsComponentDestroyed | ( | entt::registry & | registry, |
| entt::entity | entity ) |
Cleans up legacy ECS physics data when a SimulatesPhysics component is destroyed.
| registry | Registry that owns the destroyed component. |
| entity | Entity that owned the destroyed component. |
|
private |
|
private |
|
nodiscard |
Casts a filtered ray through the physics world and returns the closest hit, if any.
A valid filter profile limits hits by resolved collision response. Bodies without engine PhysicsBody user data pass the filter. Returns false when maxDistance is not positive or direction has zero length.
| origin | World-space ray origin. |
| direction | Ray direction. Does not need to be normalized. |
| maxDistance | Maximum ray length in meters. |
| filter | Collision profile filter used by the query. |
| outHit | Filled with world-space hit data when the function returns true. |
|
nodiscard |
Casts a ray through the physics world and returns the closest hit, if any.
Returns false when maxDistance is not positive or direction has zero length.
| origin | World-space ray origin. |
| direction | Ray direction. Does not need to be normalized. |
| maxDistance | Maximum ray length in meters. |
| outHit | Filled with world-space hit data when the function returns true. |
|
nodiscard |
Registers a physics body component for handle-based lookup.
| body | Physics body component to register. |
|
nodiscard |
Registers a collision component for handle-based lookup.
| collision | Collision component to register. |
| void Engine::Core::PhysicsEngine::removeRigidBody | ( | btRigidBody * | body | ) | const |
Removes a rigid body from the physics world and deletes it.
The body's motion state is deleted before the body is deleted. Passing nullptr is ignored.
| body | Rigid body to remove and destroy. |
|
nodiscard |
Resolves a runtime collision handle to a collision component.
| handle | Collision handle to resolve. |
|
nodiscard |
Resolves a runtime body handle to a physics body component.
| handle | Body handle to resolve. |
| void Engine::Core::PhysicsEngine::setCollisionProfileRegistry | ( | Physics::CollisionProfileRegistry * | collisionProfileRegistry | ) |
Sets the collision profile registry used by collision events and filtered queries.
| collisionProfileRegistry | Registry pointer. Passing nullptr falls back to the active registry. |
|
nodiscard |
Tests a filtered sphere and returns the closest overlapping collision object, if any.
A valid filter profile limits hits by resolved collision response. Bodies without engine PhysicsBody user data pass the filter. Returns false when radius is not positive.
| position | World-space position of the sphere center. |
| radius | Sphere radius in meters. |
| filter | Collision profile filter used by the query. |
| outHit | Filled with world-space hit data when the function returns true. |
| ignoredObject | Optional collision object to ignore, usually the querying body itself. |
|
nodiscard |
Tests a sphere at one position and returns the closest overlapping collision object, if any.
Returns false when radius is not positive. The hit distance is the penetration depth reported by Bullet.
| position | World-space position of the sphere center. |
| radius | Sphere radius in meters. |
| outHit | Filled with world-space hit data when the function returns true. |
| ignoredObject | Optional collision object to ignore, usually the querying body itself. |
|
nodiscard |
Sweeps a filtered sphere through the physics world and returns the closest hit, if any.
A valid filter profile limits hits by resolved collision response. Bodies without engine PhysicsBody user data pass the filter. Returns false when radius is not positive or from and to are the same position.
| from | World-space start position of the sphere center. |
| to | World-space end position of the sphere center. |
| radius | Sphere radius in meters. |
| filter | Collision profile filter used by the query. |
| outHit | Filled with world-space hit data when the function returns true. |
| ignoredObject | Optional collision object to ignore, usually the querying body itself. |
|
nodiscard |
Sweeps a sphere through the physics world and returns the closest overlap hit, if any.
Returns false when radius is not positive or from and to are the same position.
| from | World-space start position of the sphere center. |
| to | World-space end position of the sphere center. |
| radius | Sphere radius in meters. |
| outHit | Filled with world-space hit data when the function returns true. |
| ignoredObject | Optional collision object to ignore, usually the querying body itself. |
| void Engine::Core::PhysicsEngine::unregisterBody | ( | Physics::PhysicsBodyHandle | handle | ) |
Unregisters a physics body handle and queues End events for active pairs that reference it.
| handle | Body handle returned by PhysicsEngine::registerBody(). |
Invalid, stale, and already unregistered handles are ignored.
| void Engine::Core::PhysicsEngine::unregisterCollision | ( | Physics::CollisionHandle | handle | ) |
Unregisters a collision handle and queues End events for active pairs that reference it.
| handle | Collision handle returned by PhysicsEngine::registerCollision(). |
Invalid, stale, and already unregistered handles are ignored.
| void Engine::Core::PhysicsEngine::update | ( | double | deltaTimeSeconds | ) |
Steps the physics simulation and queues collision events.
Bullet receives deltaTimeSeconds with up to 10 fixed substeps at 1/120 second. This function queues Begin, Stay, and End events but does not call user callbacks. Call PhysicsEngine::dispatchQueuedCollisionEvents() after the step to invoke callbacks.
| deltaTimeSeconds | Elapsed frame time in seconds. |
|
private |
Definition at line 481 of file PhysicsEngine.h.
|
private |
Definition at line 490 of file PhysicsEngine.h.
|
private |
Definition at line 491 of file PhysicsEngine.h.
|
private |
Definition at line 480 of file PhysicsEngine.h.
|
private |
Definition at line 482 of file PhysicsEngine.h.
|
private |
Definition at line 492 of file PhysicsEngine.h.
|
private |
Definition at line 494 of file PhysicsEngine.h.
|
private |
Definition at line 483 of file PhysicsEngine.h.
|
private |
Definition at line 484 of file PhysicsEngine.h.
|
private |
Definition at line 488 of file PhysicsEngine.h.
|
private |
Definition at line 487 of file PhysicsEngine.h.
|
private |
Definition at line 486 of file PhysicsEngine.h.
|
private |
Definition at line 485 of file PhysicsEngine.h.
|
private |
Definition at line 493 of file PhysicsEngine.h.