topical media & game development

talk show tell print

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



  class MyFace{
    MyPoint[] points = new MyPoint[0]; //array of points
    MyFace(){
    }
    MyFace(MyPoint[] inp){ //construct a face out of points
      points = new MyPoint[inp.length];
      for(int i=0; i<points.length; i++)
        points[i] = new MyPoint(inp[i].x, inp[i].y, inp[i].z);
    }
    //add a point to a face one at a time
    void addPoint(float addX, float addY, float addZ){
      points = (MyPoint[])append(points, new MyPoint(addX,addY,addZ));
    }
    void plot(){
      if(points.length==4) //if we have four point faces
        beginShape(QUADS); //use the QUADS setup
      else
        beginShape(POLYGON); //else POLYGONS
      for(int i=0; i<points.length; i++)
        vertex(points[i].x,points[i].y,points[i].z);
      endShape(CLOSE); //close the face
    }
  }
  
  


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