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();
|
||||||
|
|
||||||
// Calculate the number of nanoseconds that elapsed since the previous call to this function
|
std::chrono::steady_clock::time_point now
|
||||||
long long timeDelta = std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime - _previousTimePoint).count();
|
= std::chrono::steady_clock::now();
|
||||||
// Convert the time delta in nanoseconds to seconds
|
|
||||||
double timeDeltaSeconds = (double)timeDelta / 1000000000.0;
|
|
||||||
|
|
||||||
// Store the previously measured current time
|
// nanoseconds delta
|
||||||
_previousTimePoint = currentTime;
|
long long td = std::chrono::duration_cast<std::chrono::nanoseconds>(now - _prev).count();
|
||||||
|
|
||||||
// Return the calculated time delta in seconds
|
_prev = now;
|
||||||
return timeDeltaSeconds;
|
|
||||||
|
return ((double)td) / 1000000000.0; // return as seconds
|
||||||
}
|
}
|
Loading…
Reference in New Issue