diff options
| author | realtradam <[email protected]> | 2022-11-05 02:04:30 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2022-11-05 02:04:30 -0400 |
| commit | 3c8e6238ebed92691dac9393893ca6214ab060ab (patch) | |
| tree | a6bcb9ddca6608a39b70e667231e73bb2ce19472 /src/physics.cpp | |
| parent | e35ff8879409dae845371be867ca76a1cf78cf7f (diff) | |
| download | orbital_game-3c8e6238ebed92691dac9393893ca6214ab060ab.tar.gz orbital_game-3c8e6238ebed92691dac9393893ca6214ab060ab.zip | |
implemented rough physics system
Diffstat (limited to 'src/physics.cpp')
| -rw-r--r-- | src/physics.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/physics.cpp b/src/physics.cpp index 23b21e4..d8045a5 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -1,7 +1,30 @@ -#include "physics.hpp" #include <math.h> +#include "physics.hpp" +#include "raylib.h" +#include "raymath.h" namespace Physics { - //const float gravitational_constant = 6.67e-11; + // using 1 as the const + //const float gravitational_constant = 6.67;//e-11; + //grav = grav_const × (r_mass / distance^2) + //force = s_mass * grav + //force = s_mass * (grav_const * (r_mass / distance^2)) + + Body::Body(Vector2 position, Vector2 velocity, float mass):position(position), velocity(velocity), mass(mass) { + } + + Body ship = Body((Vector2){200,400}, (Vector2){0,0.5}, 1); + Body rock = Body((Vector2){400,400}, (Vector2){0,0}, 50); + + //0.01667 + void step(float deltaTime) { + // calculate velocity change + //pow((rock.position.x - ship.position.x),2) + pow((rock.position.y - ship.position.y),2); + float distance = Vector2DistanceSqr(ship.position, rock.position); + Vector2 force = Vector2Normalize(Vector2Subtract(rock.position, ship.position)); + ship.velocity = Vector2Add(ship.velocity, Vector2Scale(force, ship.mass * (rock.mass / (distance/*this is pre squared*/)) * deltaTime)); + // calculate position change + ship.position = Vector2Add(ship.position, Vector2Scale(ship.velocity, deltaTime)); + } } |
