public void Rotate(Vector3 face, int rotationMultiple) { lastItem.NextItem.LinkTo(new CommandQueueItem(face, rotationMultiple)); lastItem.LinkTo(lastItem.NextItem.NextItem); commandsInQueue++; }
public Cube(Game game, int cubeSize) : base(game) { this.cubeSize = cubeSize; firstItem = new CommandQueueItem(new Vector3(-1), 0); lastItem = new CommandQueueItem(new Vector3(-1), 0); lastItem.LinkTo(firstItem); }
private void ExecuteRotation() { if (firstItem.NextItem != null) { Vector3 slice = firstItem.NextItem.Slice; int rotationMultiple = firstItem.NextItem.RotationMultiple; // Modify the slice by the orientation of the cube. Vector3 faceModifier = new Vector3(-1, -1, -1); float sliceModifier = 0; if (slice.X != -1) { faceModifier = rightFace; sliceModifier = slice.X; } if (slice.Y != -1) { faceModifier = bottomFace; sliceModifier = slice.Y; } if (slice.Z != -1) { faceModifier = frontFace; sliceModifier = slice.Z; } if (faceModifier.X != -1) { slice = new Vector3(Math.Abs(faceModifier.X - sliceModifier), -1, -1); } if (faceModifier.Y != -1) { slice = new Vector3(-1, Math.Abs(faceModifier.Y - sliceModifier), -1); } if (faceModifier.Z != -1) { slice = new Vector3(-1, -1, Math.Abs(faceModifier.Z - sliceModifier)); } if (NonNegativeDimension(slice) != 0) { rotationMultiple *= -1; } // Check if any cubelets in the slice are rotating. bool isFaceRotating = false; for (int i = 0; i < cubelets.Length && !isFaceRotating; i++) { if (!isFaceRotating && (slice.X == cubelets[i].CubePosition.X || slice.Y == cubelets[i].CubePosition.Y || slice.Z == cubelets[i].CubePosition.Z)) { isFaceRotating = cubelets[i].IsRotating; } } // If no cubelets in the slice are rotating, then execute the current command. if (!isFaceRotating) { for (int i = 0; i < cubelets.Length; i++) { if (slice.X == cubelets[i].CubePosition.X) { cubelets[i].Rotate(new Vector3(rotationMultiple, 0, 0)); } else if (slice.Y == cubelets[i].CubePosition.Y) { cubelets[i].Rotate(new Vector3(0, rotationMultiple, 0)); } else if (slice.Z == cubelets[i].CubePosition.Z) { cubelets[i].Rotate(new Vector3(0, 0, rotationMultiple)); } } firstItem.LinkTo(firstItem.NextItem.NextItem); if (firstItem.NextItem == null) { lastItem.LinkTo(firstItem); } commandsInQueue--; selectedCubelet = -1; selectedQuad = null; } } }