Browse Source

add pause and play buttons to gooey

main
cinnaboot 4 years ago
parent
commit
dc004d5fe4
  1. 21
      src/gooey.cpp
  2. 2
      src/gooey.h
  3. 12
      src/main.cpp

21
src/gooey.cpp

@ -45,14 +45,14 @@ void drawEllipseParameters(ellipse_parameters& ep);
void drawGravitaationalBody(grav_body& body); void drawGravitaationalBody(grav_body& body);
void drawOrbitalElements(orbital_elements& el); void drawOrbitalElements(orbital_elements& el);
void drawSatelliteWindow(satellite& sat); void drawSatelliteWindow(satellite& sat);
void drawSystemWindow(system_2body& sys); void drawSystemWindow(system_2body& sys, bool& running);
const static int G_WIDTH = 300; const static int G_WIDTH = 300;
const static ImVec2 V_SPACER(0, 10); const static ImVec2 V_SPACER(0, 10);
const int H_FLAGS = ImGuiTreeNodeFlags_DefaultOpen; const int H_FLAGS = ImGuiTreeNodeFlags_DefaultOpen;
void void
gooDraw(SDL_Window* window, system_2body& sys) gooDraw(SDL_Window* window, system_2body& sys, bool& running)
{ {
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window); ImGui_ImplSDL2_NewFrame(window);
@ -64,7 +64,7 @@ gooDraw(SDL_Window* window, system_2body& sys)
ImGui::SetNextWindowSize(ImVec2(G_WIDTH, y)); ImGui::SetNextWindowSize(ImVec2(G_WIDTH, y));
ImGui::Begin("Gooey"); ImGui::Begin("Gooey");
drawSystemWindow(sys); drawSystemWindow(sys, running);
drawSatelliteWindow(sys.sat); drawSatelliteWindow(sys.sat);
drawGravitaationalBody(sys.body); drawGravitaationalBody(sys.body);
drawOrbitalElements(sys.elements); drawOrbitalElements(sys.elements);
@ -124,19 +124,20 @@ drawSatelliteWindow(satellite& sat)
ImGui::Text("flight path angle: %f", sat.gamma); ImGui::Text("flight path angle: %f", sat.gamma);
ImGui::Dummy(V_SPACER); 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::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::Text("time_step:");
ImGui::SameLine(); ImGui::SameLine();
uint step = 1; ImGui::InputDouble("##", &sys.time_step, 1);
ImGui::InputScalar("##other.time_step",
ImGuiDataType_U32,
&sys.time_step, &step
);
ImGui::Text("epsilon, spec. orb. energy: %f", sys.epsilon); ImGui::Text("epsilon, spec. orb. energy: %f", sys.epsilon);
ImGui::Text("h, angular momentum: %f", sys.h); ImGui::Text("h, angular momentum: %f", sys.h);
ImGui::Text("r_apoapsis: %f", sys.r_apoapsis); ImGui::Text("r_apoapsis: %f", sys.r_apoapsis);

2
src/gooey.h

@ -16,5 +16,5 @@ bool
gooProcessEvent(SDL_Event &e); gooProcessEvent(SDL_Event &e);
void void
gooDraw(SDL_Window* window, system_2body& sys); gooDraw(SDL_Window* window, system_2body& sys, bool& running);

12
src/main.cpp

@ -14,6 +14,7 @@
const double SCALING = 0.001; const double SCALING = 0.001;
static bool g_running = false;
static system_2body g_sys = {0}; static system_2body g_sys = {0};
static MemoryArena* g_arena = nullptr; static MemoryArena* g_arena = nullptr;
@ -128,6 +129,7 @@ loadScene(RenderState* rs)
double mu = 398601.68; // NOTE: gravitational parameter double mu = 398601.68; // NOTE: gravitational parameter
double r = 6378; // NOTE: body radius in km double r = 6378; // NOTE: body radius in km
g_sys = systemInit(gravBodyInit(mu, r), orbitInit(a, e)); g_sys = systemInit(gravBodyInit(mu, r), orbitInit(a, e));
g_running = true;
// TODO: streamline the boilerplate in init_X_Entity functions // TODO: streamline the boilerplate in init_X_Entity functions
g_arena = arenaInit(16); g_arena = arenaInit(16);
@ -201,11 +203,12 @@ preFrameCallback(RenderState* rs)
void void
postFrameCallback(RenderState* rs) 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; static Entity* satellite = nullptr;
gooDraw(rs->handles.window, g_sys, g_running);
if (g_running) {
updateSatelliteModel(g_sys, g_sys.sat);
g_sys.ep = ellipseInitAE(g_sys.ep.a, g_sys.ep.e);
if (satellite == nullptr) { if (satellite == nullptr) {
RenderGroup* rg = getRenderGroupByName(rs, "manual mesh group"); RenderGroup* rg = getRenderGroupByName(rs, "manual mesh group");
@ -215,6 +218,7 @@ postFrameCallback(RenderState* rs)
assert(satellite); assert(satellite);
updateSatelliteEntity(satellite, g_sys.sat); updateSatelliteEntity(satellite, g_sys.sat);
//updateOrbit(g_sys, ellipse_entity); //updateOrbit(g_sys, ellipse_entity);
}
} }
int int

Loading…
Cancel
Save