diff options
Diffstat (limited to 'src/tests/test_physics.cc')
| -rw-r--r-- | src/tests/test_physics.cc | 93 |
1 files changed, 46 insertions, 47 deletions
diff --git a/src/tests/test_physics.cc b/src/tests/test_physics.cc index a59502c..df21e70 100644 --- a/src/tests/test_physics.cc +++ b/src/tests/test_physics.cc @@ -101,51 +101,50 @@ void test_bvh() { assert(results.size() == 0); // Query both - results.clear(); - bvh.query({{-12, -2, -2}, {12, 2, 2}}, results); - assert(results.size() == 2); - } - - void test_physics_falling() { - std::cout << "Testing Physics falling..." << std::endl; - Scene scene; - - // Plane at y = -1 - Object3D plane(ObjectType::PLANE); - plane.position = {0, -1, 0}; - plane.is_static = true; - scene.add_object(plane); - - // Sphere at y = 5 - Object3D sphere(ObjectType::SPHERE); - sphere.position = {0, 5, 0}; - sphere.velocity = {0, 0, 0}; - sphere.restitution = 0.0f; // No bounce for simple test - scene.add_object(sphere); - - PhysicsSystem physics; - float dt = 0.016f; - for (int i = 0; i < 100; ++i) { - physics.update(scene, dt); - } - - // Sphere should be above or at plane (y >= 0 because sphere radius is 1, - // plane is at -1) - assert(scene.objects[1].position.y >= -0.01f); - // Also should have slowed down - assert(scene.objects[1].velocity.y > -1.0f); - } - - int main() { - test_sdf_sphere(); - test_sdf_box(); - test_sdf_torus(); - test_sdf_plane(); - test_calc_normal(); - test_bvh(); - test_physics_falling(); - - std::cout << "--- ALL PHYSICS TESTS PASSED ---" << std::endl; - return 0; + results.clear(); + bvh.query({{-12, -2, -2}, {12, 2, 2}}, results); + assert(results.size() == 2); +} + +void test_physics_falling() { + std::cout << "Testing Physics falling..." << std::endl; + Scene scene; + + // Plane at y = -1 + Object3D plane(ObjectType::PLANE); + plane.position = {0, -1, 0}; + plane.is_static = true; + scene.add_object(plane); + + // Sphere at y = 5 + Object3D sphere(ObjectType::SPHERE); + sphere.position = {0, 5, 0}; + sphere.velocity = {0, 0, 0}; + sphere.restitution = 0.0f; // No bounce for simple test + scene.add_object(sphere); + + PhysicsSystem physics; + float dt = 0.016f; + for (int i = 0; i < 100; ++i) { + physics.update(scene, dt); } -
\ No newline at end of file + + // Sphere should be above or at plane (y >= 0 because sphere radius is 1, + // plane is at -1) + assert(scene.objects[1].position.y >= -0.01f); + // Also should have slowed down + assert(scene.objects[1].velocity.y > -1.0f); +} + +int main() { + test_sdf_sphere(); + test_sdf_box(); + test_sdf_torus(); + test_sdf_plane(); + test_calc_normal(); + test_bvh(); + test_physics_falling(); + + std::cout << "--- ALL PHYSICS TESTS PASSED ---" << std::endl; + return 0; +} |
