From cb12a31e8efa2f9227931d598bb75a78fe204224 Mon Sep 17 00:00:00 2001 From: urastogi2048 Date: Mon, 30 Mar 2026 00:02:40 +0530 Subject: [PATCH 1/2] chore/organising test cases --- app/test_scenarios.cpp | 110 +++++++++++++++++++++++++++++++++++++++++ app/test_scenarios.hpp | 14 +++++- renderer/window.cpp | 17 ++++++- 3 files changed, 138 insertions(+), 3 deletions(-) diff --git a/app/test_scenarios.cpp b/app/test_scenarios.cpp index c88f12f..de167a9 100644 --- a/app/test_scenarios.cpp +++ b/app/test_scenarios.cpp @@ -11,6 +11,20 @@ #define M_PI 3.14159265358979323846 #endif +std::vector chapters = {"Kinematics", "Laws of Motion", "Collision", "Rotation", "Fluids", "Thermal Properties"}; +std::unordered_map> testmap; + +void InitializeTestMap() +{ + testmap["Kinematics"] = {TestCase::ProjectMotion, TestCase::RelativeVelocity}; + testmap["Laws of Motion"] = {TestCase::NewtonThirdLaw}; + testmap["Collision"] = {TestCase::PerfectElasticCollision, TestCase::PerfectInelasticCollision, TestCase::Collision}; + testmap["Rotation"] = {TestCase::BoxToppleOnRamp, TestCase::SphereToppleOnRamp, TestCase::CollisionCauseTopple}; + testmap["Fluids"] = {TestCase::BuoyancyTest}; + testmap["Thermal Properties"] = {}; +} + + namespace { BoxCollider g_floor(Vec3(100.0f, 0.1f, 100.0f)); @@ -111,6 +125,92 @@ namespace return Camera(); } + Camera spawn_relative_velocity(PhysicsWorld &world) +{ + + + const float y = 0.5f; + + Vec3 pos1(-8.0f, y, 0.0f); + Vec3 pos2(8.0f, y, 0.0f); + + Vec3 vel1(15.0f, 0.0f, 0.0f); + Vec3 vel2(5.0f, 0.0f, 0.0f); + + Rigidbody b1(pos1, vel1, &g_small_sphere, 1.0f); + Rigidbody b2(pos2, vel2, &g_small_sphere, 1.0f); + + b1.restitution = 0.0f; + b2.restitution = 0.0f; + b1.friction = 0.0f; + b2.friction = 0.0f; + + world.addBody(b1); + world.addBody(b2); + + return Camera().setPosition(glm::vec3(0.0f, 3.0f, 20.0f)); +} + + Camera spawn_newton_third_law(PhysicsWorld &world) +{ + + + const float y = 0.5f; + Vec3 pos1(-10.0f, y, 0.0f); + Vec3 vel1(12.0f, 0.0f, 0.0f); + Rigidbody light_body(pos1, vel1, &g_small_sphere, 0.5f); + + Vec3 pos2(10.0f, y, 0.0f); + Vec3 vel2(-6.0f, 0.0f, 0.0f); + Rigidbody heavy_body(pos2, vel2, &g_big_sphere, 2.0f); + light_body.restitution = 1.0f; + heavy_body.restitution = 1.0f; + light_body.friction = 0.0f; + heavy_body.friction = 0.0f; + + world.addBody(light_body); + world.addBody(heavy_body); + return Camera().setPosition(glm::vec3(0.0f, 3.0f, 25.0f)); +} + + Camera spawn_box_topple_on_ramp(PhysicsWorld &world) +{ + + world.addBody(Rigidbody(Vec3(0.0f, 0.0f, 0.0f), Vec3(), &g_steep_ramp, 0.0f)); + Rigidbody toppling_box(Vec3(0.0f, 4.0f, 0.0f), Vec3(), &g_wide_box, 1.5f); + toppling_box.friction = 0.3f; + toppling_box.restitution = 0.4f; + world.addBody(toppling_box); + + return Camera().setPosition(glm::vec3(8.0f, 6.0f, 20.0f)); +} + + Camera spawn_sphere_topple_on_ramp(PhysicsWorld &world) +{ + world.addBody(Rigidbody(Vec3(0.0f, 0.0f, 0.0f), Vec3(), &g_steep_ramp, 0.0f)); + Rigidbody rolling_sphere(Vec3(0.0f, 4.0f, 0.0f), Vec3(), &g_big_sphere, 1.2f); + rolling_sphere.friction = 0.2f; + rolling_sphere.restitution = 0.6f; + world.addBody(rolling_sphere); + + return Camera().setPosition(glm::vec3(8.0f, 6.0f, 20.0f)); +} + + Camera spawn_collision_cause_topple(PhysicsWorld &world) +{ world.addBody(Rigidbody(Vec3(0.0f, 0.0f, 0.0f), Vec3(), &g_gentle_ramp, 0.0f)); + + Rigidbody moving_box(Vec3(-8.0f, 6.0f, 0.0f), Vec3(8.0f, 0.0f, 0.0f), &g_small_box, 2.0f); + moving_box.friction = 0.1f; + moving_box.restitution = 0.5f; + world.addBody(moving_box); + Rigidbody target_sphere(Vec3(4.0f, 1.0f, 0.0f), Vec3(), &g_small_sphere, 1.0f); + target_sphere.friction = 0.2f; + target_sphere.restitution = 0.7f; + world.addBody(target_sphere); + + return Camera().setPosition(glm::vec3(0.0f, 4.0f, 20.0f)); +} + void add_floor(PhysicsWorld &world) { // Keep floor top at y=0 so scenario bodies spawn above, not inside. @@ -551,6 +651,16 @@ Camera LoadSingleTestScenario(PhysicsWorld &world, TestCase test_case) return spawn_perfect_inelastic_collision(world); case TestCase::Collision: return spawn_collision_partial(world); + case TestCase::RelativeVelocity: + return spawn_relative_velocity(world); + case TestCase::NewtonThirdLaw: + return spawn_newton_third_law(world); + case TestCase::BoxToppleOnRamp: + return spawn_box_topple_on_ramp(world); + case TestCase::SphereToppleOnRamp: + return spawn_sphere_topple_on_ramp(world); + case TestCase::CollisionCauseTopple: + return spawn_collision_cause_topple(world); case TestCase::BuoyancyTest: world.enable_buoyancy = true; world.water_fluid = Fluid(2.0f, 2.0f, 0.3f); diff --git a/app/test_scenarios.hpp b/app/test_scenarios.hpp index 6ae7dc5..fec8366 100644 --- a/app/test_scenarios.hpp +++ b/app/test_scenarios.hpp @@ -1,5 +1,8 @@ #pragma once #include "../renderer/camera.hpp" +#include +#include +#include class PhysicsWorld; enum class TestCase @@ -8,7 +11,16 @@ enum class TestCase PerfectElasticCollision, PerfectInelasticCollision, Collision, - BuoyancyTest + BuoyancyTest, + RelativeVelocity, + NewtonThirdLaw, + BoxToppleOnRamp, + SphereToppleOnRamp, + CollisionCauseTopple }; +extern std::vector chapters; +extern std::unordered_map> testmap; + +void InitializeTestMap(); Camera LoadSingleTestScenario(PhysicsWorld &world, TestCase test_case); diff --git a/renderer/window.cpp b/renderer/window.cpp index 89ddb71..2f8ab77 100644 --- a/renderer/window.cpp +++ b/renderer/window.cpp @@ -30,7 +30,12 @@ namespace TestCase::PerfectElasticCollision, TestCase::PerfectInelasticCollision, TestCase::Collision, - TestCase::BuoyancyTest + TestCase::BuoyancyTest, + TestCase::RelativeVelocity, + TestCase::NewtonThirdLaw, + TestCase::BoxToppleOnRamp, + TestCase::SphereToppleOnRamp, + TestCase::CollisionCauseTopple }; constexpr const char *kTestCaseNames[] = { @@ -38,7 +43,12 @@ namespace "Perfectly Elastic Collision", "Perfectly Inelastic Collision", "Realistic Collision", - "Buoyancy Test" + "Buoyancy Test", + "Relative Velocity", + "Newton's Third Law", + "Box Topple on Ramp", + "Sphere Topple on Ramp", + "Collision Cause Topple" }; constexpr const char *kGravityPresetNames[] = { @@ -82,6 +92,9 @@ static void ShowTooltip(const char *text) void CreateWindow(PhysicsWorld &world) { + // Initialize test scenario mapping + InitializeTestMap(); + // Initialize and configure GLFW glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); From 0529b84715ce4709901d0a78e1d416e40f751a63 Mon Sep 17 00:00:00 2001 From: urastogi2048 Date: Mon, 30 Mar 2026 18:13:41 +0530 Subject: [PATCH 2/2] merged --- renderer/window.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/renderer/window.cpp b/renderer/window.cpp index 5eff9e5..324202a 100644 --- a/renderer/window.cpp +++ b/renderer/window.cpp @@ -83,26 +83,15 @@ namespace "Corner-to-corner impacts show how contact point offsets create torque.", "Contrast high-friction rolling with sliding motion on ramps and flats.", "Observe how buoyant forces affect floating objects in simulated fluids.", - "Watch boxes and spheres equalize heat via conduction and radiation with temperature-driven colors." + "Watch boxes and spheres equalize heat via conduction and radiation with temperature-driven colors.", + "", + "", + "", + "", + "" }; - constexpr const char *kTestCaseDescriptions[] = { - "Compare low and high launch angles to visualize projectile motion trajectories.", - "Observe conservation of momentum and energy with two identical spheres.", - "See how kinetic energy is lost when colliding bodies stick together.", - "Study partially elastic impacts with friction to mimic everyday collisions.", - "Watch gravity components down a ramp to discuss inclined-plane forces.", - "A Newton's-cradle style lineup highlights momentum transfer through a chain.", - "Side impacts on a tall stack reveal how torque about the COM drives tipping.", - "Rope, rod, and spring constraints run side-by-side for Hooke's law comparisons.", - "Off-center hits demonstrate how tangential impulses spin bodies up.", - "Sequential pushes on a block tower highlight angular momentum build-up.", - "Corner-to-corner impacts show how contact point offsets create torque.", - "Contrast high-friction rolling with sliding motion on ramps and flats.", - "Observe how buoyant forces affect floating objects in simulated fluids.", - "Watch boxes and spheres equalize heat via conduction and radiation with temperature-driven colors." - }; constexpr const char *kGravityPresetNames[] = {