Owns the Jolt PhysicsSystem and manages the lifecycle of all physics bodies.
More...
#include <kphysicsmanager.h>
Owns the Jolt PhysicsSystem and manages the lifecycle of all physics bodies.
Create one kPhysicsManager per scene. Call init() once, then step the simulation each frame with update(). After each update, sync moving objects back to their scene nodes via kObject::syncFromPhysics().
myObject->attachPhysics(box);
myObject->syncFromPhysics();
kPhysicsManager()
Constructs an uninitialised manager; call init() before use.
void update(float deltaTime)
Advances the simulation by deltaTime seconds.
kPhysicsObject * createObject(const kPhysicsObjectDesc &desc)
Creates a physics body and returns a new kPhysicsObject.
Represents a single rigid body or trigger volume inside the physics simulation.
Definition kphysicsobject.h:131
@ Box
Axis-aligned box defined by half-extents.
Definition kphysicsobject.h:25
KEMENA3D_API kPhysicsManager * createPhysicsManager()
Create and initialise the physics manager.
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33
All parameters needed to create a kPhysicsObject.
Definition kphysicsobject.h:92
kVec3 position
Definition kphysicsobject.h:95
kPhysicsShapeDesc shape
Definition kphysicsobject.h:93
kVec3 halfExtents
Box / Plane: per-axis half-extents (Plane uses x,z).
Definition kphysicsobject.h:59
kPhysicsShapeType type
Definition kphysicsobject.h:58
◆ kPhysicsManager()
| kemena::kPhysicsManager::kPhysicsManager |
( |
| ) |
|
Constructs an uninitialised manager; call init() before use.
◆ ~kPhysicsManager()
| kemena::kPhysicsManager::~kPhysicsManager |
( |
| ) |
|
Destroys the manager, calling shutdown() to release all bodies.
◆ createCharacter()
Creates a character controller in this physics world.
The returned pointer is owned by the manager; release it with destroyCharacter(). Each character's ground state is refreshed inside update() after the world steps.
- Parameters
-
| desc | Capsule + motion parameters. |
- Returns
- Pointer to the new kCharacterController, or nullptr on failure.
◆ createObject()
Creates a physics body and returns a new kPhysicsObject.
The returned pointer is owned by this manager. Release it with destroyObject() rather than deleting it directly.
- Parameters
-
| desc | Full shape and motion parameters. |
- Returns
- Pointer to the new kPhysicsObject, or nullptr on failure.
◆ destroyCharacter()
Removes a character controller from the simulation and destroys it.
- Parameters
-
◆ destroyObject()
| void kemena::kPhysicsManager::destroyObject |
( |
kPhysicsObject * | object | ) |
|
Removes a physics body from the simulation and destroys the object.
- Parameters
-
◆ getGravity()
| kVec3 kemena::kPhysicsManager::getGravity |
( |
| ) |
const |
Returns the current global gravity vector (m/s²).
◆ init()
| bool kemena::kPhysicsManager::init |
( |
| ) |
|
Initialises the Jolt physics engine and internal systems.
- Returns
- true on success.
◆ raycast()
Casts a ray into the physics world and returns the closest hit.
Intended for game-play use — requires objects to have physics bodies attached (created via createObject()). For editor picking without physics bodies, use kRenderer::pickObject() instead.
camera->screenToRay(mouseX, mouseY, vpW, vpH, origin, dir);
auto hit = physicsManager->raycast(origin, dir, 1000.0f);
if (hit.hit)
myObject->setPosition(hit.hitPoint);
- Parameters
-
| origin | Ray origin in world space. |
| direction | Normalised ray direction in world space. |
| maxDistance | Maximum distance along the ray to test. |
- Returns
- kPhysicsRaycastHit with hit == false if no body was struck.
◆ setGravity()
| void kemena::kPhysicsManager::setGravity |
( |
const kVec3 & | gravity | ) |
|
Sets the global gravity vector (m/s²).
- Parameters
-
| gravity | Acceleration vector — default is kVec3(0, -9.81, 0). |
◆ shutdown()
| void kemena::kPhysicsManager::shutdown |
( |
| ) |
|
Destroys all physics bodies and tears down the engine. Called automatically by the destructor.
◆ update()
| void kemena::kPhysicsManager::update |
( |
float | deltaTime | ) |
|
Advances the simulation by deltaTime seconds.
- Parameters
-
| deltaTime | Time since the last frame in seconds. Call this once per game-loop iteration before reading body transforms. |
The documentation for this class was generated from the following file: