summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-10-02 17:42:05 -0400
committerSam Anthony <sam@samanthony.xyz>2024-10-02 17:42:05 -0400
commit427d71beee6b17e09de10ca5782e5c6a80526f44 (patch)
tree4d58fa859d0a86cf880728fa0262c7a5ee13e8e6
parentb45a78b60136c3887430d309d2f78ed972c1fbc8 (diff)
downloadballs-427d71beee6b17e09de10ca5782e5c6a80526f44.zip
gravity
-rw-r--r--balls.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/balls.cpp b/balls.cpp
index 37383ed..48c7a5a 100644
--- a/balls.cpp
+++ b/balls.cpp
@@ -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);
}