diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-10-02 16:19:30 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-10-02 16:19:30 -0400 |
| commit | 26ce765feb702c6d40f89a8cf50274869cdc35b4 (patch) | |
| tree | 7da69540057e9bcfa89d462f301dc215fbc21734 /balls.cpp | |
| parent | a59cd43105f938a5acb84d30dc9aaa92f675c966 (diff) | |
| download | balls-26ce765feb702c6d40f89a8cf50274869cdc35b4.zip | |
ball collisions
Diffstat (limited to 'balls.cpp')
| -rw-r--r-- | balls.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -6,7 +6,7 @@ using namespace std; -#define VMAX_INIT 0.15 +#define VMAX_INIT 0.05 /* max initial velocity [m/s] */ #define RMIN 0.05 #define RMAX 0.10 @@ -183,9 +183,14 @@ volume(double radius) { void animate(int v) { - for (Ball& ball : balls) { - ball.p = ptAddVec(ball.p, ball.v); - collideWall(&ball, bounds); + size_t i, j; + + /* TODO: parallel */ + for (i = 0; i < balls.size(); i++) { + for (j = i+1; j < balls.size(); j++) + collideBall(&balls[i], &balls[j]); + balls[i].p = ptAddVec(balls[i].p, balls[i].v); + collideWall(&balls[i], bounds); } display(); |