/// <summary>
 /// Left button up
 /// </summary>
 /// <param name="sender">Sender</param>
 /// <param name="e">Event arguments</param>
 private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     // if we are in rotate full cube, reset rotation
     if (RotationActive == RotationActive.Cube)
     {
         RotationActive = RotationActive.Idle;
         Cursor         = Cursors.Arrow;
     }
     return;
 }
        /// <summary>
        /// User pressed on mouse's left button
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event arguments</param>
        private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // ignore if rotation lock is on
            if (RotationLock)
            {
                return;
            }

            // mouse current position
            Point MousePosition = e.GetPosition(CubeViewPort3D);

            // user is not setting colors

            // clear hit list if rotation is idle or full cube
            if (RotationActive != RotationActive.Face)
            {
                HitList.Clear();
            }

            // hit test for current position
            HitTest(MousePosition);

            // hit list is empty
            if (HitList.Count == 0)
            {
                // save position
                LastMousePosition = MousePosition;

                // set rotation active to full cube rotation
                Cursor         = Cursors.SizeAll;
                RotationActive = RotationActive.Cube;
            }

            // there is one entry in hit list
            else if (HitList.Count == 1 && RotationActive != RotationActive.Face)
            {
                // set rotation active to one face rotation
                RotationActive = RotationActive.Face;
                Cursor         = Cursors.Hand;
            }

            // rotate one face by mouse action
            else
            {
                RotationActive = RotationActive.Idle;
                Cursor         = Cursors.Arrow;
                RotateByMouse();
            }
            return;
        }
        /// <summary>
        /// Reset to startup conditions
        /// </summary>
        private void Reset()
        {
            // trace file
#if DEBUG
            Trace.Write("Reset");
#endif

            // create Viewport3D and add it to CubeGrid parent
            CubeViewPort3D = new Viewport3D()
            {
                //Name = "mainViewport",
                ClipToBounds = true
            };
            CubeGrid.Children.Clear();
            CubeGrid.Children.Add(CubeViewPort3D);

            // create ModelVisual3D and add it to Viewport3D
            ModelVisual3D ModelVisual = new ModelVisual3D();
            CubeViewPort3D.Children.Add(ModelVisual);

            // create Model3DGroup with white ambiant light and attach it to ModelViual
            Model3DGroup ModelGroup = new Model3DGroup();
            ModelGroup.Children.Add(new AmbientLight(Colors.White));
            ModelVisual.Content = ModelGroup;

            // create our rubik's cube and attach it to ViewPort
            RubiksCube3D = new Cube3D();
            CubeViewPort3D.Children.Add(RubiksCube3D);

            // camera position relative to the cube
            // camera is looking directly to the cube
            double PosZ = Cube3D.CameraDistance * Math.Sin(Cube3D.CameraUpAngle);
            double Temp = Cube3D.CameraDistance * Math.Cos(Cube3D.CameraUpAngle);
            double PosX = Temp * Math.Sin(Cube3D.CameraRightAngle);
            double PosY = Temp * Math.Cos(Cube3D.CameraRightAngle);

            // create camera and attach it to ViewPort
            CubeViewPort3D.Camera = new PerspectiveCamera(new Point3D(PosX, -PosY, PosZ),
                                                          new Vector3D(-PosX, PosY, -PosZ), new Vector3D(0, 0, 1), Cube3D.CameraViewAngle);

            // full cube motion transformation group allows the program to
            // rotate the whole cube in any direction
            Transform3DGroup FullCubeMotion = new Transform3DGroup();
            RubiksCube3D.Transform = FullCubeMotion;
            FullCubeZRotation      = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0);
            FullCubeMotion.Children.Add(new RotateTransform3D(FullCubeZRotation));
            FullCubeXRotation = new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0);
            FullCubeMotion.Children.Add(new RotateTransform3D(FullCubeXRotation));
            FullCubeYRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
            FullCubeMotion.Children.Add(new RotateTransform3D(FullCubeYRotation));

            // list of active solution steps
            NextMoves = new List <int>();

            // list of saved moves to be used by undo button
            PastMoves = new List <int>();

            // type of rotation that is active
            RotationActive = RotationActive.Idle;

            // mouse left button hit list
            HitList      = new List <BlockFace3D>();
            RotationLock = false;

            // current top and front face color
            TopFaceColor   = -1;
            FrontFaceColor = -1;
            SetUpAndFrontFace(true, 2, 0);

            // clear information labels
            ResetInfoLabels(false);
            return;
        }
예제 #4
0
        /// <summary>
        /// User pressed on mouse's left button
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event arguments</param>
        private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // ignore if rotation lock is on
            if (RotationLock)
            {
                return;
            }

            // mouse current position
            Point MousePosition = e.GetPosition(CubeViewPort3D);

            // user is not setting colors
            if (!UserCubeActive)
            {
                // clear hit list if rotation is idle or full cube
                if (RotationActive != RotationActive.Face)
                {
                    HitList.Clear();
                }

                // hit test for current position
                HitTest(MousePosition);

                // hit list is empty
                if (HitList.Count == 0)
                {
                    // save position
                    LastMousePosition = MousePosition;

                    // set rotation active to full cube rotation
                    Cursor         = Cursors.SizeAll;
                    RotationActive = RotationActive.Cube;
                }

                // there is one entry in hit list
                else if (HitList.Count == 1 && RotationActive != RotationActive.Face)
                {
                    // set rotation active to one face rotation
                    RotationActive = RotationActive.Face;
                    Cursor         = Cursors.Hand;
                }

                // rotate one face by mouse action
                else
                {
                    RotationActive = RotationActive.Idle;
                    Cursor         = Cursors.Arrow;
                    RotateByMouse();
                }
            }

            // user is painting the cube to agree with his/her cube
            else
            {
                HitList.Clear();
                HitTest(MousePosition);
                if (HitList.Count > 0)
                {
                    int FaceNo = HitList[HitList.Count - 1].FaceNo;
                    if (FaceNo >= 0 && FaceNo < Cube.MovableFaces)
                    {
                        // save color
                        UserColorArray[FaceNo] = UserCubeSelection;

                        // change color of block face
                        RubiksCube3D.MovableFaceArray[FaceNo].ChangeColor(UserCubeSelection);
                    }
                }
            }
            return;
        }