topical media & game development

talk show tell print

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



  MyPoint [] points;
  MySolid solid;
  MyPoint origin = new MyPoint(0.,0.,0.);
  
  void setup(){
    size(500, 500, P3D);
    camera(70.0, 35.0, 120.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((40.*sin((360./nsides)*i*PI/180.)), 
                            (40.*cos((360./nsides)*i*PI/180.)),0.);
    solid = new MySolid(points, 20.);
    for(int i=0; i<solid.nfaces; i++)
      solid.faces[i].setColor(color(random(255),random(255),random(255)));
  }
  
  int xf, yf;
  void draw(){
    background(255);
    //lights(); 
    solid.rotatex((mouseX - xf) * PI/180.,origin);
    solid.rotatey((mouseY - yf) * PI/180.,origin);
    solid.draw();
    xf = mouseX;
    yf = mouseY;
  }
  


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