/**
 * 
 * Version PixelView: the field of perception is scanned by the pixel in order to identify any obstacles
 *
 * Also new: a second drawing layer is introduced in order to maintain pixel-drawings
 *
 * Boid flocking implementation featuring: <br>
 * - obstacle avoidance <br>
 * - conic perception field <br>
 * - flight perturbation <br>
 * - field of perception visualization (mousecklick or 'n' for neighborhood) <br>
 * - interaction network visualization ('w' for web) <br>
 * - press 'space' to pause the simulation <br>

 * An implementation of Craig Reynold's Boids program to simulate
 * the flocking behavior of birds. Each boid steers itself based on 
 * rules of avoidance, alignment, and coherence.
 */
 
 
import processing.opengl.*;
import processing.dxf.*;
import peasy.*;
import controlP5.*;



PeasyCam cam;
ControlP5 cp5;

//global
boolean neighborhoodview;

//private
int mX,mY,camX,camY;

//world size
Vector3D worldSize = new Vector3D(gridSize*11,gridSize*11,gridSize*11);

Matrix matrix;
Random rand = new Random();

void setup() 
{
  frameRate(framerate);
  smooth(antialiasing);
  ReadData();
  
  fullScreen(P3D);
  colorMode(RGB,255,255,255,100);
  
  cam = new PeasyCam(this, worldSize.y*1.5);
  cam.lookAt(worldSize.x/2,worldSize.y/2,worldSize.z/2);
  //perspective(120, 1.5, 0, 1000);
  cam.setMinimumDistance(0);
  cam.setMaximumDistance(worldSize.y*10);

  //set up the GUI
  cp5 = new ControlP5(this);
  setGui();

  //set up the Matrix
  noStroke();
  matrix = new Matrix();
  matrix.setupMatrix();
}



void draw() 
{
  background(255);
    
  matrix.run();
  matrix.render();
  
  //GUI
  if(showGui)
  {
    gui();
  }
}

public void pause()
{
  pause = !pause;
}
