diff --git a/src/scene.cpp b/src/scene.cpp index 8d4f69d..4c88e7a 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -193,6 +193,7 @@ void step_scene(double timeDelta) { lightNode[1]->rotation.z -= timeDelta; //lightNode[1]->position.z = 80 + 40*glm::sin(5 * lightNode[1]->rotation.z); if(carNode) carNode->rotation.z += timeDelta; + if(treeNode) treeNode->rotation.z += timeDelta; /* if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1)) { diff --git a/src/utilities/timeutils.cpp b/src/utilities/timeutils.cpp index a3f480b..a51ed7e 100644 --- a/src/utilities/timeutils.cpp +++ b/src/utilities/timeutils.cpp @@ -1,23 +1,19 @@ #include #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. double getTimeDeltaSeconds() { - // Determine the current time - std::chrono::steady_clock::time_point currentTime = std::chrono::steady_clock::now(); + static std::chrono::steady_clock::time_point _prev + = 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 - long long timeDelta = std::chrono::duration_cast(currentTime - _previousTimePoint).count(); - // Convert the time delta in nanoseconds to seconds - double timeDeltaSeconds = (double)timeDelta / 1000000000.0; + // nanoseconds delta + long long td = std::chrono::duration_cast(now - _prev).count(); + + _prev = now; - // Store the previously measured current time - _previousTimePoint = currentTime; - - // Return the calculated time delta in seconds - return timeDeltaSeconds; -} \ No newline at end of file + return ((double)td) / 1000000000.0; // return as seconds +}