diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | 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) { |
