|
@@ -12,6 +12,8 @@
|
|
|
#include <imgui_sdl.h>
|
|
|
#include <imgui_impl_sdl.h>
|
|
|
|
|
|
+#include <physics/constants.h>
|
|
|
+
|
|
|
void application::parseParameters(int argc, char *argv[])
|
|
|
{
|
|
|
// Nothing to do for now
|
|
@@ -20,7 +22,7 @@ void application::parseParameters(int argc, char *argv[])
|
|
|
void application::setup()
|
|
|
{
|
|
|
this->running = graphics::openWindow();
|
|
|
-
|
|
|
+ this->millisecsPreviousFrame = SDL_GetTicks();
|
|
|
this->part = new particle(50, 100, 1.0);
|
|
|
}
|
|
|
|
|
@@ -50,9 +52,20 @@ void application::input()
|
|
|
|
|
|
void application::update()
|
|
|
{
|
|
|
- this->part->velocity = vec2(2, 0);
|
|
|
+ /* Let's make sure we are running at the expected framerate */
|
|
|
+ uint32_t now = SDL_GetTicks();
|
|
|
+ int32_t timeToWait = MILLISECS_PER_FRAME - (now - this->millisecsPreviousFrame);
|
|
|
+ if (timeToWait > 0) // && timeToWait <= MILLISECS_PER_FRAME)
|
|
|
+ {
|
|
|
+ SDL_Delay(timeToWait);
|
|
|
+ }
|
|
|
+ double deltaTime = (SDL_GetTicks() - this->millisecsPreviousFrame) / 1000.0;
|
|
|
+ this->millisecsPreviousFrame = SDL_GetTicks();
|
|
|
+
|
|
|
+
|
|
|
+ this->part->velocity = vec2(100 * deltaTime, 30 * deltaTime);
|
|
|
|
|
|
- this->part->position += this->part->velocity;
|
|
|
+ this->part->position += (this->part->velocity);
|
|
|
}
|
|
|
|
|
|
void application::render()
|