topical media & game development

talk show tell print

graphic-processing-algorithm-Ch09-p240-p240.pde / pde



  MyPoint [] points;
  MyGroup group;
  MyPoint origin = new MyPoint(0.,0.,0.);
  void setup(){
    size(500, 500, P3D);
    camera(70.0, 35.0, 100.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    int nsides = 6;
    points = new MyPoint[nsides];
    for(int i=0; i<nsides; i++)
      points[i] = new MyPoint((10.*sin((360./nsides)*i*PI/180.)), 
      (10.*cos((360./nsides)*i*PI/180.)),0.);
    group = new MyGroup();
    int k=0;
    int nsides2 = 4;//nsides/2;
    for(int z=-nsides2; z<nsides2; z++)
      for(int y=-nsides2; y<nsides2; y++)
        for(int x=-nsides2; x<nsides2; x++){
          group.addSolids(points, 10.);
          group.solids[k].setColor(color(255,255,255));
          group.solids[k].scale(.5,.5,.5, origin);
          group.solids[k].move(x*20.,y*20.,z*20.);
          k++;
        }
  }
  
  int xf, yf;
  void draw(){
    background(255);
    group.draw();
  }
  
  void mouseDragged(){
    group.rotatex((mouseX - xf) * PI/180.,origin);
    group.rotatey((mouseY - yf) * PI/180.,origin);
    xf = mouseX;
    yf = mouseY;
  }
  void mousePressed(){
    xf = mouseX;
    yf = mouseY;
  }
  void mouseClicked(){
    for(int i=0; i<group.nsolids; i++)
       if(group.solids[i].pick(mouseX,mouseY)){
           group.solids[i].setSelected(true);  
      //for(int ii=0; ii<group.solids[i].nfaces; ii++)
        //if(group.solids[i].faces[ii].pick(mouseX,mouseY))
             return;
       }
       else
          group.setSelected(false);
    
  }
  


(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.