From c9bc8983e623814c5e2a7a81677ab52312f9831a Mon Sep 17 00:00:00 2001 From: louis-langholtz Date: Mon, 27 Nov 2017 18:01:43 -0700 Subject: [PATCH] For issue #217 and issue #225. Adds configurability to solar system demo for much larger bomb sizes and densities. --- Testbed/Framework/Main.cpp | 5 ++++- Testbed/Framework/Test.cpp | 6 +++--- Testbed/Framework/Test.hpp | 2 ++ Testbed/Tests/SolarSystem.hpp | 26 +++++++++++++++++++++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Testbed/Framework/Main.cpp b/Testbed/Framework/Main.cpp index 937c510748..08ed066030 100644 --- a/Testbed/Framework/Main.cpp +++ b/Testbed/Framework/Main.cpp @@ -708,13 +708,16 @@ static void AboutTestUI() for (auto& handledKey: handledKeys) { const auto keyID = handledKey.first.key; + const auto mods = handledKey.first.mods; ImGui::TextUnformatted(GetKeyActionName(handledKey.first.action)); ImGui::NextColumn(); if (std::isgraph(keyID)) { - ImGui::Text("%c", keyID); + const auto shift = mods & GLFW_MOD_SHIFT; + const auto ctrl = mods & GLFW_MOD_CONTROL; + ImGui::Text("%s%s%c", (ctrl? "ctrl-": ""), (shift? "shift-": ""), keyID); } else { diff --git a/Testbed/Framework/Test.cpp b/Testbed/Framework/Test.cpp index 3ba7e6d3f2..b9f517ff0b 100644 --- a/Testbed/Framework/Test.cpp +++ b/Testbed/Framework/Test.cpp @@ -602,8 +602,8 @@ void Test::LaunchBomb(const Length2& at, const LinearVelocity2 v) .UseLocation(at).UseLinearVelocity(v)); auto conf = DiskShape::Conf{}; - conf.vertexRadius = 0.3_m; - conf.density = 20_kgpm2; + conf.vertexRadius = m_bombRadius; + conf.density = m_bombDensity; conf.restitution = 0.0f; m_bomb->CreateFixture(std::make_shared(conf)); } @@ -1252,7 +1252,7 @@ void Test::KeyboardHandler(KeyID key, KeyAction action, KeyMods mods) { continue; } - if (mods & keyActionMods.mods) + if (mods != keyActionMods.mods) { continue; } diff --git a/Testbed/Framework/Test.hpp b/Testbed/Framework/Test.hpp index cc6817b5b5..24258fe439 100644 --- a/Testbed/Framework/Test.hpp +++ b/Testbed/Framework/Test.hpp @@ -320,6 +320,8 @@ class Test : public ContactListener std::string m_status; TextLinePos m_textLine = TextLinePos{30}; + AreaDensity m_bombDensity = 20_kgpm2; + Length m_bombRadius = 0.3_m; private: void DrawStats(const StepConf& stepConf, UiState& ui); diff --git a/Testbed/Tests/SolarSystem.hpp b/Testbed/Tests/SolarSystem.hpp index 6449b785b7..e2903a9abc 100644 --- a/Testbed/Tests/SolarSystem.hpp +++ b/Testbed/Tests/SolarSystem.hpp @@ -92,7 +92,7 @@ class SolarSystem: public Test auto conf = Test::Conf{}; conf.description = os.str(); - conf.worldDef = WorldDef{}.UseMaxVertexRadius(700000_km); + conf.worldDef = WorldDef{}.UseMaxVertexRadius(1e7_km); conf.neededSettings = 0; conf.neededSettings |= (1u << NeedLinearSlopField); conf.neededSettings |= (1u << NeedCameraZoom); @@ -111,6 +111,8 @@ class SolarSystem: public Test SolarSystem(): Test(GetTestConf()) { + m_bombRadius = 100_km; + m_bombDensity = 2e12_kgpm2; m_world.SetGravity(LinearAcceleration2{}); const auto DynamicBD = BodyDef{}.UseType(BodyType::Dynamic).UseBullet(true); for (auto& sso: SolarSystemBodies) @@ -140,6 +142,26 @@ class SolarSystem: public Test [&](KeyActionMods) { m_focalBody = nullptr; }); + RegisterForKey(GLFW_KEY_S, GLFW_PRESS, GLFW_MOD_SHIFT, + "Increases bomb size.", + [&](KeyActionMods) { + m_bombRadius *= 2; + }); + RegisterForKey(GLFW_KEY_S, GLFW_PRESS, 0, + "Decreases bomb size.", + [&](KeyActionMods) { + m_bombRadius /= 2;; + }); + RegisterForKey(GLFW_KEY_D, GLFW_PRESS, GLFW_MOD_SHIFT, + "Increases bomb density.", + [&](KeyActionMods) { + m_bombDensity *= 2; + }); + RegisterForKey(GLFW_KEY_D, GLFW_PRESS, 0, + "Decreases bomb density.", + [&](KeyActionMods) { + m_bombDensity /= 2;; + }); } void PreStep(const Settings&, Drawer& drawer) override @@ -161,6 +183,8 @@ class SolarSystem: public Test { os << "Camera unlocked from following any planet."; } + os << " 'Bomb' size (radial) is now at " << Real{m_bombRadius/1_km} << "km."; + os << " 'Bomb' density (areal) is now at " << Real{m_bombDensity/1_kgpm2} << "kg/m^2."; m_status = os.str(); }