diff --git a/src/gooey.cpp b/src/gooey.cpp index 59f8aa9..39bb5e4 100644 --- a/src/gooey.cpp +++ b/src/gooey.cpp @@ -41,63 +41,106 @@ gooProcessEvent(SDL_Event& e) || ImGui::GetIO().WantCaptureKeyboard); } +void drawEllipseParameters(ellipse_parameters& ep); +void drawGravitaationalBody(grav_body& body); +void drawOrbitalElements(orbital_elements& el); +void drawSatelliteWindow(satellite& sat); +void drawSystemWindow(system_2body& sys); + +const static int G_WIDTH = 300; +const static ImVec2 V_SPACER(0, 10); +const int H_FLAGS = ImGuiTreeNodeFlags_DefaultOpen; + void -gooDraw(SDL_Window* window, orbital_elements& orbit, uint& time_step) +gooDraw(SDL_Window* window, system_2body& sys) { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplSDL2_NewFrame(window); ImGui::NewFrame(); - const static int w = 300; int x = 0, y = 0; SDL_GetWindowSize(window, &x, &y); - ImGui::SetNextWindowPos(ImVec2(x - w, 0)); - ImGui::SetNextWindowSize(ImVec2(w, y)); - ImGui::Begin("Orbital Elements"); - - ImGui::Text("iota, inclination: %f", orbit.iota); - ImGui::Text("omega, argument of periapsis: %f", orbit.omega); - ImGui::Text("mu, gravitational parameter: %f", orbit.mu); - ImGui::Text("nu, true anomoly: "); - ImGui::InputDouble("##orbit.nu", &orbit.nu, 0.1f); - ImGui::SameLine(); - ImGui::Text(" radians"); - ImGui::Spacing(); - - ImGui::Separator(); - ImGui::Spacing(); - ImGui::Text("Ellipse Parameters:"); - ImGui::Text("semi-major axis, a: "); - ImGui::InputDouble("##orbit.ep.a", &orbit.ep.a, 1000.0f); - ImGui::SameLine(); - ImGui::Text(" km"); - ImGui::Text("semi-minor axis, b: %f km", orbit.ep.b); - ImGui::Text("eccentricity, e: "); - ImGui::InputDouble("##orbit.ep.e", &orbit.ep.e, 0.01f); - ImGui::Text("linear eccentricity, c: %f km", orbit.ep.c); - ImGui::Spacing(); - - ImGui::Separator(); - ImGui::Spacing(); - ImGui::Text("Other Parameters"); - ImGui::Spacing(); - ImGui::Text("time_step:"); - ImGui::SameLine(); - uint step = 1; - ImGui::InputScalar("##other.time_step", ImGuiDataType_U32, &time_step, &step); - ImGui::Spacing(); - ImGui::Text("Satellite Parameters:"); - ImGui::Text("position:"); - ImGui::Text(" x: %f km", orbit.pos.x); - ImGui::Text(" y: %f km", orbit.pos.y); - ImGui::Text(" z: %f km", orbit.pos.z); - ImGui::Text("velocity, km/s: %f", orbit.v); - ImGui::Text("flight path angle: %f", orbit.gamma); - ImGui::Text("epsilon, spec. orb. energy: %f", orbit.epsilon); - ImGui::Text("h, angular momentum: %f", orbit.h); + ImGui::SetNextWindowPos(ImVec2(x - G_WIDTH, 0)); + ImGui::SetNextWindowSize(ImVec2(G_WIDTH, y)); + ImGui::Begin("Gooey"); + + drawSystemWindow(sys); + drawSatelliteWindow(sys.sat); + drawGravitaationalBody(sys.body); + drawOrbitalElements(sys.elements); + drawEllipseParameters(sys.ep); ImGui::End(); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } +void drawEllipseParameters(ellipse_parameters& ep) +{ + if (ImGui::CollapsingHeader("Ellipse Parameters:", H_FLAGS)) { + 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); + ImGui::Dummy(V_SPACER); + } +} + +void drawGravitaationalBody(grav_body& body) +{ + if (ImGui::CollapsingHeader("Gravitational Body:", H_FLAGS)) { + ImGui::Text("mu, gravitational parameter: %f", body.mu); + ImGui::Text("r, radius in km: %f ", body.radius); + ImGui::Dummy(V_SPACER); + } +} + +void drawOrbitalElements(orbital_elements& 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); + ImGui::Dummy(V_SPACER); + } +} + +void +drawSatelliteWindow(satellite& sat) +{ + if (ImGui::CollapsingHeader("Satellite:", H_FLAGS)) { + ImGui::Text("Satellite Parameters:"); + ImGui::Text("theta, true anomaly: %f", sat.theta); + ImGui::Text("r, radial distance: %f km", sat.r); + ImGui::Text("position:"); + 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::Text("velocity, km/s: %f", sat.v); + ImGui::Text("flight path angle: %f", sat.gamma); + ImGui::Dummy(V_SPACER); + } + +} + +void drawSystemWindow(system_2body& sys) +{ + if (ImGui::CollapsingHeader("2 Body System:", H_FLAGS)) { + ImGui::Text("time_step:"); + ImGui::SameLine(); + uint step = 1; + ImGui::InputScalar("##other.time_step", + ImGuiDataType_U32, + &sys.time_step, &step + ); + 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); + ImGui::Text("r_periapsis: %f", sys.r_periapsis); + ImGui::Dummy(V_SPACER); + } +} diff --git a/src/gooey.h b/src/gooey.h index 781cb9a..2a7c358 100644 --- a/src/gooey.h +++ b/src/gooey.h @@ -16,5 +16,5 @@ bool gooProcessEvent(SDL_Event &e); void -gooDraw(SDL_Window* window, orbital_elements& orbit, uint& time_step); +gooDraw(SDL_Window* window, system_2body& sys); diff --git a/src/main.cpp b/src/main.cpp index 5949723..0b734f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -133,6 +133,9 @@ postFrameCallback(render_state* rs) } // TODO: will need more validation from GUI as added + // TODO: might be easier to preset valid ranges in gooey code see: + // https://github.com/ocornut/imgui/blob/master/imgui.h#L810 + // ^ description of IsItemDeactivatedAfterEdit(); if (!ellipsesEqual(c_orb.ep, g_orbit.ep)) { // NOTE: handle the case where semimajor axis lowered with low // eccentricity would fail validation