|
|
|
|
@ -9,6 +9,23 @@
|
|
|
|
|
#include "orbits.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const static int G_WIDTH = 350; |
|
|
|
|
const static ImVec2 V_SPACER(0, 10); |
|
|
|
|
const int H_FLAGS = ImGuiTreeNodeFlags_DefaultOpen; |
|
|
|
|
|
|
|
|
|
// forward declarations
|
|
|
|
|
|
|
|
|
|
void drawSimulationWindow(bool& running, u64 sim_time_ms, float& sim_speed); |
|
|
|
|
void drawOrbitWindow(GameState* gs); |
|
|
|
|
void drawEllipseParameters(EllipseParameters& ep); |
|
|
|
|
void drawGravitationalBody(GravBody& body); |
|
|
|
|
void drawOrbitalElements(OrbitalElements& el); |
|
|
|
|
void drawSatelliteWindow(Satellite& sat); |
|
|
|
|
void drawSystemWindow(TwoBodySystem& sys); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// interface
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
gooInit(SDL_Window* window, SDL_GLContext gl_context) |
|
|
|
|
{ |
|
|
|
|
@ -41,20 +58,8 @@ gooProcessEvent(SDL_Event& e)
|
|
|
|
|
|| ImGui::GetIO().WantCaptureKeyboard); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void drawSimulationWindow(bool& running, u64 sim_time_ms, float& sim_speed); |
|
|
|
|
void drawEllipseParameters(EllipseParameters& ep); |
|
|
|
|
void drawGravitaationalBody(GravBody& body); |
|
|
|
|
void drawOrbitalElements(OrbitalElements& el); |
|
|
|
|
void drawSatelliteWindow(Satellite& sat); |
|
|
|
|
void drawSystemWindow(TwoBodySystem& 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, TwoBodySystem& sys, |
|
|
|
|
bool& running, u64 sim_time_ms, float& sim_speed) |
|
|
|
|
gooDraw(SDL_Window* window, GameState* gs) |
|
|
|
|
{ |
|
|
|
|
ImGui_ImplOpenGL3_NewFrame(); |
|
|
|
|
ImGui_ImplSDL2_NewFrame(window); |
|
|
|
|
@ -66,52 +71,106 @@ gooDraw(SDL_Window* window, TwoBodySystem& sys,
|
|
|
|
|
ImGui::SetNextWindowSize(ImVec2(G_WIDTH, y)); |
|
|
|
|
ImGui::Begin("Gooey"); |
|
|
|
|
|
|
|
|
|
drawSimulationWindow(running, sim_time_ms, sim_speed); |
|
|
|
|
drawSimulationWindow(gs->running, gs->sim_time_ms, gs->sim_speed); |
|
|
|
|
ImGui::Separator(); |
|
|
|
|
|
|
|
|
|
drawOrbitWindow(gs); |
|
|
|
|
ImGui::Separator(); |
|
|
|
|
#if 0 |
|
|
|
|
assert(gs->orbits[0].in_use); |
|
|
|
|
TwoBodySystem& sys = gs->orbits[0].system; |
|
|
|
|
drawSystemWindow(sys); |
|
|
|
|
drawSatelliteWindow(sys.sat); |
|
|
|
|
drawGravitaationalBody(sys.body); |
|
|
|
|
drawGravitationalBody(sys.body); |
|
|
|
|
drawOrbitalElements(sys.elements); |
|
|
|
|
drawEllipseParameters(sys.ep); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
ImGui::End(); |
|
|
|
|
ImGui::Render(); |
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// internal
|
|
|
|
|
|
|
|
|
|
void drawSimulationWindow(bool& running, u64 sim_time_ms, float& sim_speed) |
|
|
|
|
{ |
|
|
|
|
if (ImGui::CollapsingHeader("Simulation:", 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("sim time: %.2f s", |
|
|
|
|
double(double(sim_time_ms) / 1000)); |
|
|
|
|
ImGui::InputFloat("sim speed", &sim_speed, 0.1, 4.0, "%.1f"); |
|
|
|
|
if (ImGui::Button("||")) running = false; |
|
|
|
|
ImGui::SameLine(); |
|
|
|
|
if (ImGui::Button("|>")) running = true; |
|
|
|
|
ImGui::SameLine(); |
|
|
|
|
ImGui::Text("running: %s", (running > 0) ? "true" : "false"); |
|
|
|
|
|
|
|
|
|
ImGui::Text("sim time: %.2f s", |
|
|
|
|
double(double(sim_time_ms) / 1000)); |
|
|
|
|
ImGui::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" |
|
|
|
|
"body and satellite properties.\n" |
|
|
|
|
"Select a satellite to perform an inertial\n" |
|
|
|
|
"maneuver\n"); |
|
|
|
|
|
|
|
|
|
ImGui::Text("Orbit Selection"); |
|
|
|
|
|
|
|
|
|
ImGui::BeginChild("orbit selection", ImVec2(G_WIDTH - 20, 100), true); |
|
|
|
|
static u32 selected = 0; |
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < gs->num_orbits; i++) { |
|
|
|
|
GameOrbit& orbit = gs->orbits[i]; |
|
|
|
|
|
|
|
|
|
if (orbit.in_use) { |
|
|
|
|
static const u32 label_len = 128; |
|
|
|
|
char label[label_len]; |
|
|
|
|
snprintf(label, label_len, "Orbit %d", i); |
|
|
|
|
|
|
|
|
|
if (ImGui::Selectable(label, selected == i)) { |
|
|
|
|
selected = i; |
|
|
|
|
orbit.selected = true; |
|
|
|
|
} else { |
|
|
|
|
orbit.selected = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ImGui::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);
|
|
|
|
|
drawSystemWindow(sys); |
|
|
|
|
ImGui::Separator(); |
|
|
|
|
drawGravitationalBody(sys.body); |
|
|
|
|
ImGui::Separator(); |
|
|
|
|
drawSatelliteWindow(sys.sat); |
|
|
|
|
ImGui::EndChild(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void drawEllipseParameters(EllipseParameters& 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); |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void drawGravitaationalBody(GravBody& body) |
|
|
|
|
void drawGravitationalBody(GravBody& 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); |
|
|
|
|
} |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void drawOrbitalElements(OrbitalElements& el) |
|
|
|
|
@ -123,30 +182,31 @@ void drawOrbitalElements(OrbitalElements& el)
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void drawSystemWindow(TwoBodySystem& sys) |
|
|
|
|
{ |
|
|
|
|
if (ImGui::CollapsingHeader("2 Body System:", H_FLAGS)) { |
|
|
|
|
ImGui::Text("System Info:"); |
|
|
|
|
ImGui::Indent(); |
|
|
|
|
ImGui::Text("orbital period: %f", sys.orbital_period); |
|
|
|
|
ImGui::Text("epsilon, spec. orb. energy: %f", sys.epsilon); |
|
|
|
|
ImGui::Text("h, angular momentum: %f", sys.h); |
|
|
|
|
@ -158,6 +218,5 @@ void drawSystemWindow(TwoBodySystem& sys)
|
|
|
|
|
double tof_periapse = |
|
|
|
|
orbitGetTimeOfFlight(sys, sys.sat.theta, 2 * M_PI); |
|
|
|
|
ImGui::Text("time to periapsis: %.2f seconds", tof_periapse); |
|
|
|
|
ImGui::Dummy(V_SPACER); |
|
|
|
|
} |
|
|
|
|
ImGui::Unindent(); |
|
|
|
|
} |
|
|
|
|
|