void Start() { int i = 0; cubes = new CubeParams[8]; cubes[i] = new CubeParams("red", cubeColors[i++], new int[] { 0, 1, 3, 6, 9, 15 }); cubes[i] = new CubeParams("green", cubeColors[i++], new int[] { 2, 4, 7, 13, 19, 24 }); cubes[i] = new CubeParams("blue", cubeColors[i++], new int[] { 28, 5, 8, 10, 20, 47 }); cubes[i] = new CubeParams("pink", cubeColors[i++], new int[] { 33, 34, 11, 12, 17, 22 }); cubes[i] = new CubeParams("yellow", cubeColors[i++], new int[] { 14, 16, 37, 27, 39, 41 }); cubes[i] = new CubeParams("purple", cubeColors[i++], new int[] { 18, 21, 43, 44, 46, 23 }); cubes[i] = new CubeParams("cyan", cubeColors[i++], new int[] { 25, 26, 29, 35, 42, 38 }); cubes[i] = new CubeParams("brown", cubeColors[i++], new int[] { 30, 31, 32, 36, 45, 40 }); i = 0; rotation = new RotationParams[6]; rotation[i++] = new RotationParams(Axis4D.xy, 0f); rotation[i++] = new RotationParams(Axis4D.xz, 0f); rotation[i++] = new RotationParams(Axis4D.xw, 0f); rotation[i++] = new RotationParams(Axis4D.yz, 0f); rotation[i++] = new RotationParams(Axis4D.yw, 0f); rotation[i++] = new RotationParams(Axis4D.zw, 0f); ResetVertices(); SetupLineRenderer(); for (i = 0; i < faces.Length; i++) { FaceParams p = faces[i]; DrawFace(rotatedVerts[p.a], rotatedVerts[p.b], rotatedVerts[p.c], rotatedVerts[p.d], Vector3.zero, i, p.faceColor, p.faceGroup, p); } }
void HideCube(CubeParams cube) { for (int i = 0; i < cube.faceIndices.Length; i++) { HideFace(cube.faceIndices[i]); } }
void DrawCube(CubeParams cube) { // Cube center is average of all vertices Vector4 cubeCenter = Vector3.zero; int numVerts = 0; for (int i = 0; i < cube.faceIndices.Length; i++) { int faceIndex = cube.faceIndices[i]; FaceParams p = faces[faceIndex]; cubeCenter += rotatedVerts[p.a]; cubeCenter += rotatedVerts[p.b]; cubeCenter += rotatedVerts[p.c]; cubeCenter += rotatedVerts[p.d]; numVerts += 4; } cubeCenter *= 1.0f / numVerts; if (drawDebug) { Debug.DrawLine(Vector3.zero, cubeCenter, Color.red); } for (int i = 0; i < cube.faceIndices.Length; i++) { int faceIndex = cube.faceIndices[i]; FaceParams p = faces[faceIndex]; DrawFace( VectorFromProjection(projection, rotatedVerts[p.a]), VectorFromProjection(projection, rotatedVerts[p.b]), VectorFromProjection(projection, rotatedVerts[p.c]), VectorFromProjection(projection, rotatedVerts[p.d]), VectorFromProjection(projection, cubeCenter), faceIndex, cube.cubeColor, cube.tag, p); } }