From 6844f4454c3a94feec1e03e0e2664944ebc27dd5 Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Wed, 21 Aug 2024 14:53:33 +0100 Subject: [PATCH] fix: use chrono for time --- src/main.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8a65103..992a39c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,6 +49,8 @@ #include #include +#include + // INPUT! // // what input do we even want in the first place? @@ -84,6 +86,12 @@ void clearInput() input.cycleAnimation = false; } +double getTime() +{ + auto now = std::chrono::steady_clock::now().time_since_epoch(); + return std::chrono::duration(now).count(); +} + int main() { GLFWwindow* window = nullptr; @@ -120,7 +128,8 @@ int main() const int ANIM_ORBITING = 0; const int ANIM_ECCENTRICITY = 1; int animation = 0; - float time = glfwGetTime(); + + double time = getTime(); // Main loop while (!glfwWindowShouldClose(window)) @@ -141,13 +150,14 @@ int main() } // only update time if playing the orbiting animation + const double speed = 0.5; if (animation == ANIM_ORBITING) { - time = glfwGetTime(); + time = getTime() * speed; } else { - float e = .25 + .2 * sin(glfwGetTime()); + double e = .25 + .2 * sin(getTime()); orbit.setEccentricity(e); }