From 67fd7895f41618c2aecc4b9bfcd81a7859282977 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 17 Mar 2021 15:11:47 -0400 Subject: [PATCH] use new updateSimpleMesh to update orbit from gooey --- ext/tangerine | 2 +- src/gooey.cpp | 10 ++++++++-- src/main.cpp | 31 +++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/ext/tangerine b/ext/tangerine index e412f21..ca151b5 160000 --- a/ext/tangerine +++ b/ext/tangerine @@ -1 +1 @@ -Subproject commit e412f21c7e3ca25283cdd8fe7db7d093bc63bc92 +Subproject commit ca151b5c770eb586c697fe3d29c49f0de3450e1e diff --git a/src/gooey.cpp b/src/gooey.cpp index 456b88c..6d7d33d 100644 --- a/src/gooey.cpp +++ b/src/gooey.cpp @@ -6,6 +6,7 @@ #include #include "gooey.h" +#include "orbits.h" bool @@ -56,8 +57,13 @@ gooDraw(SDL_Window* window, orbital_elements& orbit) ImGui::Text("e: %f", orbit.ep.e); ImGui::Text("mu: %f km^3/s^2", orbit.mu); - static char str0[128] = "Hello"; - ImGui::InputText("testing", str0, IM_ARRAYSIZE(str0)); + ImGui::Text("a:"); + ImGui::SameLine(); + ImGui::InputDouble("##orbit.ep.a", &orbit.ep.a, 1000.0f); + + ImGui::Text("e:"); + ImGui::SameLine(); + ImGui::InputDouble("##orbit.ep.e", &orbit.ep.e, 0.1f); ImGui::End(); diff --git a/src/main.cpp b/src/main.cpp index 3f40934..9625c15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,14 +82,37 @@ doFrameCallbackPre(render_state* rs) { // handle input static input_state is = {}; - // TODO: probably need to break the while loop out of inputProcessEvents - // so we can send individual sdl events to ImGui_ImplSDL2_ProcessEvent() - // via gooProcessEvent() - inputProcessEvents(&is); + SDL_Event e; + bool gooey_wants = false; + + while (SDL_PollEvent(&e)) { + gooey_wants = gooProcessEvent(e); + if (!gooey_wants) inputProcessEvent(&is, e); + } if (is.window_closed || is.escape) rs->running = false; + // update orbital elements/ellipse_3d + // TODO: could really use another ellipse constructor that uses a and e + g_orbit.ep = constructEllipseAB(g_orbit.ep.a, + g_orbit.ep.a * sqrt(1 - pow(g_orbit.ep.e, 2.0))); + entity& ellipse_entity = rs->render_groups[0].entities[0]; + + // TODO: fix this + double angle = 2 * M_PI / g_ellipse.vert_count; + for (uint i = 0; i < g_ellipse.vert_count; i++) { + double a = angle * i; + double r = g_orbit.ep.a * + (1 - pow(g_orbit.ep.e, 2)) / (1 + g_orbit.ep.e * cos(a)); + g_ellipse.vertices[i] = glm::vec3(polarToRect(a, r), 0); + // NOTE: update mesh + ellipse_entity.mesh->vertices[i] = g_ellipse.vertices[i]; + // NOTE: update entity.render_object + entUpdateSimpleMesh(ellipse_entity, ellipse_entity.mesh, GL_LINE_LOOP); + } + + // update satellite position const static glm::mat4 xform = glm::rotate(glm::mat4(1.0), (float) M_PI_2, glm::vec3(1, 0, 0));