Commit a259c851 authored by Ant01n3's avatar Ant01n3

Ok.

parent d56143b2
...@@ -92,27 +92,37 @@ public class Boid extends AdjacencyListNode { ...@@ -92,27 +92,37 @@ public class Boid extends AdjacencyListNode {
} }
protected void checkNeighborhood(BoidParticle... particles) { protected void checkNeighborhood(BoidParticle... particles) {
System.err.printf("Boid %s :%n", id);
if (particles != null) { if (particles != null) {
Iterator<Boid> it = getNeighborNodeIterator(); Iterator<Boid> it = getNeighborNodeIterator();
LinkedList<Boid> toRemove = null; LinkedList<Boid> toRemove = null;
System.err.printf("Sees [ ");
for(BoidParticle p : particles) {
System.err.printf("%s ", p.getBoid().id);
}
System.err.printf("]%nHas Neighbors [ ");
while (it.hasNext()) { while (it.hasNext()) {
boolean found = false; boolean found = false;
Boid b = it.next(); Boid b = it.next();
for (BoidParticle p : particles) for (BoidParticle p : particles) {
if (p.getId().equals(b.getParticle().getId())) { if (p.getId().equals(b.getParticle().getId())) {
found = true; found = true;
break; break;
} }
}
System.err.printf("%s(%b)", b.id, found);
if (!found && !forces.isVisible(b.particle, this.getPosition())) { if (!found && !forces.isVisible(b.particle, this.getPosition())) {
if (toRemove == null) if (toRemove == null)
toRemove = new LinkedList<Boid>(); toRemove = new LinkedList<Boid>();
System.err.printf("(del)");
toRemove.add(b); toRemove.add(b);
} }
} }
System.err.printf("%n");
if (toRemove != null) { if (toRemove != null) {
for (Boid b : toRemove) for (Boid b : toRemove)
...@@ -121,13 +131,16 @@ public class Boid extends AdjacencyListNode { ...@@ -121,13 +131,16 @@ public class Boid extends AdjacencyListNode {
toRemove.clear(); toRemove.clear();
toRemove = null; toRemove = null;
} }
System.err.printf("adds link to [ ");
for (BoidParticle p : particles) { for (BoidParticle p : particles) {
if (getEdgeBetween(p.getBoid().getId()) == null) if (getEdgeBetween(p.getBoid().getId()) == null) {
getGraph().addEdge(getEdgeId(this, p.getBoid()), getId(), getGraph().addEdge(getEdgeId(this, p.getBoid()), getId(),
p.getBoid().getId()); p.getBoid().getId());
System.err.printf("%s ", p.getBoid().id);
}
} }
} }
System.err.printf("]%n");
} }
public static final String getEdgeId(Boid b1, Boid b2) { public static final String getEdgeId(Boid b1, Boid b2) {
......
...@@ -191,7 +191,7 @@ public class Context extends AdjacencyListGraph { ...@@ -191,7 +191,7 @@ public class Context extends AdjacencyListGraph {
boidSpecies = new HashMap<String, BoidSpecies>(); boidSpecies = new HashMap<String, BoidSpecies>();
//boidSpecies.put("default", new BoidSpecies(this, "default")); //boidSpecies.put("default", new BoidSpecies(this, "default"));
getOrCreateSpecies("default"); getOrCreateSpecies("default");
space = new OctreeCellSpace(new Anchor(-2, -2, -2), new Anchor(2, 2, 2)); space = new OctreeCellSpace(new Anchor(-area, -area, -area), new Anchor(area, area, area));
pbox = new ParticleBox(maxParticlesPerCell, space, new BoidCellData()); pbox = new ParticleBox(maxParticlesPerCell, space, new BoidCellData());
} }
......
...@@ -8,6 +8,7 @@ import java.awt.event.ActionListener; ...@@ -8,6 +8,7 @@ import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.Timer; import javax.swing.Timer;
import org.graphstream.boids.BoidSpecies;
import org.graphstream.boids.Context; import org.graphstream.boids.Context;
import org.graphstream.ui.swingViewer.Viewer; import org.graphstream.ui.swingViewer.Viewer;
import org.graphstream.ui.swingViewer.util.Camera; import org.graphstream.ui.swingViewer.util.Camera;
...@@ -83,7 +84,9 @@ public class GUI extends JFrame implements ActionListener ...@@ -83,7 +84,9 @@ public class GUI extends JFrame implements ActionListener
public static void main(String args[]) { public static void main(String args[]) {
Context ctx = new Context(); Context ctx = new Context();
GUI gui = new GUI(ctx); GUI gui = new GUI(ctx);
BoidSpecies species = ctx.getDefaultSpecies();
species.angleOfView = 0;
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
ctx.addNode(String.format("boid%03d", i)); ctx.addNode(String.format("boid%03d", i));
......
...@@ -57,7 +57,7 @@ public class ParticleViewer extends JPanel implements ParticleBoxListener, ...@@ -57,7 +57,7 @@ public class ParticleViewer extends JPanel implements ParticleBoxListener,
protected float near = 1f; protected float near = 1f;
protected float radius = 1.03f, theta, phi; protected float radius = 1.3f, theta, phi;
protected Point3 camera; protected Point3 camera;
...@@ -67,7 +67,7 @@ public class ParticleViewer extends JPanel implements ParticleBoxListener, ...@@ -67,7 +67,7 @@ public class ParticleViewer extends JPanel implements ParticleBoxListener,
protected Cube env; protected Cube env;
protected Color background = new Color(0, 0, 0); protected Color background = new Color(255, 255, 255);
// Constructors // Constructors
...@@ -201,7 +201,7 @@ public class ParticleViewer extends JPanel implements ParticleBoxListener, ...@@ -201,7 +201,7 @@ public class ParticleViewer extends JPanel implements ParticleBoxListener,
public void display(Buffer buffer) { public void display(Buffer buffer) {
setView(); setView();
// displayEnv(); displayEnv();
displayParticles(); displayParticles();
} }
......
...@@ -479,6 +479,7 @@ public class SwingBuffer ...@@ -479,6 +479,7 @@ public class SwingBuffer
public void display() public void display()
{ {
canvas.display(); canvas.display();
canvas.swapBuffers();
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment