feat: add moving platform support + fix jolt

This commit is contained in:
2026-10-18 13:34:30 +02:00
parent 65a7310b56
commit 7223e9ce07
15 changed files with 291 additions and 34 deletions
+43
View File
@@ -540,6 +540,48 @@ namespace {
"a frustum entirely behind the camera must not overlap");
}
void testKinematicBodiesMoveWithVelocity()
{
constexpr float fixedDt = 1.0f / 60.0f;
Scene& scene = SceneManager::GetInstance().CreateScene("kinematic-velocity");
GameObject* platform = scene.CreateGameObject("platform");
platform->AddComponent<BoxCollider>(glm::vec3{2.0f, 0.25f, 2.0f});
auto* platformBody = platform->AddComponent<Rigidbody>();
platformBody->SetType(RigidbodyType::Kinematic);
GameObject* crate = scene.CreateGameObject("crate");
crate->GetTransform().SetWorldPosition({0.0f, 0.76f, 0.0f});
crate->AddComponent<BoxCollider>(glm::vec3{0.5f});
auto* crateBody = crate->AddComponent<Rigidbody>();
crateBody->SetFriction(1.0f);
crateBody->SetAllowSleep(false);
scene.CommitPendingAdditions();
scene.GetPhysics().RefreshGameObject(*platform);
scene.GetPhysics().RefreshGameObject(*crate);
for (int step = 0; step < 30; ++step) {
scene.FixedUpdate(fixedDt);
}
check(glm::length(platformBody->GetLinearVelocity()) < 0.001f,
"a kinematic body that is not moved must have no velocity");
constexpr float platformSpeed = 2.0f;
for (int step = 0; step < 60; ++step) {
platform->GetTransform().SetWorldPosition(
platform->GetTransform().GetWorldPosition() + glm::vec3{platformSpeed * fixedDt, 0.0f, 0.0f});
scene.FixedUpdate(fixedDt);
}
check(close(platformBody->GetLinearVelocity().x, platformSpeed),
"a kinematic body moved through its transform must get the matching velocity");
check(crate->GetTransform().GetWorldPosition().x > 1.5f,
"a dynamic body resting on a moving kinematic platform must be carried along");
SceneManager::GetInstance().Destroy();
}
void testRenderer2DShapes()
{
auto& r2d = Renderer2D::GetInstance();
@@ -1335,6 +1377,7 @@ int main()
testColliderCenterOffset();
testCapsuleColliderDebugLines();
testFrustumFromViewProj();
testKinematicBodiesMoveWithVelocity();
testRenderer2DShapes();
testFontAtlasAndLayout();
std::cout << "destrum tests passed\n";