diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-10-02 17:42:05 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-10-02 17:42:05 -0400 |
| commit | 427d71beee6b17e09de10ca5782e5c6a80526f44 (patch) | |
| tree | 4d58fa859d0a86cf880728fa0262c7a5ee13e8e6 | |
| parent | b45a78b60136c3887430d309d2f78ed972c1fbc8 (diff) | |
| download | balls-427d71beee6b17e09de10ca5782e5c6a80526f44.zip | |
gravity
| -rw-r--r-- | balls.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -8,12 +8,15 @@ using namespace std; #define VMAX_INIT 0.05 - /* max initial velocity [m/s] */ + /* max initial velocity [m/frame] */ #define RMIN 0.05 #define RMAX 0.10 /* min/max radius [m] */ #define DENSITY 1500.0 /* density of ball [kg/m^3] */ +#define G (9.81/FPS/G_FACTOR) + /* acceleration of gravity [m/(s*frame)] */ +#define G_FACTOR 25.0 enum { WIDTH = 800, @@ -191,6 +194,7 @@ animate(int v) { for (i = 0; i < balls.size(); i++) { for (j = i+1; j < balls.size(); j++) collideBall(&balls[i], &balls[j]); + balls[i].v.y -= G; balls[i].p = ptAddVec(balls[i].p, balls[i].v); collideWall(&balls[i], bounds); } |