Owns and drives a single Jolt physics simulation scene. More...
#include <PhysicsWorld.h>
Public Member Functions | |
| PULSAR_API | PhysicsWorld ()=default |
| PULSAR_API | ~PhysicsWorld ()=default |
| PULSAR_API void | Init () |
Initialises the Jolt PhysicsSystem using the global Pulsar configuration. | |
| PULSAR_API void | Shutdown () |
| Removes all bodies from the simulation and releases Jolt resources. | |
| PULSAR_API u32 | CreateBody (u64 entityID, const BodyTransform &transform, const RigidBodyDesc &desc, const JPH::Shape *shape) |
| Creates a rigid body for the given entity and registers it in the world. | |
| PULSAR_API void | DestroyBody (u64 entityID) |
| Removes the body associated with the given entity and frees its Jolt resources. | |
| PULSAR_API u32 | CreateMeshBody (u64 entityID, u32 bodyID, const BodyTransform &transform, const JPH::Shape *shape) |
| Creates a static mesh body, optionally reusing a specific Jolt body ID. | |
| PULSAR_API JPH::Ref< JPH::Shape > | CreateShape (const RigidBodyDesc &desc) |
| Builds a Jolt collision shape from a RigidBodyDesc. | |
| PULSAR_API void | Step () |
| Advances the simulation by one fixed time step. | |
| PULSAR_API void | SyncTransform (u64 entityID, BodyTransform &outTransform) const |
| Reads the current Jolt body state into a BodyTransform. | |
| PULSAR_API void | SetTransform (u64 entityID, const BodyTransform &transform) |
| Teleports a body to a new position and orientation without waking it. | |
| PULSAR_API void | MoveKinematic (u64 entityID, const BodyTransform &transform, float dt) |
| Drives a kinematic body to the target pose over the given time delta. | |
| PULSAR_API bool | HasBody (u64 entityID) const |
| Returns whether the world currently tracks a body for the given entity. | |
| PULSAR_API void | AddImpulse (u64 entityID, const Crux::vec3 &impulse) |
| Applies an instantaneous linear impulse to a body's centre of mass. | |
| PULSAR_API void | AddForce (u64 entityID, const Crux::vec3 &force) |
| Applies a continuous force to a body's centre of mass for the current sub-step. | |
| PULSAR_API void | AddTorque (u64 entityID, const Crux::vec3 &torque) |
| Applies a continuous torque to a body for the current sub-step. | |
| PULSAR_API void | AddLinearVelocity (u64 entityID, const Crux::vec3 &velocity) |
| Adds a delta to the current linear velocity. | |
| PULSAR_API void | SetLinearVelocity (u64 entityID, const Crux::vec3 &velocity) |
| Overwrites the linear velocity of a body. | |
| PULSAR_API Crux::vec3 | GetLinearVelocity (u64 entityID) const |
| Returns the current linear velocity of a body. | |
| PULSAR_API void | AddAngularImpulse (u64 entityID, const Crux::vec3 &impulse) |
| Applies an instantaneous angular impulse to a body. | |
| PULSAR_API void | SetAngularVelocity (u64 entityID, const Crux::vec3 &velocity) |
| Overwrites the angular velocity of a body. | |
| PULSAR_API Crux::vec3 | GetAngularVelocity (u64 entityID) const |
| Returns the current angular velocity of a body. | |
| PULSAR_API void | SetGravityFactor (u64 entityID, float factor) |
| Scales the global gravity vector for a single body. | |
| PULSAR_API void | SetActive (u64 entityID, bool active) |
| Activates or deactivates a body in the simulation. | |
| template<typename Fn> | |
| void | WithBody (u64 entityID, Fn &&fn) const |
| Acquires a read lock on a body and invokes a callback with it. | |
Owns and drives a single Jolt physics simulation scene.
Each scene (e.g. a game level) owns one PhysicsWorld. The world maps engine entity IDs to Jolt BodyID values and exposes a high-level API that hides Jolt internals from the rest of the engine.
|
default |
|
default |
| void Raven::PhysicsWorld::AddAngularImpulse | ( | u64 | entityID, |
| const Crux::vec3 & | impulse ) |
Applies an instantaneous angular impulse to a body.
| entityID | Entity to affect. |
| impulse | Angular impulse in world space (kg·m²/s). |
| void Raven::PhysicsWorld::AddForce | ( | u64 | entityID, |
| const Crux::vec3 & | force ) |
Applies a continuous force to a body's centre of mass for the current sub-step.
| entityID | Entity to affect. |
| force | Force vector in world space (N). |
| void Raven::PhysicsWorld::AddImpulse | ( | u64 | entityID, |
| const Crux::vec3 & | impulse ) |
Applies an instantaneous linear impulse to a body's centre of mass.
| entityID | Entity to affect. |
| impulse | Impulse vector in world space (kg·m/s). |
| void Raven::PhysicsWorld::AddLinearVelocity | ( | u64 | entityID, |
| const Crux::vec3 & | velocity ) |
Adds a delta to the current linear velocity.
| entityID | Entity to affect. |
| velocity | Velocity delta in world space (m/s). |
| void Raven::PhysicsWorld::AddTorque | ( | u64 | entityID, |
| const Crux::vec3 & | torque ) |
Applies a continuous torque to a body for the current sub-step.
| entityID | Entity to affect. |
| torque | Torque vector in world space (N·m). |
| u32 Raven::PhysicsWorld::CreateBody | ( | u64 | entityID, |
| const BodyTransform & | transform, | ||
| const RigidBodyDesc & | desc, | ||
| const JPH::Shape * | shape ) |
Creates a rigid body for the given entity and registers it in the world.
| entityID | Unique engine entity identifier. |
| transform | Initial world-space position and orientation. |
| desc | Motion type, material properties, and mass. |
| shape | Pre-built Jolt collision shape (must remain valid for the body's lifetime). |
u32 via GetIndexAndSequenceNumber. | u32 Raven::PhysicsWorld::CreateMeshBody | ( | u64 | entityID, |
| u32 | bodyID, | ||
| const BodyTransform & | transform, | ||
| const JPH::Shape * | shape ) |
Creates a static mesh body, optionally reusing a specific Jolt body ID.
| entityID | Unique engine entity identifier. |
| bodyID | Desired Jolt body ID packed as u32, or 0xFFFFFFFF to let Jolt assign one. |
| transform | Initial world-space position and orientation. |
| shape | Pre-built triangle mesh or other static Jolt shape. |
u32. | JPH::Ref< JPH::Shape > Raven::PhysicsWorld::CreateShape | ( | const RigidBodyDesc & | desc | ) |
Builds a Jolt collision shape from a RigidBodyDesc.
| desc | Descriptor whose Shape, HalfExtent, Radius, and HalfHeight fields are used. |
| void Raven::PhysicsWorld::DestroyBody | ( | u64 | entityID | ) |
Removes the body associated with the given entity and frees its Jolt resources.
| entityID | Entity whose body should be destroyed. No-op if not found. |
| Crux::vec3 Raven::PhysicsWorld::GetAngularVelocity | ( | u64 | entityID | ) | const |
Returns the current angular velocity of a body.
| entityID | Entity to query. |
| Crux::vec3 Raven::PhysicsWorld::GetLinearVelocity | ( | u64 | entityID | ) | const |
Returns the current linear velocity of a body.
| entityID | Entity to query. |
| bool Raven::PhysicsWorld::HasBody | ( | u64 | entityID | ) | const |
Returns whether the world currently tracks a body for the given entity.
| entityID | Entity to query. |
true if a body exists. | void Raven::PhysicsWorld::Init | ( | ) |
Initialises the Jolt PhysicsSystem using the global Pulsar configuration.
Must be called after Pulsar::Init and before any body-creation calls.
| void Raven::PhysicsWorld::MoveKinematic | ( | u64 | entityID, |
| const BodyTransform & | transform, | ||
| float | dt ) |
Drives a kinematic body to the target pose over the given time delta.
| entityID | Entity to move. Must have BodyMotionType::Kinematic. |
| transform | Target world-space position and Euler rotation. |
| dt | Time delta used to derive the implicit velocity (seconds). |
| void Raven::PhysicsWorld::SetActive | ( | u64 | entityID, |
| bool | active ) |
Activates or deactivates a body in the simulation.
| entityID | Entity to configure. |
| active | true to activate, false to put to sleep. |
| void Raven::PhysicsWorld::SetAngularVelocity | ( | u64 | entityID, |
| const Crux::vec3 & | velocity ) |
Overwrites the angular velocity of a body.
| entityID | Entity to affect. |
| velocity | New angular velocity in world space (rad/s). |
| void Raven::PhysicsWorld::SetGravityFactor | ( | u64 | entityID, |
| float | factor ) |
Scales the global gravity vector for a single body.
| entityID | Entity to configure. |
| factor | Multiplier applied to world gravity (0 = weightless, 1 = full gravity). |
| void Raven::PhysicsWorld::SetLinearVelocity | ( | u64 | entityID, |
| const Crux::vec3 & | velocity ) |
Overwrites the linear velocity of a body.
| entityID | Entity to affect. |
| velocity | New linear velocity in world space (m/s). |
| void Raven::PhysicsWorld::SetTransform | ( | u64 | entityID, |
| const BodyTransform & | transform ) |
Teleports a body to a new position and orientation without waking it.
| entityID | Entity to reposition. |
| transform | Desired world-space position and Euler rotation. |
| void Raven::PhysicsWorld::Shutdown | ( | ) |
Removes all bodies from the simulation and releases Jolt resources.
| void Raven::PhysicsWorld::Step | ( | ) |
Advances the simulation by one fixed time step.
Uses PhysicsConfiguration::FixedTimeStep and PhysicsConfiguration::MaxSubSteps from the global Pulsar configuration.
| void Raven::PhysicsWorld::SyncTransform | ( | u64 | entityID, |
| BodyTransform & | outTransform ) const |
Reads the current Jolt body state into a BodyTransform.
| entityID | Entity to query. |
| outTransform | Receives the world-space position and Euler rotation. Unchanged if not found. |
|
inline |
Acquires a read lock on a body and invokes a callback with it.
The callback is skipped if the entity has no registered body or if the lock cannot be acquired. The lock is released before the function returns.
| Fn | Callable with signature void(const JPH::Body&). |
| entityID | Entity whose body to access. |
| fn | Callback receiving the locked JPH::Body reference. |