diff options
| author | arngo <[email protected]> | 2022-11-05 21:57:15 -0400 |
|---|---|---|
| committer | arngo <[email protected]> | 2022-11-05 21:57:15 -0400 |
| commit | a9649b97ddfb0b39f8b3c27b14a7d855b1e824fa (patch) | |
| tree | 272b950a831cdd54bcfc1d0221463bfb8d1ddac8 | |
| parent | ceb76492b07dbeda6949f35008999d0f400e49fd (diff) | |
| download | orbital_game-a9649b97ddfb0b39f8b3c27b14a7d855b1e824fa.tar.gz orbital_game-a9649b97ddfb0b39f8b3c27b14a7d855b1e824fa.zip | |
add times parameter to step function
| -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) { |
