Esempio n. 1
0
    /// <summary>
    /// Returns true if it gets even one valid point on the specified face, else returns false
    /// </summary>
    /// <param name="inX"></param>
    /// <param name="inY"></param>
    /// <param name="inZ"></param>
    /// <param name="inFace"></param>
    /// <returns></returns>
    public bool IsFaceWithValidPt(int inX, int inY, int inZ, CubeFaceType inFace)
    {
        if (!(inX > 0 && inX < _moldFileInfo.X && inY > 0 && inY < _moldFileInfo.Y && inZ > 0 && inZ < _moldFileInfo.Z))
        {
            throw new Exception("cube indexes should be one less than total points");
        }

        if (!(inFace == CubeFaceType.MaxX || inFace == CubeFaceType.MaxY || inFace == CubeFaceType.MaxZ))
        {
            throw new Exception("Face is not a right value.");
        }

        if (inFace == CubeFaceType.MaxX)
        {
            //frontTopRight - frontBottomRight - backTopRight - backBottomRight
            return(IsValidPoint(inX + 1, inY, inZ) || IsValidPoint(inX + 1, inY + 1, inZ) || IsValidPoint(inX + 1, inY, inZ + 1) || IsValidPoint(inX + 1, inY + 1, inZ + 1));
        }
        if (inFace == CubeFaceType.MaxY)
        {
            //frontTopRight - frontTopLeft - backTopRight - backTopLeft
            return(IsValidPoint(inX, inY + 1, inZ) || IsValidPoint(inX + 1, inY + 1, inZ) || IsValidPoint(inX, inY + 1, inZ + 1) || IsValidPoint(inX + 1, inY + 1, inZ + 1));
        }
        if (inFace != CubeFaceType.MaxZ)
        {
            throw new Exception("Cube face type is not one of the expected values.");
        }

        //frontTopRight - frontBottomRight - frontBottomLeft - frontTopLeft
        return(IsValidPoint(inX, inY + 1, inZ + 1) || IsValidPoint(inX, inY, inZ + 1) || IsValidPoint(inX + 1, inY, inZ + 1) || IsValidPoint(inX + 1, inY + 1, inZ + 1));
    }
