From 68e26c64c95dabf0e1f187a288562c0bd722bc59 Mon Sep 17 00:00:00 2001 From: ktyl Date: Sun, 8 Oct 2023 00:13:32 +0100 Subject: [PATCH] feat(orbit): cycle animation --- src/main.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ef40713..0828e25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,12 +73,25 @@ int main() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float time = glfwGetTime(); + const float orbitalPeriod = 6.284; - float e = .25 + .2 * sin(time); - keplerianElements[astro::eccentricityIndex] = e; - orbit.setElements(keplerianElements); + const int ANIM_ORBITING = 0; + const int ANIM_ECCENTRICITY = 1; + int animation = (int)(time / orbitalPeriod) % 2 == 1; - glm::vec3 pos = orbit.getPosition(time); + glm::vec3 pos; + if (animation == ANIM_ORBITING) + { + pos = orbit.getPosition(time); + } + else if (animation == ANIM_ECCENTRICITY) + { + float e = .25 + .2 * sin(time); + keplerianElements[astro::eccentricityIndex] = e; + orbit.setElements(keplerianElements); + + pos = orbit.getPosition(0); + } orbiter.setPosition(pos); // Render lit objects