fix: use chrono for time

This commit is contained in:
Cat Flynn 2024-08-21 14:53:33 +01:00
parent ae3e5c201b
commit 6844f4454c
1 changed files with 13 additions and 3 deletions

View File

@ -49,6 +49,8 @@
#include <skein/particle.h> #include <skein/particle.h>
#include <skein/particlemap.h> #include <skein/particlemap.h>
#include <chrono>
// INPUT! // INPUT!
// //
// what input do we even want in the first place? // what input do we even want in the first place?
@ -84,6 +86,12 @@ void clearInput()
input.cycleAnimation = false; input.cycleAnimation = false;
} }
double getTime()
{
auto now = std::chrono::steady_clock::now().time_since_epoch();
return std::chrono::duration<double>(now).count();
}
int main() int main()
{ {
GLFWwindow* window = nullptr; GLFWwindow* window = nullptr;
@ -120,7 +128,8 @@ int main()
const int ANIM_ORBITING = 0; const int ANIM_ORBITING = 0;
const int ANIM_ECCENTRICITY = 1; const int ANIM_ECCENTRICITY = 1;
int animation = 0; int animation = 0;
float time = glfwGetTime();
double time = getTime();
// Main loop // Main loop
while (!glfwWindowShouldClose(window)) while (!glfwWindowShouldClose(window))
@ -141,13 +150,14 @@ int main()
} }
// only update time if playing the orbiting animation // only update time if playing the orbiting animation
const double speed = 0.5;
if (animation == ANIM_ORBITING) if (animation == ANIM_ORBITING)
{ {
time = glfwGetTime(); time = getTime() * speed;
} }
else else
{ {
float e = .25 + .2 * sin(glfwGetTime()); double e = .25 + .2 * sin(getTime());
orbit.setEccentricity(e); orbit.setEccentricity(e);
} }