static CubeTransformations() { // rotations for faces Vector3[] faceRotations = { new Vector3(0, 0, 90), new Vector3(0, 0, 0), new Vector3(90, 0, 0), new Vector3(180, 0, 0), new Vector3(0, 0, -90), new Vector3(-90, 0, 0), }; // default tile is placed in the "up"-position // all other tiles are rotated with the origin as pivot Vector3 position = new Vector3(0, .5f, 0); Transformations = new TRSTransformation[6]; for (CubeFace face = 0; (int)face < 6; face++) { Transformations[(int)face] = new TRSTransformation(position, faceRotations[(int)face]); } }
static FlatTransformations() { // 1 ^= a whole face (3 tiles) Vector3[] faceOffsets = new Vector3[6] { new Vector3(-1, 1 / 3f, 0), new Vector3(-0.5f, 1, 0), new Vector3(-0.5f, 1 / 3f, 0), new Vector3(-0.5f, -1 / 3f, 0), new Vector3(0, 1 / 3f, 0), new Vector3(0.5f, 1 / 3f, 0) }; Transformations = new TRSTransformation[6, 9]; for (CubeFace face = 0; (int)face < 6; face++) { for (int tile = 0; tile < 9; tile++) { TRSTransformation transform = new TRSTransformation(faceOffsets[(int)face], new Vector3(0)); transform.Position += new Vector3(1 / 6f * (tile % 3), -1 / 4.5f * (tile / 3), 0); transform.Scale = new Vector3(1 / 6f, 1 / 4.5f, 1); Transformations[(int)face, tile] = transform; } } }
/// <summary> /// Properly construct transformations for faces of a cuboid /// <para> /// Access by [layer(up-down),layer(front-back), layer(left-right)] /// </para> /// </summary> static CuboidTransformations() { // order from top to bottom // start on white 0 going to white[-1] Transformations = new TRSTransformation[27]; CuboidMappings = new Dictionary <Vector3, Position[]>(); string[] lines = File.ReadAllLines("Resources/CuboidTileMappings.txt").Where(val => !val.Contains("//")).ToArray(); int lineIndex = 0; FaceMappings = new Dictionary <CubeFace, int[]>() { { CubeFace.LEFT, new int[] { 0, 3, 6, 9, 12, 15, 18, 21, 24 } }, { CubeFace.UP, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 } }, { CubeFace.FRONT, new int[] { 0, 1, 2, 9, 10, 11, 18, 19, 20 } }, { CubeFace.DOWN, new int[] { 18, 19, 20, 21, 22, 23, 24, 25, 26 } }, { CubeFace.RIGHT, new int[] { 2, 5, 8, 11, 14, 17, 20, 23, 26 } }, { CubeFace.BACK, new int[] { 6, 7, 8, 15, 16, 17, 24, 25, 26 } }, }; for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { for (int x = 0; x < 3; x++) { // mapping string line = lines[lineIndex]; List <Position> positions = new List <Position>(); while (!line.Contains("end")) { Console.WriteLine(line); string[] split = line.Split(','); Position pos = new Position((CubeFace)int.Parse(split[0]), int.Parse(split[1])); positions.Add(pos); line = lines[++lineIndex]; } // x - 1 ... necessary to center cube CuboidMappings.Add(new Vector3(x - 1, 1 - y, 1 - z), positions.ToArray()); // transformations Transformations[y * 9 + z * 3 + x] = new TRSTransformation( new Vector3(x - 1, 1 - y, 1 - z), new Vector3(0, 0, 0)); Log.LogStuff(x + " " + y + " " + z); Log.LogStuff((y * 9 + z * 3 + x).ToString()); lineIndex++; } } } }
public static void Init(Vector3[] _renderColors, Cube cube = null) { cubeShader = new Shader("Resources/CubeShader"); flatShader = new Shader("Resources/FlatShader"); cubeShader.Bind(); // texture units to sampler for (int i = 0; i < 2; i++) { cubeShader.Upload(string.Format("texture{0}", i.ToString()), i); } if (cube != null) { currentState = cube; } else { currentState = new Cube(); } renderColors = _renderColors; faceRotations = new float[6]; faceRotationMatrices = new Matrix4[6]; Transformation = new TRSTransformation(); Transformation.Scale = new Vector3(2); for (int i = 0; i < 6; i++) { faceRotationMatrices[i] = Matrix4.Identity; } moveQueue = new Queue <AnimatedMove>(); Log.LogStuff("Animation Thread Start"); }