import java.awt.Color;
import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.NormalGenerator;
import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.*;
import javax.vecmath.*;
public class RubiksCube
{
int place = 0;
public IndexedQuadArray cubies = new IndexedQuadArray(24,GeometryArray.COORDINATES | GeometryArray.COLOR_3|IndexedQuadArray.NORMALS,24); // Initializes an array of size 24; 6 sides with vertices at the Top right, Top left, Bottom Right, and Bottom Left
public PointArray cubiesP = new PointArray(216, PointArray.COORDINATES);// Initializes an array with all points. This includes every sticker (9*6) * every corner of the sticker (4) = 216
public Point3f[][][] getPoints(float width, float distance)
{
Point3f[][][] points = new Point3f[6][6][6]; // This creates the grid. There are 6 sides, a 6x6 grid is on all sides.
int place = 0;
for(int right = 0;right<6;right++)
for(int up = 0;up<6;up++)
for(int front = 0;front<6;front++)
points[right][up][front]=new Point3f(getNumb(right, width, distance),getNumb(up, width, distance) ,getNumb(front, width, distance)); // Puts the point at the correct location
return points; // returns the array
}
public IndexedQuadArray getCubies() // accessor... No reason really to have it here, but we need it for the grade
{
return cubies;
}
public float getNumb(int numb, float width, float distance) // This returns the correct distance.
{
switch(numb)
{ case(0):
return (float)(-1.5 * width -distance); //Far edge
case(1):
return (float)(-.5 * width - distance); //far edge + width of the first cube
case(2):
return (float)(-.5 * width); // far edge + width of the first cube + distance between first cube and second
case(3):
return (float)(.5 * width); // the rest is a mirror of it.
case(4):
return (float)(.5 * width + distance);
default:
return (float)(1.5 * width + distance);
}
}
public void init(double width2, double distance2, Color[] colors)
{
int place= 0;
float width = (float)width2; // Initializes them as floats
float distance = (float)distance2;
Point3f[][][] points = getPoints(width,distance);
int a = 0;
Color3b white = new Color3b((byte)255,(byte)255,(byte)255); // Initializes colors. I have not checked the colors.
Color3b red = new Color3b((byte)255,(byte)5,(byte)10);
Color3b orange = new Color3b((byte)170,(byte)30,(byte)30);
Color3b green = new Color3b((byte)5,(byte)255,(byte)10);
Color3b yellow = new Color3b((byte)20,(byte)70,(byte)70);
Color3b blue = new Color3b((byte)1,(byte)10,(byte)255);
Point3f[] paint = {points[0][0][0], points[0][0][5], points[0][5][0], points[0][5][5], points[5][0][0], points[5][0][5], points[5][5][0], points[5][5][5]};
cubies.setColor(a, red);// These add the points in along with their color. I have checked the coordinate system and it works.
cubies.setCoordinate(a++,paint[0] );// 4 5
cubies.setColor(a, red);
cubies.setCoordinate(a++,paint[1] );// 0 1
cubies.setColor(a, red);
cubies.setCoordinate(a++,paint[3] ); //6 7
cubies.setColor(a, red);
cubies.setCoordinate(a++,paint[2] ); // 2 3
cubies.setColor(a, white);
cubies.setCoordinate(a++,paint[0] );
cubies.setColor(a, white);
cubies.setCoordinate(a++,paint[1] );
cubies.setColor(a, white);
cubies.setCoordinate(a++,paint[5] );
cubies.setColor(a, white);
cubies.setCoordinate(a++,paint[4] );
cubies.setColor(a, blue);
cubies.setCoordinate(a++,paint[2] );
cubies.setColor(a, blue);
cubies.setCoordinate(a++,paint[6] );
cubies.setColor(a, blue);
cubies.setCoordinate(a++,paint[7] );
cubies.setColor(a, blue);
cubies.setCoordinate(a++,paint[3] );
cubies.setColor(a, yellow);
cubies.setCoordinate(a++,paint[2] );
cubies.setColor(a, yellow);
cubies.setCoordinate(a++,paint[0] );
cubies.setColor(a, yellow);
cubies.setCoordinate(a++,paint[4] );
cubies.setColor(a, yellow);
cubies.setCoordinate(a++,paint[6] );
cubies.setColor(a, orange);
cubies.setCoordinate(a++,paint[1] );
cubies.setColor(a, orange);
cubies.setCoordinate(a++,paint[3] );
cubies.setColor(a, orange);
cubies.setCoordinate(a++,paint[7] );
cubies.setColor(a, orange);
cubies.setCoordinate(a++,paint[5] );
cubies.setColor(a, green);
cubies.setCoordinate(a++,paint[6] );
cubies.setColor(a, green);
cubies.setCoordinate(a++,paint[7] );
cubies.setColor(a, green);
cubies.setCoordinate(a++,paint[5] );
cubies.setColor(a, green);
cubies.setCoordinate(a++,paint[4] );
// for(int p = 0;p<5;p++)
// for(int i = 0;i<6;i+=2)
// for(int r = 0;r<6;r+=2)
// {
// cubies.setCoordinate(a++,points[p][i][r]); //One that goes front,
// cubies.setCoordinate(a++,points[p][i][1 + r]);
// cubies.setCoordinate(a++,points[p][1 + i][1 + r]);
// cubies.setCoordinate(a++,points[p][1 + i][r]);
//
// cubies.setCoordinate(a++,points[p][i][r]); //One that goes Left
// cubies.setCoordinate(a++,points[p][i+1][r]);
// cubies.setCoordinate(a++,points[p+1][1 + i][r]);
// cubies.setCoordinate(a++,points[p+1][i][r]);
//
// cubies.setCoordinate(a++,points[p][i][r]); //One that goes Up
// cubies.setCoordinate(a++,points[p][i][1 + r]);
// cubies.setCoordinate(a++,points[p+1][i][1 + r]);
// cubies.setCoordinate(a++,points[p+1][i][r]);
//
//
// }
a = 0;
for(int p = 0;p<6;p++)
for(int i = 0;i<6;i++)
for(int r = 0;r<6;r++)
cubiesP.setCoordinate(a++,points[p][i][r]); // Puts all points in a PointArray
}
public RubiksCube(double width, double distance, Color[] colors)
{
init(width, distance, colors); // Initializes the cube. No real point besides that it is simplified
}
}