Types of Boids


Scene Creation

WrapFlocking3D is like previous Wrap classes in that it creates a 3D scene inside a JPanel, made up of a checkerboard floor, blue sky, lighting, and an OrbitBehavior node to allow the user to adjust the viewpoint.

The additions are the obstacles and the two flocks, both created in addFlockingBoids( ):

     private void addFlockingBoids(int numPreds, int numPrey, int numObs)     { // create obstacles       Obstacles obs = new Obstacles(numObs);       sceneBG.addChild( obs.getObsBG(  ) );  // add obstacles to scene           // make the predator manager       PredatorBehavior predBeh = new PredatorBehavior(numPreds, obs);       predBeh.setSchedulingBounds(bounds);       sceneBG.addChild( predBeh.getBoidsBG(  ) );  // add preds to scene           // make the prey manager       PreyBehavior preyBeh = new PreyBehavior(numPrey, obs);       preyBeh.setSchedulingBounds(bounds);       sceneBG.addChild( preyBeh.getBoidsBG(  ) );  // add prey to scene           // tell behaviors about each other       predBeh.setPreyBeh( preyBeh );       preyBeh.setPredBeh( predBeh );         } // end of addFlockingBoids(  ) 

The number of predators, prey, and obstacles are read from the command line in Flocking3D or are assigned default values. The behaviors are passed references to each other so their steering rules can consider neighboring boids of the other type. Here's a typical call to Flocking3D:

     java Flocking3D 10 200 15 

This will make addFlockingBoids( ) create 10 predators, 200 prey, and 15 obstacles.



Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net