topical media & game development

talk show tell print

graphic-processing-algorithm-Ch09-p214-MyFace.pde / pde



  class MyFace {
    int npoints = 0; //the number of points
    MyPoint [] points; //array of points
  
    MyFace (){
      points = new MyPoint[0];
    }
      MyFace(MyPoint[] inPoints){
      points = new MyPoint[inPoints.length];
      npoints = inPoints.length;
      for(int i=0; i<inPoints.length; i++)
        points[i] = new
          MyPoint(inPoints[i].x, inPoints[i].y, inPoints[i].z);
    }
    void addPoint(float addX, float addY, float addZ){
      npoints++;
      points=(MyPoint[])append(points, new MyPoint(addX,addY,addZ));
    }
    void move(float xoff, float yoff, float zoff){
      for(int i=0; i<npoints; i++)
        points[i].move(xoff, yoff, zoff);
    }
    void rotatex (float angle, MyPoint ref) {
      for(int i=0; i<npoints; i++)
        points[i].rotatex(angle, ref);
    }
    void rotatey (float angle, MyPoint ref) {
      for(int i=0; i<npoints; i++)
        points[i].rotatey(angle, ref);
    }
    void rotatez (float angle, MyPoint ref) {
      for(int i=0; i<npoints; i++)
        points[i].rotatez(angle, ref);
    }
    void scale(float xs, float ys, float zs, MyPoint ref){
      for(int i=0; i<npoints; i++)
        points[i].scale(xs, ys, zs, ref);
    }
    void draw(){
      beginShape(QUADS);
      for(int i = 0; i < npoints; i++){
        vertex(points[i].x,points[i].y, points[i].z);
      }
      endShape(CLOSE);
    }
  }
  
  


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