Remove noise from timeutils.cpp
This commit is contained in:
parent
0475f17110
commit
2cac6e1766
|
@ -193,6 +193,7 @@ void step_scene(double timeDelta) {
|
||||||
lightNode[1]->rotation.z -= timeDelta;
|
lightNode[1]->rotation.z -= timeDelta;
|
||||||
//lightNode[1]->position.z = 80 + 40*glm::sin(5 * lightNode[1]->rotation.z);
|
//lightNode[1]->position.z = 80 + 40*glm::sin(5 * lightNode[1]->rotation.z);
|
||||||
if(carNode) carNode->rotation.z += timeDelta;
|
if(carNode) carNode->rotation.z += timeDelta;
|
||||||
|
if(treeNode) treeNode->rotation.z += timeDelta;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1)) {
|
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1)) {
|
||||||
|
|
|
@ -1,23 +1,19 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include "timeutils.h"
|
#include "timeutils.h"
|
||||||
|
|
||||||
// In order to be able to calculate when the getTimeDeltaSeconds() function was last called, we need to know the point in time when that happened. This requires us to keep hold of that point in time.
|
|
||||||
// We initialise this value to the time at the start of the program.
|
|
||||||
static std::chrono::steady_clock::time_point _previousTimePoint = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
// Calculates the elapsed time since the previous time this function was called.
|
// Calculates the elapsed time since the previous time this function was called.
|
||||||
double getTimeDeltaSeconds() {
|
double getTimeDeltaSeconds() {
|
||||||
// Determine the current time
|
static std::chrono::steady_clock::time_point _prev
|
||||||
std::chrono::steady_clock::time_point currentTime = std::chrono::steady_clock::now();
|
= std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
std::chrono::steady_clock::time_point now
|
||||||
|
= std::chrono::steady_clock::now();
|
||||||
|
|
||||||
// Calculate the number of nanoseconds that elapsed since the previous call to this function
|
// nanoseconds delta
|
||||||
long long timeDelta = std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime - _previousTimePoint).count();
|
long long td = std::chrono::duration_cast<std::chrono::nanoseconds>(now - _prev).count();
|
||||||
// Convert the time delta in nanoseconds to seconds
|
|
||||||
double timeDeltaSeconds = (double)timeDelta / 1000000000.0;
|
_prev = now;
|
||||||
|
|
||||||
// Store the previously measured current time
|
return ((double)td) / 1000000000.0; // return as seconds
|
||||||
_previousTimePoint = currentTime;
|
}
|
||||||
|
|
||||||
// Return the calculated time delta in seconds
|
|
||||||
return timeDeltaSeconds;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue