Skip to content

Commit

Permalink
Added NN grid init code for flocking
Browse files Browse the repository at this point in the history
  • Loading branch information
muraliavarma committed Feb 1, 2013
1 parent 13ebd53 commit e082e6e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion murali_varma_hw2/Creature.pde
Expand Up @@ -54,7 +54,7 @@ class Creature {


void applyForces() { void applyForces() {
//apply the 3 forces to the creature and update its x and y velocities //apply the 3 forces to the creature and update its x and y velocities

} }


Creature[] getNeighbors(float radius) { Creature[] getNeighbors(float radius) {
Expand Down
22 changes: 21 additions & 1 deletion murali_varma_hw2/Neighbors.pde
@@ -1,4 +1,24 @@
final float FLOCK_CENTERING_RADIUS = 0.2;

HashMap flockCenterGrid;

void initNeighborGrids() {
flockCenterGrid = new HashMap();
}

void computeNeighborGrids() { void computeNeighborGrids() {
//use active forces and compute separate neighbor grids for each force //use active forces and compute separate neighbor grids for each force

float radius = FLOCK_CENTERING_RADIUS;
flockCenterGrid.clear();
for (int i = 0; i < NUM_CREATURES; i++) {
String key = int(creatures[i].posX/radius) + "," + int(creatures[i].posY/radius);
ArrayList val = (ArrayList)flockCenterGrid.get(key);
if (val != null) {
val.add(i);
}
else {
flockCenterGrid.put(key, new ArrayList());
}
}

} }
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.
25 changes: 23 additions & 2 deletions murali_varma_hw2/build-tmp/source/murali_varma_hw2.java
Expand Up @@ -37,6 +37,7 @@ public void setup() {
background(0); background(0);
stroke(100); stroke(100);


initNeighborGrids();
initCreatures(); initCreatures();
} }


Expand Down Expand Up @@ -130,17 +131,37 @@ public void update() {


public void applyForces() { public void applyForces() {
//apply the 3 forces to the creature and update its x and y velocities //apply the 3 forces to the creature and update its x and y velocities

} }


public Creature[] getNeighbors(float radius) { public Creature[] getNeighbors(float radius) {
return null; return null;
} }
}; };


final float FLOCK_CENTERING_RADIUS = 0.2f;

HashMap flockCenterGrid;

public void initNeighborGrids() {
flockCenterGrid = new HashMap();
}

public void computeNeighborGrids() { public void computeNeighborGrids() {
//use active forces and compute separate neighbor grids for each force //use active forces and compute separate neighbor grids for each force
print(wanderingForce); float radius = FLOCK_CENTERING_RADIUS;
flockCenterGrid.clear();
for (int i = 0; i < NUM_CREATURES; i++) {
String key = PApplet.parseInt(creatures[i].posX/radius) + "," + PApplet.parseInt(creatures[i].posY/radius);
ArrayList val = (ArrayList)flockCenterGrid.get(key);
if (val != null) {
val.add(i);
}
else {
flockCenterGrid.put(key, new ArrayList());
}
}

} }
static public void main(String[] passedArgs) { static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "murali_varma_hw2" }; String[] appletArgs = new String[] { "murali_varma_hw2" };
Expand Down
1 change: 1 addition & 0 deletions murali_varma_hw2/murali_varma_hw2.pde
Expand Up @@ -22,6 +22,7 @@ void setup() {
background(0); background(0);
stroke(100); stroke(100);


initNeighborGrids();
initCreatures(); initCreatures();
} }


Expand Down

0 comments on commit e082e6e

Please sign in to comment.