/*************************************** * * FlockOfBirds04 * * Click and Drag to rotate the cage * The Birds in this example show the following behaviours: * Wander, Separation, Cohesion, Align * ***************************************/ // see http://www.red3d.com/cwr/boids/ // also check http://www.red3d.com/cwr/steer/gdc99/ // bird settings: double BIRD_MAX_VELOCITY=15; // maximum velocity double BIRD_MAX_FORCE=2; // maximum steering force double BIRD_PERCEPTION_RADIUS=250; // local perception radius double BIRD_INIT_POS_BOX_SIDE=600; // initial random x/y/z coordinate box [-side,side] boolean BIRD_SHOW_CONNECTIONS=false; // show bird's neighbours (within perception radius) double BIRD_WALL_AVOID_DISTANCE=150; // (horizontal) distance to a wall when bird starts turning double BIRD_STEER_WANDER_FAC=1.0; // strength of wander double BIRD_STEER_SEPARATION_FAC=1.0; // strength of alignment double BIRD_STEER_COHESION_FAC=1.0; // strength of cohesion double BIRD_STEER_ALIGN_FAC=1.0; // strength of alignment // universe boundaries settings: double BOUNDARIES_X_RANGE=1600; // min/max x pos double BOUNDARIES_Y_RANGE=1600; // min/max y pos double BOUNDARIES_Z_RANGE=1600; // min/max z pos color BOUNDARIES_COLOR=#52b0f9; // color of bounding box boolean BOUNDARIES_DRAW=true; // show bounding box // display variables color SPACIAL_DATA_COLOR=#88FF88; // color of spacial bounding box int CAM_MODE=1; // CAM_MODE_BIRD=0, CAM_MODE_OUTSIDE=1, CAM_MODE_CAGE=2; Bird[] bird=new Bird[80]; Bread[] bread=new Bread[100]; SpacialData spacialData=new SpacialData(); CustomCam myCamera;//=new CustomCam(BOUNDARIES_X_RANGE,BOUNDARIES_Y_RANGE,BOUNDARIES_Z_RANGE,800,600); void setup() { size(800,600,P3D); myCamera=new CustomCam(BOUNDARIES_X_RANGE,BOUNDARIES_Y_RANGE,BOUNDARIES_Z_RANGE,width,height); initBirds(); initBread(); initSpacialData(); } void draw() { background(0xc1e1f9); // set camera position if (keyPressed) { if (key=='1') {CAM_MODE=0;myCamera.reset();} if (key=='2') {CAM_MODE=1;myCamera.reset();} if (key=='3') {CAM_MODE=2;myCamera.reset();} } myCamera.updateAndSet(CAM_MODE); // update position of all Birds updateBirds(); // update SpacialData (which Bird is in which quadrant) updateSpacialData(); // draw total universe boundaries if (BOUNDARIES_DRAW) {drawBoundaries();} // draw all Birds drawBirds(); // calculate neighbouring Birds for all Birds updateBirdsInPossibleRange(); // draw connections between Birds and neighbouring Birds before moving them if (BIRD_SHOW_CONNECTIONS) {showBirdNeighbourConnections();} // draw Bread drawBread(); } // INIT FUNCTIONS: void initBirds() { for (int i=0;i