From a9649b97ddfb0b39f8b3c27b14a7d855b1e824fa Mon Sep 17 00:00:00 2001 From: arngo <27396817+arngo@users.noreply.github.com> Date: Sat, 5 Nov 2022 21:57:15 -0400 Subject: add times parameter to step function --- src/main.cpp | 4 +--- src/physics.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 50ccd47..830b229 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,9 +33,7 @@ int main(void) // Draw //---------------------------------------------------------------------------------- - for (int i = 0; i < 50000; i++) { - Physics::step(0.001); - } + Physics::step(0.001,50000); std::cout << std::to_string(Vector2Distance(Physics::ship.position, Physics::rock.position)) << std::endl; BeginDrawing(); diff --git a/src/physics.cpp b/src/physics.cpp index df45085..b8d4e29 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -17,11 +17,13 @@ namespace Physics { Body rock = Body((Vector2){400,400}, (Vector2){0,0}, 50); //0.01667 - void step(float deltaTime) { - // calculate position change - Vector2 grav_force = get_grav_force(ship, rock); - ship.velocity = Vector2Add(ship.velocity, Vector2Scale(grav_force, deltaTime)); - ship.position = Vector2Add(ship.position, Vector2Scale(ship.velocity, deltaTime)); + void step(float deltaTime, int times) { + for (int i = 0; i < times; i++) { + // calculate position change + Vector2 grav_force = get_grav_force(ship, rock); + ship.velocity = Vector2Add(ship.velocity, Vector2Scale(grav_force, deltaTime)); + ship.position = Vector2Add(ship.position, Vector2Scale(ship.velocity, deltaTime)); + } } Vector2 get_grav_force(Body body1, Body body2) { -- cgit v1.2.3