Browse files

Param tweaking for attract/repel. Not that bad, but can be better

  • Loading branch information...
1 parent 7c40877 commit 3e2850f1b67f82ef4f9911efd4e6aa660f71c5c5 @muraliavarma committed Feb 6, 2013
View
6 murali_varma_hw2/Creature.pde
@@ -47,8 +47,8 @@ class Creature {
velY += forceY;
//clamp velocities
- velX = max(-0.01, min(velX, 0.01));
- velY = max(-0.01, min(velY, 0.01));
+ velX = max(MIN_VELOCITY, min(velX, MAX_VELOCITY));
+ velY = max(MIN_VELOCITY, min(velY, MAX_VELOCITY));
posX += velX;
posY += velY;
@@ -167,7 +167,7 @@ class Creature {
float y = (1.0 * mouseY)/SCREEN_HEIGHT;
int sign = mouseMode == ATTRACT_MODE ? -1 : 1;
float dist = distSqTo(x, y);
- if (dist < MOUSE_RADIUS) {
+ if (dist < MOUSE_RADIUS * MOUSE_RADIUS) {
float weight = 1/(dist + EPSILON);
forceX += sign * MOUSE_WEIGHT * (posX - x) * weight;
forceY += sign * MOUSE_WEIGHT * (posY - y) * weight;
View
BIN murali_varma_hw2/build-tmp/murali_varma_hw2$Creature.class
Binary file not shown.
View
BIN murali_varma_hw2/build-tmp/murali_varma_hw2.class
Binary file not shown.
View
19 murali_varma_hw2/build-tmp/source/murali_varma_hw2.java
@@ -27,18 +27,21 @@
final int MIN_CREATURES = 1;
final int MAX_CREATURES = 100;
-final float EPSILON = 0.01f;
+final float EPSILON = 0.0001f;
-final float FLOCK_CENTERING_RADIUS = 0.1f;
+final float FLOCK_CENTERING_RADIUS = 0.2f;
final float COLLISION_AVOIDANCE_RADIUS = 0.05f;
final float VELOCITY_MATCHING_RADIUS = 0.1f;
-final float MOUSE_RADIUS = 0.1f;
+final float MOUSE_RADIUS = 0.2f;
final float FLOCKING_CENTERING_WEIGHT = 0.0001f;
-final float COLLISION_AVOIDANCE_WEIGHT = 0.001f;
+final float COLLISION_AVOIDANCE_WEIGHT = 0.002f;
final float VELOCITY_MATCHING_WEIGHT = 0.1f;
final float WANDERING_WEIGHT = 0.0002f;
-final float MOUSE_WEIGHT = 0.00001f;
+final float MOUSE_WEIGHT = 0.00003f;
+
+final float MIN_VELOCITY = -0.005f;
+final float MAX_VELOCITY = 0.005f;
int NUM_CREATURES = 100;
@@ -151,8 +154,8 @@ public void update() {
velY += forceY;
//clamp velocities
- velX = max(-0.01f, min(velX, 0.01f));
- velY = max(-0.01f, min(velY, 0.01f));
+ velX = max(MIN_VELOCITY, min(velX, MAX_VELOCITY));
+ velY = max(MIN_VELOCITY, min(velY, MAX_VELOCITY));
posX += velX;
posY += velY;
@@ -271,7 +274,7 @@ public void applyForces() {
float y = (1.0f * mouseY)/SCREEN_HEIGHT;
int sign = mouseMode == ATTRACT_MODE ? -1 : 1;
float dist = distSqTo(x, y);
- if (dist < MOUSE_RADIUS) {
+ if (dist < MOUSE_RADIUS * MOUSE_RADIUS) {
float weight = 1/(dist + EPSILON);
forceX += sign * MOUSE_WEIGHT * (posX - x) * weight;
forceY += sign * MOUSE_WEIGHT * (posY - y) * weight;
View
13 murali_varma_hw2/murali_varma_hw2.pde
@@ -12,18 +12,21 @@ final int REPEL_MODE = 1;
final int MIN_CREATURES = 1;
final int MAX_CREATURES = 100;
-final float EPSILON = 0.01;
+final float EPSILON = 0.0001;
-final float FLOCK_CENTERING_RADIUS = 0.1;
+final float FLOCK_CENTERING_RADIUS = 0.2;
final float COLLISION_AVOIDANCE_RADIUS = 0.05;
final float VELOCITY_MATCHING_RADIUS = 0.1;
-final float MOUSE_RADIUS = 0.1;
+final float MOUSE_RADIUS = 0.2;
final float FLOCKING_CENTERING_WEIGHT = 0.0001;
-final float COLLISION_AVOIDANCE_WEIGHT = 0.001;
+final float COLLISION_AVOIDANCE_WEIGHT = 0.002;
final float VELOCITY_MATCHING_WEIGHT = 0.1;
final float WANDERING_WEIGHT = 0.0002;
-final float MOUSE_WEIGHT = 0.00001;
+final float MOUSE_WEIGHT = 0.00003;
+
+final float MIN_VELOCITY = -0.005;
+final float MAX_VELOCITY = 0.005;
int NUM_CREATURES = 100;

0 comments on commit 3e2850f

Please sign in to comment.