topical media & game development

talk show tell print

graphic-processing-algorithm-Ch08-p196-p196.pde / pde



  MyObject [] b; //define an array of objects
  int zoom; //zoom in/out factor
  void setup(){
    size(400,400,P3D);
    b = new MyObject[100]; //populate the array
    for(int i=0; i<b.length; i++)
      b[i] = new MyObject(); //construct objects
  }
  void draw(){
    background(200); //redraw the background
    camera(xd,yd,getWheel(), b[55].x,b[55].y,b[55].z, 0,0,1);
    int k=0; //object counter
    for(int x=0; x<10; x++) //10x10 grid
      for(int y=0; y<10; y++){
        b[k].draw3(); //draw the object
        b[k].move3(x*60,y*60,0); //move on a grid configuration
        k++; //increment the counter
      }
  }
  float xd,yd; // difference between current and previous mouse
  void mouseDragged(){
    xd += mouseX-pmouseX; //get the difference
    yd += mouseY-pmouseY;
    camera(xd,yd,100+(zoom*5), b[55].x,b[55].y,b[55].z, 0,0,1);
  }
  void mousePressed(){
    for(int i=0; i<b.length; i++)
      b[i].pick(mouseX,mouseY); //pick an object
  }
  int getWheel(){
    addMouseWheelListener(new MouseWheelListener() {
      public void mouseWheelMoved(MouseWheelEvent e){
        zoom+=e.getWheelRotation();
      }
    }
    );
    return(zoom);
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.