From dc004d5fe47558ea11de27b71c20f14104f0da0d Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Thu, 24 Mar 2022 16:44:50 -0400 Subject: [PATCH] add pause and play buttons to gooey --- src/gooey.cpp | 21 +++++++++++---------- src/gooey.h | 2 +- src/main.cpp | 26 +++++++++++++++----------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/gooey.cpp b/src/gooey.cpp index 39bb5e4..18ad5fa 100644 --- a/src/gooey.cpp +++ b/src/gooey.cpp @@ -45,14 +45,14 @@ void drawEllipseParameters(ellipse_parameters& ep); void drawGravitaationalBody(grav_body& body); void drawOrbitalElements(orbital_elements& el); void drawSatelliteWindow(satellite& sat); -void drawSystemWindow(system_2body& sys); +void drawSystemWindow(system_2body& sys, bool& running); const static int G_WIDTH = 300; const static ImVec2 V_SPACER(0, 10); const int H_FLAGS = ImGuiTreeNodeFlags_DefaultOpen; void -gooDraw(SDL_Window* window, system_2body& sys) +gooDraw(SDL_Window* window, system_2body& sys, bool& running) { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplSDL2_NewFrame(window); @@ -64,7 +64,7 @@ gooDraw(SDL_Window* window, system_2body& sys) ImGui::SetNextWindowSize(ImVec2(G_WIDTH, y)); ImGui::Begin("Gooey"); - drawSystemWindow(sys); + drawSystemWindow(sys, running); drawSatelliteWindow(sys.sat); drawGravitaationalBody(sys.body); drawOrbitalElements(sys.elements); @@ -124,19 +124,20 @@ drawSatelliteWindow(satellite& sat) ImGui::Text("flight path angle: %f", sat.gamma); ImGui::Dummy(V_SPACER); } - } -void drawSystemWindow(system_2body& sys) +void drawSystemWindow(system_2body& sys, bool& running) { if (ImGui::CollapsingHeader("2 Body System:", H_FLAGS)) { + if (ImGui::Button("||")) running = false; + ImGui::SameLine(); + if (ImGui::Button("|>")) running = true; + ImGui::SameLine(); + ImGui::Text("running: %s", (running > 0) ? "true" : "false"); + ImGui::Text("time_step:"); ImGui::SameLine(); - uint step = 1; - ImGui::InputScalar("##other.time_step", - ImGuiDataType_U32, - &sys.time_step, &step - ); + ImGui::InputDouble("##", &sys.time_step, 1); ImGui::Text("epsilon, spec. orb. energy: %f", sys.epsilon); ImGui::Text("h, angular momentum: %f", sys.h); ImGui::Text("r_apoapsis: %f", sys.r_apoapsis); diff --git a/src/gooey.h b/src/gooey.h index 2a7c358..153f45d 100644 --- a/src/gooey.h +++ b/src/gooey.h @@ -16,5 +16,5 @@ bool gooProcessEvent(SDL_Event &e); void -gooDraw(SDL_Window* window, system_2body& sys); +gooDraw(SDL_Window* window, system_2body& sys, bool& running); diff --git a/src/main.cpp b/src/main.cpp index b83f886..e76e85a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ const double SCALING = 0.001; +static bool g_running = false; static system_2body g_sys = {0}; static MemoryArena* g_arena = nullptr; @@ -128,6 +129,7 @@ loadScene(RenderState* rs) double mu = 398601.68; // NOTE: gravitational parameter double r = 6378; // NOTE: body radius in km g_sys = systemInit(gravBodyInit(mu, r), orbitInit(a, e)); + g_running = true; // TODO: streamline the boilerplate in init_X_Entity functions g_arena = arenaInit(16); @@ -201,20 +203,22 @@ preFrameCallback(RenderState* rs) void postFrameCallback(RenderState* rs) { - gooDraw(rs->handles.window, g_sys); - g_sys.ep = ellipseInitAE(g_sys.ep.a, g_sys.ep.e); - updateSatelliteModel(g_sys, g_sys.sat); - static Entity* satellite = nullptr; + gooDraw(rs->handles.window, g_sys, g_running); - if (satellite == nullptr) { - RenderGroup* rg = getRenderGroupByName(rs, "manual mesh group"); - satellite = getEntityByName(rg, "ship 01"); - } + if (g_running) { + updateSatelliteModel(g_sys, g_sys.sat); + g_sys.ep = ellipseInitAE(g_sys.ep.a, g_sys.ep.e); - assert(satellite); - updateSatelliteEntity(satellite, g_sys.sat); - //updateOrbit(g_sys, ellipse_entity); + if (satellite == nullptr) { + RenderGroup* rg = getRenderGroupByName(rs, "manual mesh group"); + satellite = getEntityByName(rg, "ship 01"); + } + + assert(satellite); + updateSatelliteEntity(satellite, g_sys.sat); + //updateOrbit(g_sys, ellipse_entity); + } } int