Skip to content

Commit

Permalink
Fixed behavior that caused grid-like pattern to emerge due to
Browse files Browse the repository at this point in the history
centering-attraction being added after bodies had already been repelled from
each other
  • Loading branch information
bikegriffith committed Feb 11, 2010
1 parent 3a87c09 commit 766db18
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/PhysicsEngineOrderly.java
Expand Up @@ -52,6 +52,16 @@ public void setup (CodeSwarmConfig p)
public void onRelax(code_swarm.PersonNode pNode) {
Vector2f delta = new Vector2f();

// A gentle force to attract pNodes to the center
// NOTE: this should be done prior to attraction/repulsion forces, otherwise
// tends to generate a grid-like pattern
Vector2f midpoint = new Vector2f(code_swarm.width / 2, code_swarm.height / 2);
delta = new Vector2f();
delta.sub(midpoint, pNode.mPosition);

delta.scale(1 / delta.length() * 0.003f);
pNode.mPosition.add(delta);

// All person nodes attract each other, but only to a certain point, then they repel with gentle force
for (code_swarm.PersonNode n : code_swarm.getLivingPeople()) {
if (pNode != n) {
Expand All @@ -76,15 +86,6 @@ public void onRelax(code_swarm.PersonNode pNode) {
}
}


// A gentle force to attract pNodes to the center
Vector2f midpoint = new Vector2f(code_swarm.width / 2, code_swarm.height / 2);
delta = new Vector2f();
delta.sub(midpoint, pNode.mPosition);

delta.scale(1 / delta.length() * 0.003f);
pNode.mPosition.add(delta);

// place the edited files around the person
Iterator<code_swarm.FileNode> editedFiles = pNode.editing.iterator();
int index = 0;
Expand Down

0 comments on commit 766db18

Please sign in to comment.