Skip to content

Commit

Permalink
Param tweaking for attract/repel. Not that bad, but can be better
Browse files Browse the repository at this point in the history
  • Loading branch information
muraliavarma committed Feb 7, 2013
1 parent 7c40877 commit 3e2850f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
6 changes: 3 additions & 3 deletions murali_varma_hw2/Creature.pde
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Binary file modified murali_varma_hw2/build-tmp/murali_varma_hw2$Creature.class
Binary file not shown.
Binary file modified murali_varma_hw2/build-tmp/murali_varma_hw2.class
Binary file not shown.
19 changes: 11 additions & 8 deletions murali_varma_hw2/build-tmp/source/murali_varma_hw2.java
Expand Up @@ -27,18 +27,21 @@ public class murali_varma_hw2 extends PApplet {
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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions murali_varma_hw2/murali_varma_hw2.pde
Expand Up @@ -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;

Expand Down

0 comments on commit 3e2850f

Please sign in to comment.