Shape.java

java · 81 lines · part of White Outline (Cartoon Shading) · raw



public class Shape
{
  //---- Data

  Scene scene = null;
  public Transform trans = null;

  int numPoints = 0;

  double[] px, py, pz;

  Vector shapes;

  //---- Main code

  public Shape(Scene sc)
  {
    scene = sc;
    shapes = new Vector();

    trans = new Transform();
    
    px = new double[64];
    py = new double[64];
    pz = new double[64];
  }

  //---- addPoint

  public void addPoint(double x, double y, double z)
  {
    px[numPoints] = x;
    py[numPoints] = y;
    pz[numPoints] = z;

    numPoints ++;
  }

  //---- addShape

  public void addShape(Shape s)
  {
    shapes.addElement(s);
  }

  //---- setTransform
  
  public void setTransform(Transform newtrans)
  {
    this.trans = null;
    this.trans = new Transform(newtrans);
  }

  //---- render

  public void render()
  {
    int i;

    //  Set up transformation

    scene.transform(trans);
        
    //  Render sub-shapes
    
    for(i=0; i<shapes.size(); i++) ((Shape)shapes.elementAt(i)).render();
    
    //  Render this shape
    
    for(i=0; i<numPoints; i++) scene.plotPoint(px[i], py[i], pz[i]);
    
    //  Revert transformation
    
    scene.untransform();
  }
  
}