PhysicsSystem class in Thread
Singleton facade over Jolt Physics. The engine takes care of lifecycle and the
per-frame step; user code mostly calls these static functions to apply forces or
move kinematic bodies during gameplay.
Lifecycle
| Init() | bool | Register Jolt types, build the broadphase, allocate temp allocator + job system. Idempotent. |
| Shutdown() | void | Tear everything down. Called automatically on app exit. |
| IsInitialized() | bool | True after Init succeeded. |
| Step(dt, steps = 1) | void | Advance simulation. Called internally per runtime frame. |
Globals
| SetGravity(g) | void | World gravity vector. Default {0, -9.81, 0}. |
| GetGravity() | Thread::Vec3 | Current gravity. |
Body manipulation
| AddForce(bodyId, f) | void | Continuous force (N). Apply each frame for sustained accel. |
| AddImpulse(bodyId, imp) | void | Instant change of momentum — single-frame for jumps / explosions. |
| SetLinearVel(bodyId, v) | void | Overwrite linear velocity. |
| SetAngularVel(bodyId, v) | void | Overwrite angular velocity (rad/s). |
| SetBodyTransform(bodyId, p, r) | void | Teleport (and re-activate) a body. |
| GetBodyTransform(bodyId, &p, &r) | bool | Read current world position/rotation. |
Specialised constructors
| CreateHeightFieldBody(...) | uint32_t | Used internally by TerrainComponent. Resolution must be a multiple of 4. |
| CreateCharacter(desc) | void* | Spawns a Jolt CharacterVirtual. Used by CharacterControllerComponent. |
Example — one-shot impulse
void OnUpdate(float ts) override {
if (Input::WasKeyPressed(Key::Space)) {
auto& rb = GetComponent<Thread::RigidBodyComponent>();
Thread::PhysicsSystem::AddImpulse(rb.BodyId, Thread::Vec3(0.0f, 8.0f, 0.0f));
}
}
PhysicsSystem klasa w Thread
Singleton nad Jolt Physics. Silnik dba o cykl życia i krok symulacji co klatkę; kod gry głównie
wywołuje te statyczne funkcje, żeby przykładać siły albo przesuwać ciała kinematyczne.
Cykl życia
| Init() | bool | Rejestruje typy Jolt, buduje broadphase, przydziela alokator tymczasowy i system zadań. Idempotentne. |
| Shutdown() | void | Sprząta wszystko. Wywoływane automatycznie przy wyjściu z aplikacji. |
| IsInitialized() | bool | True po udanym Init. |
| Step(dt, steps = 1) | void | Przesuwa symulację. Wywoływane wewnętrznie co klatkę gry. |
Ustawienia globalne
| SetGravity(g) | void | Wektor grawitacji świata. Domyślnie {0, -9.81, 0}. |
| GetGravity() | Thread::Vec3 | Bieżąca grawitacja. |
Sterowanie ciałami
| AddForce(bodyId, f) | void | Ciągła siła (N). Przykładaj co klatkę dla stałego przyspieszenia. |
| AddImpulse(bodyId, imp) | void | Natychmiastowa zmiana pędu — jednorazowo przy skokach i wybuchach. |
| SetLinearVel(bodyId, v) | void | Nadpisuje prędkość liniową. |
| SetAngularVel(bodyId, v) | void | Nadpisuje prędkość kątową (rad/s). |
| SetBodyTransform(bodyId, p, r) | void | Teleportuje (i budzi) ciało. |
| GetBodyTransform(bodyId, &p, &r) | bool | Odczytuje bieżącą pozycję/rotację w świecie. |
Specjalne konstruktory
| CreateHeightFieldBody(...) | uint32_t | Używane wewnętrznie przez TerrainComponent. Rozdzielczość musi być wielokrotnością 4. |
| CreateCharacter(desc) | void* | Tworzy CharacterVirtual z Jolt. Używane przez CharacterControllerComponent. |
Przykład — jednorazowy impuls
void OnUpdate(float ts) override {
if (Input::WasKeyPressed(Key::Space)) {
auto& rb = GetComponent<Thread::RigidBodyComponent>();
Thread::PhysicsSystem::AddImpulse(rb.BodyId, Thread::Vec3(0.0f, 8.0f, 0.0f));
}
}