mias
YaBB Newbies
Offline
Posts: 9
flocking excample to XML
Nov 16th , 2007, 11:41am
i'd like to work with the possisions of the boids in the flocking excample in an XML file! is this possible??? here's the file again: Flock flock; void setup() { size(500,500); colorMode(RGB,255,255,255,100); flock = new Flock(); // Add an initial set of boids into the system for (int i = 0; i < 50; i++) { flock.addBoid(new Boid(new Vector3D(width/2,height/2),2.0f,0.05f)); } smooth(); } void draw() { background(100); flock.run(); } // Add a new boid into the System void mousePressed() { flock.addBoid(new Boid(new Vector3D(mouseX,mouseY),2.0f,0.05f)); } class Flock { ArrayList boids; // An arraylist for all the boids Flock() { boids = new ArrayList(); // Initialize the arraylist } void run() { for (int i = 0; i < boids.size(); i++) { Boid b = (Boid) boids.get(i); b.run(boids); // Passing the entire list of boids to each boid individually } } void addBoid(Boid b) { boids.add(b); } } class Boid { Vector3D loc; Vector3D vel; Vector3D acc; float r; float maxforce; // Maximum steering force float maxspeed; // Maximum speed Boid(Vector3D l, float ms, float mf) { acc = new Vector3D(0,0); vel = new Vector3D(random(-1,1),random(-1,1)); loc = l.copy(); r = 2.0f; maxspeed = ms; maxforce = mf; } void run(ArrayList boids) { flock(boids); update(); borders(); render(); } // We accumulate a new acceleration each time based on three rules void flock(ArrayList boids) { Vector3D sep = separate(boids); // Separation Vector3D ali = align(boids); // Alignment Vector3D coh = cohesion(boids); // Cohesion // Arbitrarily weight these forces sep.mult(2.0f); ali.mult(1.0f); coh.mult(1.0f); // Add the force vectors to acceleration acc.add(sep); acc.add(ali); acc.add(coh); } // Method to update location void update() { // Update velocity vel.add(acc); // Limit speed vel.limit(maxspeed); loc.add(vel); // Reset accelertion to 0 each cycle acc.setXYZ(0,0,0); } void seek(Vector3D target) { acc.add(steer(target,false)); } void arrive(Vector3D target) { acc.add(steer(target,true)); } ... ... ... ... ... how do i write the possision and ID of a boid in an XML-file??? thanks everybody! mias