From 64755fc33dc6c964b73622085a589563be24a1fe Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 23 Mar 2021 18:15:30 -0400 Subject: [PATCH] add more inputs to demo application --- src/gooey.cpp | 49 +++++++++++++++++++++++++++++++++---------------- src/gooey.h | 2 +- src/main.cpp | 18 ++++++++++++------ src/orbits.cpp | 1 + src/orbits.h | 3 +++ 5 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/gooey.cpp b/src/gooey.cpp index 6f4eb49..93381af 100644 --- a/src/gooey.cpp +++ b/src/gooey.cpp @@ -42,42 +42,59 @@ gooProcessEvent(SDL_Event& e) } void -gooDraw(SDL_Window* window, orbital_elements& orbit) +gooDraw(SDL_Window* window, orbital_elements& orbit, uint& time_step) { - // Start the Dear ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplSDL2_NewFrame(window); ImGui::NewFrame(); - ImGui::SetNextWindowPos(ImVec2(0,0)); - ImGui::SetNextWindowSize(ImVec2(300,270)); + 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: %f", orbit.nu); + 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("a: %f km", orbit.ep.a); - ImGui::Text("b: %f km", orbit.ep.b); - ImGui::Text("e: %f", orbit.ep.e); - ImGui::Text("c: %f km", orbit.ep.c); - - - ImGui::Text("a:"); - ImGui::SameLine(); + ImGui::Text("semi-major axis, a: "); ImGui::InputDouble("##orbit.ep.a", &orbit.ep.a, 1000.0f); - - ImGui::Text("e:"); 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::End(); + 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("radial velocity:"); + ImGui::Text("flight path angle:"); + ImGui::End(); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } diff --git a/src/gooey.h b/src/gooey.h index 15cdbb5..781cb9a 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); +gooDraw(SDL_Window* window, orbital_elements& orbit, uint& time_step); diff --git a/src/main.cpp b/src/main.cpp index e0cfde3..310d62f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ const double SCALING = 0.001; static orbital_elements g_orbit = {}; static ellipse_3d g_ellipse3d; +static uint g_time_step = 100; simple_mesh* @@ -82,12 +83,10 @@ updateSatellitePosition(entity& satellite) glm::rotate(glm::mat4(1.0), (float) M_PI_2, glm::vec3(1, 0, 0)); // TODO: decouple framerate from time_step - unsigned int time_step = 100; // NOTE: seconds - - g_orbit.nu = getPropagatedTrueAnomaly(g_orbit, g_orbit.nu, time_step); + g_orbit.nu = getPropagatedTrueAnomaly(g_orbit, g_orbit.nu, g_time_step); double r2 = getRadialPosition(g_orbit.ep, g_orbit.nu); glm::vec2 coords = polarToRect(g_orbit.nu, r2); - glm::vec3 v = glm::vec3(coords, 0); + glm::vec3 v = g_orbit.pos = glm::vec3(coords, 0); entSetWorldPosition(satellite, xform * glm::vec4(v.x, v.y, v.z, 1)); } @@ -129,7 +128,7 @@ postFrameCallback(render_state* rs) { static orbital_elements c_orb = {}; orbitCopy(g_orbit, c_orb); - gooDraw(rs->handles->window, c_orb); + gooDraw(rs->handles->window, c_orb, g_time_step); // TODO: will need more validation from GUI as added if (!ellipsesEqual(c_orb.ep, g_orbit.ep)) { @@ -148,13 +147,20 @@ postFrameCallback(render_state* rs) updateOrbit(g_orbit, g_ellipse3d, ellipse_entity); } } + + if (c_orb.nu != g_orbit.nu && + ((c_orb.nu >= 0 && c_orb.nu <= M_PI) || + (c_orb.nu < 0 && c_orb.nu >= -1 * M_PI))) + { + g_orbit.nu = c_orb.nu; + } } int main() { render_state* rs = renInit("orbital shipping", - glm::vec2(1280, 720), + glm::vec2(1280, 800), SDL_INIT_TIMER); if (rs == nullptr) { diff --git a/src/orbits.cpp b/src/orbits.cpp index 53274e8..a6e8e15 100644 --- a/src/orbits.cpp +++ b/src/orbits.cpp @@ -61,6 +61,7 @@ orbitCopy(const orbital_elements& o1, orbital_elements& o2) o2.omega = o1.omega; o2.mu = o1.mu; o2.nu = o1.nu; + o2.pos = o1.pos; } ellipse_3d diff --git a/src/orbits.h b/src/orbits.h index 9a363bc..112e2d5 100644 --- a/src/orbits.h +++ b/src/orbits.h @@ -26,6 +26,9 @@ struct orbital_elements double omega; // NOTE: (ω) argument of periapsis double mu; // NOTE: (μ) gravitational parameter double nu; // NOTE: (ν) true anomaly + + glm::vec3 pos; // NOTE: true anomaly in 3d with ep.f2 at origin + double radial_velocity; }; struct ellipse_3d