Browse Source

use ImGui namespace in gooey.cpp

main
cinnaboot 4 years ago
parent
commit
3c12a4ea42
  1. 148
      src/gooey.cpp

148
src/gooey.cpp

@ -4,6 +4,7 @@
#include <imgui.h> #include <imgui.h>
#include <backends/imgui_impl_opengl3.h> #include <backends/imgui_impl_opengl3.h>
#include <backends/imgui_impl_sdl.h> #include <backends/imgui_impl_sdl.h>
using namespace ImGui;
#include "gooey.h" #include "gooey.h"
#include "orbits.h" #include "orbits.h"
@ -30,10 +31,10 @@ bool
gooInit(SDL_Window* window, SDL_GLContext gl_context) gooInit(SDL_Window* window, SDL_GLContext gl_context)
{ {
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); CreateContext();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = GetIO();
io.IniFilename = NULL; // don't save window state to imgui.ini io.IniFilename = NULL; // don't save window state to imgui.ini
ImGui::StyleColorsDark(); StyleColorsDark();
bool ret = true; bool ret = true;
ret = ret && ImGui_ImplSDL2_InitForOpenGL(window, gl_context); ret = ret && ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
@ -47,15 +48,15 @@ gooFree()
{ {
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown(); ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext(); DestroyContext();
} }
bool bool
gooProcessEvent(SDL_Event& e) gooProcessEvent(SDL_Event& e)
{ {
ImGui_ImplSDL2_ProcessEvent(&e); ImGui_ImplSDL2_ProcessEvent(&e);
return (ImGui::GetIO().WantCaptureMouse return (GetIO().WantCaptureMouse
|| ImGui::GetIO().WantCaptureKeyboard); || GetIO().WantCaptureKeyboard);
} }
void void
@ -63,19 +64,20 @@ gooDraw(SDL_Window* window, GameState* gs)
{ {
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window); ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame(); NewFrame();
int x = 0, y = 0; int x = 0, y = 0;
SDL_GetWindowSize(window, &x, &y); SDL_GetWindowSize(window, &x, &y);
ImGui::SetNextWindowPos(ImVec2(x - G_WIDTH, 0)); SetNextWindowPos(ImVec2(x - G_WIDTH, 0));
ImGui::SetNextWindowSize(ImVec2(G_WIDTH, y)); SetNextWindowSize(ImVec2(G_WIDTH, y));
ImGui::Begin("Gooey"); Begin("Gooey");
drawSimulationWindow(gs->running, gs->sim_time_ms, gs->sim_speed); drawSimulationWindow(gs->running, gs->sim_time_ms, gs->sim_speed);
ImGui::Separator(); Separator();
drawOrbitWindow(gs); drawOrbitWindow(gs);
ImGui::Separator(); Separator();
drawManeuverWinow(gs);
#if 0 #if 0
assert(gs->orbits[0].in_use); assert(gs->orbits[0].in_use);
TwoBodySystem& sys = gs->orbits[0].system; TwoBodySystem& sys = gs->orbits[0].system;
@ -86,9 +88,9 @@ gooDraw(SDL_Window* window, GameState* gs)
drawEllipseParameters(sys.ep); drawEllipseParameters(sys.ep);
#endif #endif
ImGui::End(); End();
ImGui::Render(); Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(GetDrawData());
} }
@ -96,27 +98,27 @@ gooDraw(SDL_Window* window, GameState* gs)
void drawSimulationWindow(bool& running, u64 sim_time_ms, float& sim_speed) void drawSimulationWindow(bool& running, u64 sim_time_ms, float& sim_speed)
{ {
if (ImGui::Button("||")) running = false; if (Button("||")) running = false;
ImGui::SameLine(); SameLine();
if (ImGui::Button("|>")) running = true; if (Button("|>")) running = true;
ImGui::SameLine(); SameLine();
ImGui::Text("running: %s", (running > 0) ? "true" : "false"); Text("running: %s", (running > 0) ? "true" : "false");
ImGui::Text("sim time: %.2f s", Text("sim time: %.2f s",
double(double(sim_time_ms) / 1000)); double(double(sim_time_ms) / 1000));
ImGui::InputFloat("sim speed", &sim_speed, 0.1, 4.0, "%.1f"); InputFloat("sim speed", &sim_speed, 0.1, 4.0, "%.1f");
} }
void drawOrbitWindow(GameState* gs) void drawOrbitWindow(GameState* gs)
{ {
ImGui::Text("WIP: Show a list of orbits, with grav\n" Text("WIP: Show a list of orbits, with grav\n"
"body and satellite properties.\n" "body and satellite properties.\n"
"Select a satellite to perform an inertial\n" "Select a satellite to perform an inertial\n"
"maneuver\n"); "maneuver\n");
ImGui::Text("Orbit Selection"); Text("Orbit Selection");
ImGui::BeginChild("orbit selection", ImVec2(G_WIDTH - 20, 100), true); BeginChild("orbit selection", ImVec2(G_WIDTH - 20, 100), true);
static u32 selected = 0; static u32 selected = 0;
for (u32 i = 0; i < gs->num_orbits; i++) { for (u32 i = 0; i < gs->num_orbits; i++) {
@ -127,7 +129,7 @@ void drawOrbitWindow(GameState* gs)
char label[label_len]; char label[label_len];
snprintf(label, label_len, "Orbit %d", i); snprintf(label, label_len, "Orbit %d", i);
if (ImGui::Selectable(label, selected == i)) { if (Selectable(label, selected == i)) {
selected = i; selected = i;
orbit.selected = true; orbit.selected = true;
} else { } else {
@ -136,87 +138,87 @@ void drawOrbitWindow(GameState* gs)
} }
} }
ImGui::EndChild(); EndChild();
if (selected < gs->num_orbits if (selected < gs->num_orbits
&& gs->orbits[selected].in_use) && gs->orbits[selected].in_use)
{ {
TwoBodySystem& sys = gs->orbits[selected].system; TwoBodySystem& sys = gs->orbits[selected].system;
ImGui::BeginChild("orbit details", ImVec2(G_WIDTH - 20, 400), true); BeginChild("orbit details", ImVec2(G_WIDTH - 20, 400), true);
ImGui::Text("Selected Orbit#: %d", selected); Text("Selected Orbit#: %d", selected);
//ImGui::Text("Orbital Period: %.2fs", sys.orbital_period); //Text("Orbital Period: %.2fs", sys.orbital_period);
drawSystemWindow(sys); drawSystemWindow(sys);
ImGui::Separator(); Separator();
drawGravitationalBody(sys.body); drawGravitationalBody(sys.body);
ImGui::Separator(); Separator();
drawSatelliteWindow(sys.sat); drawSatelliteWindow(sys.sat);
ImGui::EndChild(); EndChild();
} }
} }
void drawEllipseParameters(EllipseParameters& ep) void drawEllipseParameters(EllipseParameters& ep)
{ {
ImGui::Text("semi_major axis, a: %f km", ep.a); Text("semi_major axis, a: %f km", ep.a);
ImGui::Text("semi_minor axis, b: %f km", ep.b); Text("semi_minor axis, b: %f km", ep.b);
ImGui::Text("eccentricity, e: %f ", ep.e); Text("eccentricity, e: %f ", ep.e);
ImGui::Text("linear eccentricity, c: %f km", ep.c); Text("linear eccentricity, c: %f km", ep.c);
ImGui::Text("semilatus rectum, p: %f km", ep.p); Text("semilatus rectum, p: %f km", ep.p);
} }
void drawGravitationalBody(GravBody& body) void drawGravitationalBody(GravBody& body)
{ {
ImGui::Text("Grav Body:"); Text("Grav Body:");
ImGui::Indent(); Indent();
ImGui::Text("mu, gravitational parameter: %.3f", body.mu); Text("mu, gravitational parameter: %.3f", body.mu);
ImGui::Text("r, radius in km: %.3f", body.radius); Text("r, radius in km: %.3f", body.radius);
ImGui::Unindent(); Unindent();
} }
void drawOrbitalElements(OrbitalElements& el) void drawOrbitalElements(OrbitalElements& el)
{ {
if (ImGui::CollapsingHeader("Orbital Elements", H_FLAGS)) { if (CollapsingHeader("Orbital Elements", H_FLAGS)) {
ImGui::Text("semi_major axis, a: %f km", el.a); Text("semi_major axis, a: %f km", el.a);
ImGui::Text("eccentricity, e: %f", el.e); Text("eccentricity, e: %f", el.e);
ImGui::Text("iota, inclination: %f", el.iota); Text("iota, inclination: %f", el.iota);
ImGui::Text("ohm, longitude ascending node: %f", el.ohm); Text("ohm, longitude ascending node: %f", el.ohm);
ImGui::Text("omega, argument of periapsis: %f", el.omega); Text("omega, argument of periapsis: %f", el.omega);
ImGui::Text("nu, true anomaly at T0: %f", el.nu); Text("nu, true anomaly at T0: %f", el.nu);
} }
} }
void void
drawSatelliteWindow(Satellite& sat) drawSatelliteWindow(Satellite& sat)
{ {
ImGui::Text("Satellite Parameters:"); Text("Satellite Parameters:");
ImGui::Indent(); Indent();
ImGui::Text("theta, true anomaly: %f", sat.theta); Text("theta, true anomaly: %f", sat.theta);
ImGui::Text("r, radial distance: %f km", sat.r); Text("r, radial distance: %f km", sat.r);
ImGui::Text("position:"); Text("position:");
ImGui::Indent(); Indent();
ImGui::Text("x: %f km", sat.position.x); Text("x: %f km", sat.position.x);
ImGui::Text("y: %f km", sat.position.y); Text("y: %f km", sat.position.y);
ImGui::Text("z: %f km", sat.position.z); Text("z: %f km", sat.position.z);
ImGui::Unindent(); Unindent();
ImGui::Text("velocity, km/s: %f", sat.v); Text("velocity, km/s: %f", sat.v);
ImGui::Text("flight path angle: %f", sat.gamma); Text("flight path angle: %f", sat.gamma);
ImGui::Unindent(); Unindent();
} }
void drawSystemWindow(TwoBodySystem& sys) void drawSystemWindow(TwoBodySystem& sys)
{ {
ImGui::Text("System Info:"); Text("System Info:");
ImGui::Indent(); Indent();
ImGui::Text("orbital period: %.2f s", sys.orbital_period); Text("orbital period: %.2f s", sys.orbital_period);
ImGui::Text("epsilon, spec. orb. energy: %f", sys.epsilon); Text("epsilon, spec. orb. energy: %f", sys.epsilon);
ImGui::Text("h, angular momentum: %f", sys.h); Text("h, angular momentum: %f", sys.h);
ImGui::Text("r_apoapsis: %f km", sys.r_apoapsis); Text("r_apoapsis: %f km", sys.r_apoapsis);
ImGui::Text("r_periapsis: %f km", sys.r_periapsis); Text("r_periapsis: %f km", sys.r_periapsis);
// FIXME: not ideal to call into orbit interface from the gooey // FIXME: not ideal to call into orbit interface from the gooey
double tof_apoapse = orbitGetTimeOfFlight(sys, sys.sat.theta, M_PI); double tof_apoapse = orbitGetTimeOfFlight(sys, sys.sat.theta, M_PI);
ImGui::Text("time to apoapsis: %.2f s", tof_apoapse); Text("time to apoapsis: %.2f s", tof_apoapse);
double tof_periapse = double tof_periapse =
orbitGetTimeOfFlight(sys, sys.sat.theta, 2 * M_PI); orbitGetTimeOfFlight(sys, sys.sat.theta, 2 * M_PI);
ImGui::Text("time to periapsis: %.2f s", tof_periapse); Text("time to periapsis: %.2f s", tof_periapse);
ImGui::Unindent(); Unindent();
} }

Loading…
Cancel
Save