public Rotation CreateRotationFromSides( CubeCoords coords1, CubeSide side1, CubeCoords coords2, CubeSide side2) { int left1 = coords1.Left; int top1 = coords1.Top; int depth1 = coords1.Depth; int left2 = coords2.Left; int top2 = coords2.Top; int depth2 = coords2.Depth; if (side1 == side2 && coords1 != coords2) { bool invert; Axis? equalsWay = GetEqualsWay(side1, left1, top1, depth1, left2, top2, depth2, out invert); if (equalsWay == null) return null; Axis rotation = (Axis)equalsWay; int layer = CoordsHelper.GetLayerFromAxis(rotation, coords1); return new Rotation(rotation, layer, !invert); } else if (coords1 == coords2 && side1 != side2) { int sum = (int)Axis.Left + (int)Axis.Top + (int)Axis.Depth; Axis axis1 = CoordsHelper.GetAxisFromSide(side1); Axis axis2 = CoordsHelper.GetAxisFromSide(side2); Axis rotation = (Axis)(sum - (int)axis1 - (int)axis2); int layer = CoordsHelper.GetLayerFromAxis(rotation, coords1); bool clockwise = false; for (int i = 0; i < rotationRules.GetLength(0); i++) { if (rotationRules[i, 0] == side1 && rotationRules[i, 1] == side2) { clockwise = true; break; } } return new Rotation(rotation, layer, clockwise); } return null; }
public CubeView(DataCube <SmallCube> model, Color[] colorMap, bool removeBlackParts) { if (colorMap == null) { throw new ArgumentNullException("colorMap"); } viewCube = new DataCube <CubePart>(model.Size); var partTransform = MatrixHelper.CreateScale(0.9f * 2f / model.Size); EmptyCubePart emptyPart = new EmptyCubePart(); int maxIndex = model.Size - 1; for (int i = 0; i < model.Size; i++) { for (int j = 0; j < model.Size; j++) { for (int k = 0; k < model.Size; k++) { bool isInnerCube = i != 0 && j != 0 && k != 0 && i != maxIndex && j != maxIndex && k != maxIndex; if (model[i, j, k] == null || removeBlackParts && isInnerCube) { viewCube[i, j, k] = emptyPart; } else { CubePart part = new TPart(); PaintCubePart(part, model[i, j, k], colorMap); part.World *= partTransform; part.Position = CoordsHelper.GetPositionFromCoords( new CubeCoords(i, j, k), model.Size); viewCube[i, j, k] = part; } } } } }