// <pre>

package actor;

import render.Geometry;
import render.Material;

public class PollyGeometry extends ActorGeometry
{
  // HOW THE VERTICES OF THE POLYHEDRON ARE CONNECTED BY FACES
  static int faces[][] = { { 0, 1, 2 }, {
      3, 4, 5 }, {
      6, 7, 8, 9 }, {
      10, 11, 12, 13 }, {
      14, 15, 16, 17 }
  };
  
  static Point3D[] pollyShape =
    {
      new Point3D(-.5, 1, -.5),
      new Point3D(-.5, 0, 0),
      new Point3D(-.5, 1, .5),
      new Point3D(.5, 1, -.5),
      new Point3D(.5, 0, 0),
      new Point3D(.5, 1, .5)};
    
  static int map[] = { 0, 1, 2, 5, 4, 3, 1, 0, 3, 4, 2, 1, 4, 5, 0, 2, 5, 3 };
  static Material red = (new Material()).setColor(1, 0, 0, 1, 1, 1, 10, .2, 0, 0);

  // CONSTRUCTOR ==============================================
  public PollyGeometry()
  {
    setMaterial(red);
    Geometry body = add();
    body.faces = faces;
    body.vertices = new double[18][6];
    
    setBaseShape(pollyShape);
    setAnimationVertexMap(map);    
    updateVertices(pollyShape);

    Geometry shadow = add();
    shadow.setMaterial(
      (new Material()).setDiffuse(0, 0, 0).setTransparency(.75));
    shadow.faces = body.faces;
    shadow.vertices = body.vertices;
    shadow.matrix.translate(0, .03, 0);
    shadow.matrix.scale(1, .02, 1);

  }

  // ALLOW APPLICATION TO SET VARIOUS PARAMETERS

  public PollyGeometry setColor(double r, double g, double b)
  {
    geometry.child[0].setMaterial(
      (new Material()).setColor(r, g, b, 1, 1, 1, 10, .2 * r, .2 * g, .2 * b));
    return this;
  }
  
  public int getVertexCount() {
    return 6;
  }
  
  public void updateVertices(Point3D[] vertexList)
  {
    Geometry body = geometry.child[0];
    int animationIndex;

    for (int v = 0; v < body.vertices.length; v++)
    {
      animationIndex = mapAnimationVertex(v);
      body.vertices[v][0] = vertexList[animationIndex].x;
      body.vertices[v][1] = vertexList[animationIndex].y;
      body.vertices[v][2] = vertexList[animationIndex].z;
    }
    body.computePolyhedronNormals();
  }
 
}