//
import java.awt.*;

// A VERY SIMPLE 3D RENDERER BUILT IN JAVA 1.0 - KEN PERLIN

public class Shape
{

// SHAPE DATA FOR A CUBE

   private static int[][] cubeFace = {
      {4,5,7,6}, {5,1,3,7}, {6,7,3,2}, {0,2,3,1}, {4,6,2,0}, {0,1,5,4}
   };

   private static double[][] cubeVertices = {
      {-1,-1,-1}, { 1,-1,-1}, {-1, 1,-1}, { 1, 1,-1},
      {-1,-1, 1}, { 1,-1, 1}, {-1, 1, 1}, { 1, 1, 1},
   };

// SHAPE DATA FOR A PYRAMID

   private static int[][] pyramidFace = {
   };

   private static double[][] pyramidVertices = {
   };

   public int[][] face;
   public double[][] vertices;

// CONSTRUCTOR

   public Shape() {
      Matrix.identity(matrix);
      useFace(cubeFace);
      useVertices(cubeVertices);
   }

// ALTERNATE SHAPES

   public void pyramid() {
      useFace(pyramidFace);
      useVertices(pyramidVertices);
   }

// PUBLIC ACCESS FUNCTIONS

   public void setColor(double[] src) {
      Vec.copy(src, color);
   }

   public void getColor(double[] dst) {
      Vec.copy(color, dst);
   }

   public void setTranslation(double[] src) {
      Vec.copy(src, translation);
      mustRecalc = true;
   }

   public void setRotation(double[] src) {
      Vec.copy(src, rotation);
      mustRecalc = true;
   }

   public void setScale(double[] src) {
      Vec.copy(src, scale);
      mustRecalc = true;
   }

   public void getTranslation(double[] dst) {
      Vec.copy(translation, dst);
   }

   public void getRotation(double[] dst) {
      Vec.copy(rotation, dst);
   }

   public void getScale(double[] dst) {
      Vec.copy(scale, dst);
   }

   public void getMatrix(double[][] m) {
      if (mustRecalc) {
	 Matrix.identity(matrix);
	 Matrix.translate(matrix, translation[0],translation[1],translation[2]);
	 Matrix.rotateX(matrix, rotation[0]);
	 Matrix.rotateY(matrix, rotation[1]);
	 Matrix.rotateZ(matrix, rotation[2]);
	 Matrix.scale(matrix, scale[0],scale[1],scale[2]);
	 mustRecalc = false;
      }
      Matrix.copy(matrix, m);
   }

// INTERNALLY STORED COLOR

   private double[] color = { 1,1,1 };

// TRANSLATION X Y Z, ROTATION X Y Z, SCALE X Y Z

   private double[] translation = { 0,0,0 };
   private double[] rotation    = { 0,0,0 };
   private double[] scale       = { 1,1,1 };

// INTERNALLY CALCULATED MATRIX

   private double[][] matrix = new double[4][4];

// NEED TO RECALCULATE MATRIX?

   private boolean mustRecalc = true;

   private void useFace(int[][] f) {
      face = new int[f.length][];
      for (int i = 0 ; i < f.length ; i++) {
	 face[i] = new int[f[i].length];
         for (int j = 0 ; j < f[i].length ; j++)
	    face[i][j] = f[i][j];
      }
   }
   private void useVertices(double[][] v) {
      vertices = new double[v.length][];
      for (int i = 0 ; i < v.length ; i++) {
	 vertices[i] = new double[v[i].length];
         for (int j = 0 ; j < v[i].length ; j++)
	    vertices[i][j] = v[i][j];
      }
   }
}