Browse Source

add pause and play buttons to gooey

main
cinnaboot 4 years ago
parent
commit
dc004d5fe4
  1. 21
      src/gooey.cpp
  2. 2
      src/gooey.h
  3. 26
      src/main.cpp

21
src/gooey.cpp

@ -45,14 +45,14 @@ void drawEllipseParameters(ellipse_parameters& ep);
void drawGravitaationalBody(grav_body& body);
void drawOrbitalElements(orbital_elements& el);
void drawSatelliteWindow(satellite& sat);
void drawSystemWindow(system_2body& sys);
void drawSystemWindow(system_2body& sys, bool& running);
const static int G_WIDTH = 300;
const static ImVec2 V_SPACER(0, 10);
const int H_FLAGS = ImGuiTreeNodeFlags_DefaultOpen;
void
gooDraw(SDL_Window* window, system_2body& sys)
gooDraw(SDL_Window* window, system_2body& sys, bool& running)
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window);
@ -64,7 +64,7 @@ gooDraw(SDL_Window* window, system_2body& sys)
ImGui::SetNextWindowSize(ImVec2(G_WIDTH, y));
ImGui::Begin("Gooey");
drawSystemWindow(sys);
drawSystemWindow(sys, running);
drawSatelliteWindow(sys.sat);
drawGravitaationalBody(sys.body);
drawOrbitalElements(sys.elements);
@ -124,19 +124,20 @@ drawSatelliteWindow(satellite& sat)
ImGui::Text("flight path angle: %f", sat.gamma);
ImGui::Dummy(V_SPACER);
}
}
void drawSystemWindow(system_2body& sys)
void drawSystemWindow(system_2body& sys, bool& running)
{
if (ImGui::CollapsingHeader("2 Body System:", 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("time_step:");
ImGui::SameLine();
uint step = 1;
ImGui::InputScalar("##other.time_step",
ImGuiDataType_U32,
&sys.time_step, &step
);
ImGui::InputDouble("##", &sys.time_step, 1);
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);

2
src/gooey.h

@ -16,5 +16,5 @@ bool
gooProcessEvent(SDL_Event &e);
void
gooDraw(SDL_Window* window, system_2body& sys);
gooDraw(SDL_Window* window, system_2body& sys, bool& running);

26
src/main.cpp

@ -14,6 +14,7 @@
const double SCALING = 0.001;
static bool g_running = false;
static system_2body g_sys = {0};
static MemoryArena* g_arena = nullptr;
@ -128,6 +129,7 @@ loadScene(RenderState* rs)
double mu = 398601.68; // NOTE: gravitational parameter
double r = 6378; // NOTE: body radius in km
g_sys = systemInit(gravBodyInit(mu, r), orbitInit(a, e));
g_running = true;
// TODO: streamline the boilerplate in init_X_Entity functions
g_arena = arenaInit(16);
@ -201,20 +203,22 @@ preFrameCallback(RenderState* rs)
void
postFrameCallback(RenderState* rs)
{
gooDraw(rs->handles.window, g_sys);
g_sys.ep = ellipseInitAE(g_sys.ep.a, g_sys.ep.e);
updateSatelliteModel(g_sys, g_sys.sat);
static Entity* satellite = nullptr;
gooDraw(rs->handles.window, g_sys, g_running);
if (satellite == nullptr) {
RenderGroup* rg = getRenderGroupByName(rs, "manual mesh group");
satellite = getEntityByName(rg, "ship 01");
}
if (g_running) {
updateSatelliteModel(g_sys, g_sys.sat);
g_sys.ep = ellipseInitAE(g_sys.ep.a, g_sys.ep.e);
assert(satellite);
updateSatelliteEntity(satellite, g_sys.sat);
//updateOrbit(g_sys, ellipse_entity);
if (satellite == nullptr) {
RenderGroup* rg = getRenderGroupByName(rs, "manual mesh group");
satellite = getEntityByName(rg, "ship 01");
}
assert(satellite);
updateSatelliteEntity(satellite, g_sys.sat);
//updateOrbit(g_sys, ellipse_entity);
}
}
int

Loading…
Cancel
Save