summaryrefslogtreecommitdiffstats
path: root/balls.cpp
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-10-02 16:19:30 -0400
committerSam Anthony <sam@samanthony.xyz>2024-10-02 16:19:30 -0400
commit26ce765feb702c6d40f89a8cf50274869cdc35b4 (patch)
tree7da69540057e9bcfa89d462f301dc215fbc21734 /balls.cpp
parenta59cd43105f938a5acb84d30dc9aaa92f675c966 (diff)
downloadballs-26ce765feb702c6d40f89a8cf50274869cdc35b4.zip
ball collisions
Diffstat (limited to 'balls.cpp')
-rw-r--r--balls.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/balls.cpp b/balls.cpp
index e7a5a28..a939053 100644
--- a/balls.cpp
+++ b/balls.cpp
@@ -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();