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

Loading…
Cancel
Save