Esempio n. 2
0
 private void SetFacePosition(VisualCube c, VisualCubeFace fToTurn, CubeFaceType desiredType)
 {
     if (fToTurn.FaceType != desiredType)
     {
         c.TurnCube(fToTurn, desiredType);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Gets the correpondent face.
 /// </summary>
 /// <param name="color">The position of the face</param>
 /// <returns>Returns the face position.</returns>
 /// <exception cref="IndexOutOfRangeException"></exception>
 public CubeFace this[CubeFaceType type]
 {
     get
     {
         foreach (KeyValuePair<CubeFace, CubeFaceType> entry in CubeMap)
         {
             if (entry.Value.Equals(type))
                 return entry.Key;
         }
         throw new IndexOutOfRangeException();
     }
 }
Esempio n. 4
0
 void SetFaceTexture(CubeFaceType faceType, Vector2[] uvs)
 {
     if (faceType == CubeFaceType.Front)
     {
         Vector2[] newUVS = GetUVS(frontPoint.x, frontPoint.y);
         uvs[0] = newUVS[0];
         uvs[1] = newUVS[1];
         uvs[2] = newUVS[2];
         uvs[3] = newUVS[3];
     }
     else if (faceType == CubeFaceType.Back)
     {
         Vector2[] newUVS = GetUVS(backPoint.x, backPoint.y);
         uvs[10] = newUVS[0];
         uvs[11] = newUVS[1];
         uvs[6]  = newUVS[2];
         uvs[7]  = newUVS[3];
     }
     else if (faceType == CubeFaceType.Top)
     {
         Vector2[] newUVS = GetUVS(topPoint.x, topPoint.y);
         uvs[8] = newUVS[0];
         uvs[9] = newUVS[1];
         uvs[4] = newUVS[2];
         uvs[5] = newUVS[3];
     }
     else if (faceType == CubeFaceType.Bottom)
     {
         Vector2[] newUVS = GetUVS(bottomPoint.x, bottomPoint.y);
         uvs[12] = newUVS[0];
         uvs[14] = newUVS[1];
         uvs[15] = newUVS[2];
         uvs[13] = newUVS[3];
     }
     else if (faceType == CubeFaceType.Left)
     {
         Vector2[] newUVS = GetUVS(leftPoint.x, leftPoint.y);
         uvs[16] = newUVS[0];
         uvs[18] = newUVS[1];
         uvs[19] = newUVS[2];
         uvs[17] = newUVS[3];
     }
     else if (faceType == CubeFaceType.Right)
     {
         Vector2[] newUVS = GetUVS(rightPoint.x, rightPoint.y);
         uvs[20] = newUVS[0];
         uvs[22] = newUVS[1];
         uvs[23] = newUVS[2];
         uvs[21] = newUVS[3];
     }
 }
Esempio n. 5
0
    private void CheckInput()
    {
        if(MainCamera == null || Target == null)
            return;

        if(Input.GetKey(KeyCode.D))
        {
            m_inputState = InputState.Deletion;
        }
        else if(Status == GameStatus.Editor && Input.GetKey(KeyCode.A))
        {
            m_inputState = InputState.Addition;
        }
        else if(Input.GetKey(KeyCode.W))
        {
            m_inputState = InputState.Mark;
        }
        else
            m_inputState = InputState.None;

        if(m_clickable && Input.GetMouseButtonDown(0))
        {
            //从摄像机发出到点击坐标的射线
            Ray ray = MainCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            if(Physics.Raycast(ray, out hitInfo, 100f, 1<<8))
            {
                //划出射线,只有在scene视图中才能看到
                Debug.DrawLine(ray.origin, hitInfo.point);
                ModelCube target = hitInfo.collider.gameObject.GetComponent<ModelCube>();
                if(target != null)
                {
                    Vector3 point = target.transform.InverseTransformPoint(hitInfo.point);

                    switch(m_inputState)
                    {
                        case InputState.Mark:
                            //cube.Mark();
                            break;
                        case InputState.Deletion:
                            Target.DeleteCube(target);
                            break;
                        case InputState.Addition:
                            CubeFaceType face = ClickFace(point);
                            Target.AddCube(target, face);
                            break;
                    }//end switch
                }//end null
            }//end ray
        }//end buttondown
    }
Esempio n. 6
0
        private GeometryModel3D PrepareCubeFace(CubeFaceType face, Brush brush, double aspect)
        {
            // Create the mesh
            var mesh = ((MeshGeometry3D)_viewport.Resources["CubeFace"]).Clone();

            switch (face)
            {
            case CubeFaceType.Left:
                mesh.Positions[0] = new Point3D(-aspect / 2, 0.5, -aspect);
                mesh.Positions[1] = new Point3D(-aspect / 2, 0.5, 0);
                mesh.Positions[2] = new Point3D(-aspect / 2, -0.5, 0);
                mesh.Positions[3] = new Point3D(-aspect / 2, -0.5, -aspect);
                break;

            case CubeFaceType.Right:
                mesh.Positions[0] = new Point3D(aspect / 2, 0.5, 0);
                mesh.Positions[1] = new Point3D(aspect / 2, 0.5, -aspect);
                mesh.Positions[2] = new Point3D(aspect / 2, -0.5, -aspect);
                mesh.Positions[3] = new Point3D(aspect / 2, -0.5, 0);
                break;

            case CubeFaceType.Top:
                mesh.Positions[0] = new Point3D(-aspect / 2, 0.5, -1);
                mesh.Positions[1] = new Point3D(aspect / 2, 0.5, -1);
                mesh.Positions[2] = new Point3D(aspect / 2, 0.5, 0);
                mesh.Positions[3] = new Point3D(-aspect / 2, 0.5, 0);
                break;

            case CubeFaceType.Bottom:
                mesh.Positions[0] = new Point3D(-aspect / 2, -0.5, 0);
                mesh.Positions[1] = new Point3D(aspect / 2, -0.5, 0);
                mesh.Positions[2] = new Point3D(aspect / 2, -0.5, -1);
                mesh.Positions[3] = new Point3D(-aspect / 2, -0.5, -1);
                break;

            case CubeFaceType.Front:
                mesh.Positions[0] = new Point3D(-aspect / 2, 0.5, 0);
                mesh.Positions[1] = new Point3D(aspect / 2, 0.5, 0);
                mesh.Positions[2] = new Point3D(aspect / 2, -0.5, 0);
                mesh.Positions[3] = new Point3D(-aspect / 2, -0.5, 0);
                break;
            }

            // Apply material
            var material = new DiffuseMaterial(brush);

            // Create the model
            var model = new GeometryModel3D(mesh, material);

            return(model);
        }
Esempio n. 7
0
 protected void SetFaceTexture(CubeFaceType faceType, Vector2[] uvs)
 {
     if (faceType == CubeFaceType.Front)
     {
         Vector2[] newUVS = GetUVS(FrontPoint.x, FrontPoint.y);
         uvs[0] = newUVS[0];
         uvs[1] = newUVS[1];
         uvs[2] = newUVS[2];
         uvs[3] = newUVS[3];
     }
     else if (faceType == CubeFaceType.Back)
     {
         Vector2[] newUVS = GetUVS(BackPoint.x, BackPoint.y);
         uvs[7]  = newUVS[0];
         uvs[6]  = newUVS[1];
         uvs[11] = newUVS[2];
         uvs[10] = newUVS[3];
     }
     else if (faceType == CubeFaceType.Top)
     {
         Vector2[] newUVS = GetUVS(TopPoint.x, TopPoint.y);
         uvs[8] = newUVS[0];
         uvs[9] = newUVS[1];
         uvs[4] = newUVS[2];
         uvs[5] = newUVS[3];
     }
     else if (faceType == CubeFaceType.Bottom)
     {
         Vector2[] newUVS = GetUVS(BottomPoint.x, BottomPoint.y);
         uvs[15] = newUVS[1];
         uvs[12] = newUVS[0];
         uvs[13] = newUVS[2];
         uvs[14] = newUVS[3];
     }
     else if (faceType == CubeFaceType.Left)
     {
         Vector2[] newUVS = GetUVS(LeftPoint.x, LeftPoint.y);
         uvs[19] = newUVS[1];
         uvs[16] = newUVS[0];
         uvs[17] = newUVS[2];
         uvs[18] = newUVS[3];
     }
     else if (faceType == CubeFaceType.Right)
     {
         Vector2[] newUVS = GetUVS(RightPoint.x, RightPoint.y);
         uvs[23] = newUVS[1];
         uvs[20] = newUVS[0];
         uvs[21] = newUVS[2];
         uvs[22] = newUVS[3];
     }
 }
Esempio n. 8
0
            public Face( Cube cube, CubeFaceType type, Vector3 normal, Vector3 up, Direction rotation )
                : base(cube.Game)
            {
                Cube = cube;
                Type = type;
                Normal = Vector3.Normalize( normal );
                UpVec = Vector3.Normalize( up );
                RightVec = Vector3.Cross( Normal, UpVec );
                Rotation = -rotation.Angle;
                BackgroundColor = Color.Gray;

                SetUpVertices();
                SetUpWorld();
            }
Esempio n. 9
0
 /// <summary>
 /// Change the position of the blocks from U or D face. DOES NOT CHECK if the value of coordinate is 0.
 /// </summary>
 /// <param name="faceType">The facetype wich the blockmatrix belong</param>
 /// <param name="blockMatrix">The block matrix to change positions</param>
 /// <param name="coord">The coordinate of the movement</param>
 private void ChangeUDBlockPosition(CubeFaceType faceType, List<VisualCubeBlock> blockMatrix, Coordinate coord)
 {
     switch (coord.Axis)
     {
         case CoordinateAxis.X:
             if (coord.Value == 90)
                 RotateBlockMatrix(blockMatrix, true);
             else if (coord.Value == -90)
                 RotateBlockMatrix(blockMatrix, false);
             else
             {
                 RotateBlockMatrix(blockMatrix, false);
                 RotateBlockMatrix(blockMatrix, false);
             }
             break;
         case CoordinateAxis.Y:
             if (faceType == CubeFaceType.U && coord.Value == -90)
             {
                 RotateBlockMatrix(blockMatrix, true);
                 RotateBlockMatrix(blockMatrix, true);
             }
             else if (faceType == CubeFaceType.D && coord.Value == +90)
             {
                 RotateBlockMatrix(blockMatrix, true);
                 RotateBlockMatrix(blockMatrix, true);
             }
             break;
         case CoordinateAxis.Z:
             if (coord.Value != 180)
                 RotateBlockMatrix(blockMatrix, IsClockWise(faceType, coord));
             else
             {
                 RotateBlockMatrix(blockMatrix, true);
                 RotateBlockMatrix(blockMatrix, true);
             }
             break;
         default:
             break;
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Change the block matrix positions of the F and the B faces.DOES NOT CHECK if the value of coordinate is 0.
 /// </summary>
 /// <param name="faceType">The facetype wich the blockmatrix belong</param>
 /// <param name="blockMatrix">The block matrix to change positions</param>
 /// <param name="coord">The coordinate of the movement</param>
 private void ChangeFBBlockPosition(CubeFaceType faceType, List<VisualCubeBlock> blockMatrix, Coordinate coord)
 {
     switch (coord.Axis)
     {
         case CoordinateAxis.X:
             if (coord.Value == 90)
                 RotateBlockMatrix(blockMatrix, (faceType == CubeFaceType.F));
             else if (coord.Value == -90)
                 RotateBlockMatrix(blockMatrix, (faceType != CubeFaceType.F));
             else
             {
                 RotateBlockMatrix(blockMatrix, true);
                 RotateBlockMatrix(blockMatrix, true);
             }
             break;
         case CoordinateAxis.Y:
             if (faceType == CubeFaceType.B)
             {
                 RotateBlockMatrix(blockMatrix, true);
                 RotateBlockMatrix(blockMatrix, true);
             }
             else if (coord.Value == 180)
             {
                 RotateBlockMatrix(blockMatrix, true);
                 RotateBlockMatrix(blockMatrix, true);
             }
             break;
         case CoordinateAxis.Z:
             //No changes
             break;
     }
 }
Esempio n. 11
0
 /// <summary>
 /// Change the position of the blocks from L or R face. DOES NOT CHECK if the value of coordinate is 0.
 /// </summary>
 /// <param name="faceType">The facetype wich the blockmatrix belong</param>
 /// <param name="blockMatrix">The block matrix to change positions</param>
 /// <param name="coord">The coordinate of the movement</param>
 private void ChangeLRBlockPosition(CubeFaceType faceType, List<VisualCubeBlock> blockMatrix, Coordinate coord)
 {
     switch (coord.Axis)
     {
         case CoordinateAxis.X:
             if (coord.Value == 90)
                 RotateBlockMatrix(blockMatrix, true);
             else if (coord.Value == -90)
                 RotateBlockMatrix(blockMatrix, false);
             else
             {
                 RotateBlockMatrix(blockMatrix, false);
                 RotateBlockMatrix(blockMatrix, false);
             }
             break;
         case CoordinateAxis.Y:
             if (coord.Value != 180)
                 RotateBlockMatrix(blockMatrix, IsClockWise(faceType, coord));
             else
             {
                 RotateBlockMatrix(blockMatrix, false);
                 RotateBlockMatrix(blockMatrix, false);
             }
             break;
         case CoordinateAxis.Z:
             //It is not affected
             break;
     }
 }
Esempio n. 12
0
 /// <summary>
 /// Turns the especific face
 /// </summary>
 /// <param name="faceType">The type of the face</param>
 /// <param name="coord">The coordinate of the face</param>
 public void TurnFace(CubeFaceType faceType, Coordinate coord)
 {
     switch (faceType)
     {
         case CubeFaceType.U:
         case CubeFaceType.D:
             TurnUDFace(faceType, coord);
             break;
         case CubeFaceType.L:
         case CubeFaceType.R:
             TurnLFace(faceType, coord);
             break;
         case CubeFaceType.F:
         case CubeFaceType.B:
             TurnFBFace(faceType, coord);
             break;
     }
 }
Esempio n. 13
0
 /// <summary>
 /// Changes the position of all cubeblocks. CHECKS if the coordinate value is 0.
 /// </summary>
 /// <param name="faceType">Type of the face</param>
 /// <param name="blockMatrix">The blockmatrix of the face</param>
 /// <param name="coord">The coordinate of the movement</param>
 private void ChangeBlocksPosition(CubeFaceType faceType, List<VisualCubeBlock> blockMatrix, Coordinate coord)
 {
     if (coord.Value != 0)
     {
         switch (faceType)
         {
             case CubeFaceType.U:
             case CubeFaceType.D:
                 ChangeUDBlockPosition(faceType, blockMatrix, coord);
                 break;
             case CubeFaceType.L:
             case CubeFaceType.R:
                 ChangeLRBlockPosition(faceType, blockMatrix, coord);
                 break;
             case CubeFaceType.F:
             case CubeFaceType.B:
                 ChangeFBBlockPosition(faceType, blockMatrix, coord);
                 break;
         }
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Gets the correpondent face.
 /// </summary>
 /// <param name="type">Type of the face</param>
 /// <returns>Returns the face.</returns>
 /// <exception cref="IndexOutOfRangeException"></exception>
 public VisualCubeFace this[CubeFaceType type]
 {
     get
     {
         VisualCubeFace face = null;
         foreach (VisualCubeFace item in _faces)
         {
             if (item.FaceType == type)
             {
                 face = item;
                 break;
             }
         }
         if (face != null)
             return face;
         else
             throw new IndexOutOfRangeException();
     }
 }
Esempio n. 15
0
 /// <summary>
 /// Turns, if it is necessary, the cube to the face become the desired type.
 /// </summary>
 /// <param name="f">Face to turn</param>
 /// <param name="desiredType">Desired type for the face</param>
 public void TurnCube(VisualCubeFace f, CubeFaceType desiredType)
 {
     if (f.FaceType != desiredType)
     {
         Coordinate coord = GetVariationMovement(f.FaceType, desiredType);
         TurnCube(coord);
     }
 }
Esempio n. 16
0
 public World this[CubeFaceType faceType]
 {
     get {
         switch ( faceType )
         {
         case CubeFaceType.Front:
             return StringToWorld( FrontFace );
         case CubeFaceType.Back:
             return StringToWorld( BackFace );
         case CubeFaceType.Top:
             return StringToWorld( TopFace );
         case CubeFaceType.Bottom:
             return StringToWorld( BottomFace );
         case CubeFaceType.Left:
             return StringToWorld( LeftFace );
         case CubeFaceType.Right:
             return StringToWorld( RightFace );
         default:
             throw new ArgumentException();
         }
     }
     set {
         switch ( faceType )
         {
         case CubeFaceType.Front:
             FrontFace = WorldToString( value );
             break;
         case CubeFaceType.Back:
             BackFace = WorldToString( value );
             break;
         case CubeFaceType.Top:
             TopFace = WorldToString( value );
             break;
         case CubeFaceType.Bottom:
             BottomFace = WorldToString( value );
             break;
         case CubeFaceType.Left:
             LeftFace = WorldToString( value );
             break;
         case CubeFaceType.Right:
             RightFace = WorldToString( value );
             break;
         default:
             throw new ArgumentException();
         }
     }
 }
 public static Point GetPoint(CubeFaceType face, CubeFaceletType square)
 {
     return positions[face.GetHashCode(), square.GetHashCode()];
 }
Esempio n. 18
0
 /// <summary>
 /// Turn the face based on coordinates
 /// </summary>
 /// <param name="face">The face to be turned</param>
 /// <param name="coord">The coordinates</param>
 /// <returns>Return the new face, after the turn.</returns>
 private CubeFaceType RotateFace(CubeFaceType face, Coordinate coord)
 {
     CubeFaceType newFace = CubeFaceType.U;
     switch (face)
     {
         case CubeFaceType.U:
             newFace = RotateUFace(coord);
             break;
         case CubeFaceType.D:
             newFace = RotateDFace(coord);
             break;
         case CubeFaceType.L:
             newFace = RotateLFace(coord);
             break;
         case CubeFaceType.R:
             newFace = RotateRFace(coord);
             break;
         case CubeFaceType.F:
             newFace = RotateFFace(coord);
             break;
         case CubeFaceType.B:
             newFace = RotateBFace(coord);
             break;
     }
     return newFace;
 }
Esempio n. 19
0
 /// <summary>
 /// Get the coordinates of the movement based on the face origins
 /// </summary>
 /// <param name="fOriging">FaceType origins of the movement</param>
 /// <param name="fDestiny">FaceType destiny</param>
 /// <returns>Returns the coordinate for the new movement</returns>
 private Coordinate GetVariationMovement(CubeFaceType fOriging, CubeFaceType fDestiny)
 {
     int fOr = fOriging.GetHashCode();
     int fDes = fDestiny.GetHashCode();
     return default_moves[fOr, fDes];
 }
Esempio n. 20
0
        private GeometryModel3D PrepareCubeFace(CubeFaceType face, Brush brush, double aspect)
        {
            // Create the mesh
            MeshGeometry3D mesh = (_viewport.Resources["CubeFace"] as MeshGeometry3D).Clone();
            switch (face)
            {
                case CubeFaceType.Left:
                    mesh.Positions[0] = new Point3D(-aspect/2, 0.5, -aspect);
                    mesh.Positions[1] = new Point3D(-aspect/2, 0.5, 0);
                    mesh.Positions[2] = new Point3D(-aspect/2, -0.5, 0);
                    mesh.Positions[3] = new Point3D(-aspect/2, -0.5, -aspect);
                    break;
                case CubeFaceType.Right:
                    mesh.Positions[0] = new Point3D(aspect/2, 0.5, 0);
                    mesh.Positions[1] = new Point3D(aspect/2, 0.5, -aspect);
                    mesh.Positions[2] = new Point3D(aspect/2, -0.5, -aspect);
                    mesh.Positions[3] = new Point3D(aspect/2, -0.5, 0);
                    break;
                case CubeFaceType.Top:
                    mesh.Positions[0] = new Point3D(-aspect/2, 0.5, -1);
                    mesh.Positions[1] = new Point3D(aspect/2, 0.5, -1);
                    mesh.Positions[2] = new Point3D(aspect/2, 0.5, 0);
                    mesh.Positions[3] = new Point3D(-aspect/2, 0.5, 0);
                    break;
                case CubeFaceType.Bottom:
                    mesh.Positions[0] = new Point3D(-aspect/2, -0.5, 0);
                    mesh.Positions[1] = new Point3D(aspect/2, -0.5, 0);
                    mesh.Positions[2] = new Point3D(aspect/2, -0.5, -1);
                    mesh.Positions[3] = new Point3D(-aspect/2, -0.5, -1);
                    break;
                case CubeFaceType.Front:
                    mesh.Positions[0] = new Point3D(-aspect/2, 0.5, 0);
                    mesh.Positions[1] = new Point3D(aspect/2, 0.5, 0);
                    mesh.Positions[2] = new Point3D(aspect/2, -0.5, 0);
                    mesh.Positions[3] = new Point3D(-aspect/2, -0.5, 0);
                    break;
            }

            // Apply material
            DiffuseMaterial material = new DiffuseMaterial(brush);

            // Create the model
            GeometryModel3D model = new GeometryModel3D(mesh, material);
            return model;
        }
        /// <summary>
        /// Adds the rotation movement.
        /// </summary>
        /// <param name="positionFace">Position of the face to be turned</param>
        /// <param name="movements">List of movements to be concatenated of the new movement</param>
        private void BringFaceToSomeClaw(CubeFaceType positionFace, CubeFaceType nextPositionFace, List<Movement> movements)
        {
            // se face não está diretamente ligada a uma das garras, leva a face para a garra
            if (!positionFace.Equals(Claw_L) && !positionFace.Equals(Claw_F))
            {
                RotateCubeMovement mov = new RotateCubeMovement();

                switch (positionFace)
                {
                    case CubeFaceType.U:
                        if (nextPositionFace.Equals(CubeFaceType.F))
                        {
                            mov.Axis = CoordinateAxis.X;
                            mov.Type = TurnType.HalfTurnLeft;
                        }
                        else
                        {
                            mov.Axis = CoordinateAxis.Y;
                            mov.Type = TurnType.HalfTurnRight;
                        }
                        break;
                    case CubeFaceType.B:
                        mov.Axis = CoordinateAxis.Y;
                        mov.Type = TurnType.FullTurn;
                        break;
                    case CubeFaceType.R:
                        mov.Axis = CoordinateAxis.X;
                        mov.Type = TurnType.FullTurn;
                        break;
                    case CubeFaceType.D:
                        if (nextPositionFace.Equals(CubeFaceType.F))
                        {
                            mov.Axis = CoordinateAxis.X;
                            mov.Type = TurnType.HalfTurnRight;
                        }
                        else
                        {
                            mov.Axis = CoordinateAxis.Y;
                            mov.Type = TurnType.HalfTurnLeft;
                        }
                        break;
                }
                // turns the representation of the cube (very important)
                Cube.TurnCube(mov);
                // adds the new movement to the list of movements
                movements.Add(mov);
            }
        }
Esempio n. 22
0
 private static int[] SortFacelets(CubeFaceType face)
 {
     int[] faceUL = {
                        (int)CubeFaceletType.UpLeft, (int)CubeFaceletType.UpMid,(int)CubeFaceletType.UpRight,
                        (int)CubeFaceletType.MidLeft,(int)CubeFaceletType.Center, (int)CubeFaceletType.MidRight,
                        (int)CubeFaceletType.DownLeft, (int)CubeFaceletType.DownMid,(int)CubeFaceletType.DownRight
                    };
     int[] faceUR = {
                        (int)CubeFaceletType.UpRight, (int)CubeFaceletType.MidRight,(int)CubeFaceletType.DownRight,
                        (int)CubeFaceletType.UpMid,(int)CubeFaceletType.Center, (int)CubeFaceletType.DownMid,
                        (int)CubeFaceletType.UpLeft, (int)CubeFaceletType.MidLeft,(int)CubeFaceletType.DownLeft
                    };
     int[] faceDL = {
                        (int)CubeFaceletType.DownLeft, (int)CubeFaceletType.MidLeft,(int)CubeFaceletType.UpLeft,
                        (int)CubeFaceletType.DownMid,(int)CubeFaceletType.Center, (int)CubeFaceletType.UpMid,
                        (int)CubeFaceletType.DownRight, (int)CubeFaceletType.MidRight,(int)CubeFaceletType.UpRight
                    };
     int[] faceDR = {
                        (int)CubeFaceletType.DownRight,(int)CubeFaceletType.DownMid,(int)CubeFaceletType.DownLeft,
                        (int)CubeFaceletType.MidRight,(int)CubeFaceletType.Center,(int)CubeFaceletType.MidLeft,
                        (int)CubeFaceletType.UpRight,(int)CubeFaceletType.UpMid,(int)CubeFaceletType.UpLeft
                    };
     switch (face)
     {
         case CubeFaceType.U:
             return faceUR;
         case CubeFaceType.B:
             return faceDL;
         case CubeFaceType.D:
             return faceUR;
         case CubeFaceType.F:
             return faceUR;
         case CubeFaceType.R:
             return faceDR;
         case CubeFaceType.L:
             return faceDR;
         default:
             return faceUR;
     }
 }
Esempio n. 23
0
 /// <summary>
 /// Indicates if the movement is clockwise or counter-clockwise to the face.
 /// </summary>
 /// <param name="faceType">Type of the face</param>
 /// <param name="coord">Coordinate of the movement</param>
 /// <returns>Returns true if the movement is clockwise. Otherwise, false</returns>
 private bool IsClockWise(CubeFaceType faceType, Coordinate coord)
 {
     bool _isClockwise = false;
     switch (faceType)
     {
         case CubeFaceType.U:
             if (coord.Axis == CoordinateAxis.Z)
             {
                 if (coord.Value == 90)
                     _isClockwise = true;
                 else if (coord.Value == -90)
                     _isClockwise = false;
             }
             break;
         case CubeFaceType.D:
             if (coord.Axis == CoordinateAxis.Z)
             {
                 if (coord.Value == -90)
                     _isClockwise = true;
                 else if (coord.Value == +90)
                     _isClockwise = false;
             }
             break;
         case CubeFaceType.L:
             if (coord.Axis == CoordinateAxis.Y)
             {
                 if (coord.Value == 90)
                     _isClockwise = true;
                 else if (coord.Value == -90)
                     _isClockwise = false;
             }
             break;
         case CubeFaceType.R:
             if (coord.Axis == CoordinateAxis.Y)
             {
                 if (coord.Value == -90)
                     _isClockwise = true;
                 else if (coord.Value == +90)
                     _isClockwise = false;
             }
             break;
         case CubeFaceType.F:
             if (coord.Axis == CoordinateAxis.X)
             {
                 if (coord.Value == 90)
                     _isClockwise = true;
                 else if (coord.Value == -90)
                     _isClockwise = false;
             }
             break;
         case CubeFaceType.B:
             if (coord.Axis == CoordinateAxis.X)
             {
                 if (coord.Value == -90)
                     _isClockwise = true;
                 else if (coord.Value == +90)
                     _isClockwise = false;
             }
             break;
     }
     return _isClockwise;
 }
Esempio n. 24
0
    public bool AddCube(ModelCube target, CubeFaceType face)
    {
        if (!m_editable)
        {
            return(false);
        }
        ModelCube prefab = Resources.Load <ModelCube>("Prefabs/ModelCube");

        if (prefab == null)
        {
            return(false);
        }

        int     current = 1;
        Vector3 offset  = Vector3.right;

        switch (face)
        {
        case CubeFaceType.Top:
            offset  = Vector3.up;
            current = m_info.Heigth;
            break;

        case CubeFaceType.Bottom:
            offset  = Vector3.down;
            current = m_info.Heigth;
            break;

        case CubeFaceType.Front:
            offset  = Vector3.forward;
            current = m_info.Depth;
            break;

        case CubeFaceType.Back:
            offset  = Vector3.back;
            current = m_info.Depth;
            break;

        case CubeFaceType.Right:
            offset  = Vector3.right;
            current = m_info.Width;
            break;

        case CubeFaceType.Left:
            offset  = Vector3.left;
            current = m_info.Width;
            break;
        }

        if (current >= GameConst.CubeMax)
        {
            return(false);
        }

        CubeModelData data = new CubeModelData();

        data.Pos = target.ModelData.Pos + offset;
        m_info.Cubes.Add(data);

        ModelCube cube = GameObject.Instantiate <ModelCube>(prefab);

        cube.transform.parent        = transform;
        cube.transform.localPosition = data.Pos;
        cube.ModelData = data;
        m_cubes.Add(cube);

        UpdateWHD(cube);
        return(true);
    }
Esempio n. 25
0
        /// <summary>
        /// Turns the L or R face
        /// </summary>
        /// <param name="faceType">The type of the face</param>
        /// <param name="coord">Coordinate of the movement</param>
        private void TurnLFace(CubeFaceType faceType, Coordinate coord)
        {
            if (coord.Value != 0)
            {
                if (coord.Axis != CoordinateAxis.Y)
                {
                    //If not Y, it is impossible to turn only the L/R face. So, it turns the whole cube
                    TurnCube(coord);
                }
                else
                {
                    //Changes the position of the blocks in the face
                    ChangeLRBlockPosition(faceType, this[faceType].GetBlocks(), coord);

                    List<VisualCubeBlock> next_Blocks = new List<VisualCubeBlock>();
                    List<VisualCubeBlock> block_toChange = new List<VisualCubeBlock>();
                    List<VisualCubeBlock> search_blocks = new List<VisualCubeBlock>();
                    CubeFaceType[] face_order = new CubeFaceType[] { CubeFaceType.F, CubeFaceType.D, CubeFaceType.B, CubeFaceType.U };

                    bool clockwise = IsClockWise(CubeFaceType.L, coord);
                    int index;
                    int post_index = 0;
                    int incremento = (coord.Value != 180) ? 1 : 2;
                    int limit = (coord.Value != 180) ? 4 : 2;
                    for (int i = 0; i < limit; i++)
                    {
                        //Determine the current index and the next index
                        index = i;
                        post_index = index + incremento;
                        if (!clockwise && coord.Value != 180)
                        {
                            index = 3 - index;
                            post_index = index - 1;
                        }
                        //Ajust last post_index
                        if (post_index == -1)
                            post_index = 3;
                        else if (post_index == 4)
                            post_index = 0;
                        //Gets the current face and the next face
                        VisualCubeFace currentFace = this[face_order[index]];
                        VisualCubeFace nextFace = this[face_order[post_index]];
                        //Save the next blocks
                        if (faceType == CubeFaceType.L)
                        {
                            search_blocks = (face_order[post_index] == CubeFaceType.B) ? nextFace.GetRightBlocks() : nextFace.GetLeftBlocks();
                        }
                        else
                        {
                            search_blocks = (face_order[post_index] != CubeFaceType.B) ? nextFace.GetRightBlocks() : nextFace.GetLeftBlocks();
                        }
                        next_Blocks.Clear();
                        foreach (VisualCubeBlock item in search_blocks)
                        {
                            next_Blocks.Add(item.Clone());
                        }
                        //load the current blocks, if necessary
                        if (block_toChange.Count == 0)
                        {
                            if (faceType == CubeFaceType.L)
                            {
                                search_blocks = (face_order[index] == CubeFaceType.B) ? currentFace.GetRightBlocks() : currentFace.GetLeftBlocks();
                            }
                            else
                            {
                                search_blocks = (face_order[index] != CubeFaceType.B) ? currentFace.GetRightBlocks() : currentFace.GetLeftBlocks();
                            }
                            foreach (VisualCubeBlock item in search_blocks)
                            {
                                VisualCubeBlock toChange = item.Clone();
                                block_toChange.Add(toChange);
                            }
                        }
                        //Changes the position of the blocks turned
                        ChangeBlocksPosition(face_order[index], block_toChange, coord);

                        //Adds to the face
                        foreach (VisualCubeBlock item in block_toChange)
                        {
                            nextFace.AddBlock(item.Clone(), false);
                        }

                        //Redo the cycle, copying the temp_blocks to block_toChange;
                        block_toChange.Clear();
                        if (coord.Value != 180)
                        {
                            foreach (VisualCubeBlock item in next_Blocks)
                            {
                                block_toChange.Add(item.Clone());
                            }
                        }
                        else
                        {
                            ChangeBlocksPosition(face_order[post_index], next_Blocks, coord);
                            foreach (VisualCubeBlock item in next_Blocks)
                            {
                                currentFace.AddBlock(item.Clone(), false);
                            }
                        }
                    }
                    if (coord.Value != 180)
                        ChangeBlocksPosition(face_order[post_index], block_toChange, coord);

                }
            }
        }
Esempio n. 26
0
 protected override Cube.Face NewFace( CubeFaceType type, Vector3 normal, Vector3 up, Direction rotation )
 {
     return new Face( this, type, normal, up, rotation );
 }
Esempio n. 27
0
 public Face( EditableCube cube, CubeFaceType type, Vector3 normal, Vector3 up, Direction orientation )
     : base(cube, type, normal, up, orientation)
 {
 }
 public RotateFaceMovement(CubeFaceColor color, CubeFaceType type)
 {
     Face = color;
     PositionFace = type;
 }