Esempio n. 1
0
        public RubikManager.PositionSpec Render(Graphics g, Rectangle screen, double scale, Point mousePos)
        {
            RubikManager.PositionSpec result = new RubikManager.PositionSpec()
            {
                cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
            };
            cubesRender.Clear();
            cubesRender     = genCubesRotated(false);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            IEnumerable <Face3D> facesProjected = cubesRender.Select(c => c.Project(screen.Width, screen.Height, 100, 4, scale).Faces).Aggregate((a, b) => a.Concat(b));

            facesProjected = facesProjected.OrderBy(p => p.Edges.ElementAt(0).Z).ToArray();
            foreach (Face3D face in facesProjected.Reverse())
            {
                PointF[]     parr = face.Edges.Select(p => new PointF((float)p.X, (float)p.Y)).ToArray();
                GraphicsPath gp   = new GraphicsPath();
                gp.AddPolygon(parr);
                double fak = ((Math.Sin((double)Environment.TickCount / (double)200) + 1) / 4) + 0.75;
                if (gp.IsVisible(mousePos))
                {
                    result = new RubikManager.PositionSpec()
                    {
                        cubePos = face.MasterPosition, facePos = face.Position
                    }
                }
                ;
                if (face.Selection.HasFlag(Face3D.SelectionMode.Second))
                {
                    g.FillPolygon(new HatchBrush(HatchStyle.Percent75, Color.Black, face.Color), parr);
                }
                else if (face.Selection.HasFlag(Face3D.SelectionMode.NotPossible))
                {
                    g.FillPolygon(new SolidBrush(Color.FromArgb(face.Color.A, (int)(face.Color.R * 0.15), (int)(face.Color.G * 0.15), (int)(face.Color.B * 0.15))), parr);
                }
                else if (face.Selection.HasFlag(Face3D.SelectionMode.First))
                {
                    g.FillPolygon(new HatchBrush(HatchStyle.Percent30, Color.Black, face.Color), parr);
                }
                else if (face.Selection.HasFlag(Face3D.SelectionMode.Possible))
                {
                    g.FillPolygon(new SolidBrush(Color.FromArgb(face.Color.A, (int)(Math.Min(face.Color.R * fak, 255)), (int)(Math.Min(face.Color.G * fak, 255)), (int)(Math.Min(face.Color.B * fak, 255)))), parr);
                }
                else
                {
                    g.FillPolygon(new SolidBrush(face.Color), parr);
                }
                g.DrawPolygon(Pens.Black, parr);
            }
            return(result);
        }
    }
Esempio n. 2
0
 private void groupBox1_EnabledChanged(object sender, EventArgs e)
 {
     if (!groupBox1.Enabled)
     {
         rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
         oldSelection = new RubikManager.PositionSpec()
         {
             cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
         };
         currentSelection = new RubikManager.PositionSpec()
         {
             cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
         };
     }
 }
Esempio n. 3
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Delete)
     {
         rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
         oldSelection = new RubikManager.PositionSpec()
         {
             cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
         };
         currentSelection = new RubikManager.PositionSpec()
         {
             cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
         };
     }
 }
Esempio n. 4
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Rectangle r      = new Rectangle(0, 0, this.ClientRectangle.Width - ((groupBox1.Visible)? groupBox1.Width:0), this.ClientRectangle.Height - ((statusStrip1.Visible)? statusStrip1.Height:0) - ((statusStrip1.Visible)? statusStrip2.Height:0) + menuStrip1.Height);
            int       min    = Math.Min(r.Height, r.Width);
            double    factor = 3 * ((double)min / (double)400);

            if (r.Width > r.Height)
            {
                r.X = (r.Width - r.Height) / 2;
            }
            else if (r.Height > r.Width)
            {
                r.Y = (r.Height - r.Width) / 2;
            }
            RubikManager.PositionSpec selectedPos = rubikManager.Render(e.Graphics, r, factor, PointToClient(Cursor.Position));
            rubikManager.setFaceSelection(Face3D.SelectionMode.None);
            rubikManager.setFaceSelection(oldSelection.cubePos, oldSelection.facePos, Face3D.SelectionMode.Second);
            rubikManager.setFaceSelection(selectedPos.cubePos, selectedPos.facePos, Face3D.SelectionMode.First);
            currentSelection           = selectedPos;
            toolStripStatusLabel2.Text = "[" + selectedPos.cubePos.ToString() + "] | " + selectedPos.facePos.ToString();
        }
Esempio n. 5
0
 private void Form1_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Left)
     {
         if (oldSelection.cubePos == Cube3D.RubikPosition.None || oldSelection.facePos == Face3D.FacePosition.None)
         {
             if (currentSelection.cubePos == Cube3D.RubikPosition.None || currentSelection.facePos == Face3D.FacePosition.None)
             {
                 rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                 oldSelection = new RubikManager.PositionSpec()
                 {
                     cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
                 };
                 currentSelection = new RubikManager.PositionSpec()
                 {
                     cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
                 };
             }
             else
             {
                 if (!Cube3D.isCorner(currentSelection.cubePos))
                 {
                     oldSelection = currentSelection;
                     rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f =>
                     {
                         if (currentSelection.cubePos != c.Position && !Cube3D.isCenter(c.Position) && currentSelection.facePos == f.Position)
                         {
                             Cube3D.RubikPosition assocLayer  = Face3D.layerAssocToFace(currentSelection.facePos);
                             Cube3D.RubikPosition commonLayer = Cube3D.getCommonLayer(currentSelection.cubePos, c.Position, assocLayer);
                             if (commonLayer != Cube3D.RubikPosition.None && c.Position.HasFlag(commonLayer))
                             {
                                 f.Selection |= Face3D.SelectionMode.Possible;
                             }
                             else
                             {
                                 f.Selection |= Face3D.SelectionMode.NotPossible;
                             }
                         }
                         else
                         {
                             f.Selection |= Face3D.SelectionMode.NotPossible;
                         }
                     }));
                     toolStripStatusLabel1.Text = "First selection: [" + currentSelection.cubePos.ToString() + "] | " + currentSelection.facePos.ToString();;
                 }
                 else
                 {
                     rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                     toolStripStatusLabel1.Text = "Error: Invalid first selection, must not be a corner";
                 }
             }
         }
         else
         {
             if (currentSelection.cubePos == Cube3D.RubikPosition.None || currentSelection.facePos == Face3D.FacePosition.None)
             {
                 toolStripStatusLabel1.Text = "Ready";
             }
             else
             {
                 if (currentSelection.cubePos != oldSelection.cubePos)
                 {
                     if (!Cube3D.isCenter(currentSelection.cubePos))
                     {
                         if (oldSelection.facePos == currentSelection.facePos)
                         {
                             Cube3D.RubikPosition assocLayer  = Face3D.layerAssocToFace(oldSelection.facePos);
                             Cube3D.RubikPosition commonLayer = Cube3D.getCommonLayer(oldSelection.cubePos, currentSelection.cubePos, assocLayer);
                             Boolean direction = true;
                             if (commonLayer == Cube3D.RubikPosition.TopLayer || commonLayer == Cube3D.RubikPosition.MiddleLayer || commonLayer == Cube3D.RubikPosition.BottomLayer)
                             {
                                 if (((oldSelection.facePos == Face3D.FacePosition.Front) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.LeftSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Right) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.FrontSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Back) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.RightSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Left) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.BackSlice)))
                                 {
                                     direction = false;
                                 }
                             }
                             if (commonLayer == Cube3D.RubikPosition.LeftSlice || commonLayer == Cube3D.RubikPosition.MiddleSlice_Sides || commonLayer == Cube3D.RubikPosition.RightSlice)
                             {
                                 if (((oldSelection.facePos == Face3D.FacePosition.Top) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.FrontSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Front) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.BottomLayer)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Bottom) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.BackSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Back) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.TopLayer)))
                                 {
                                     direction = false;
                                 }
                             }
                             if (commonLayer == Cube3D.RubikPosition.BackSlice || commonLayer == Cube3D.RubikPosition.MiddleSlice || commonLayer == Cube3D.RubikPosition.FrontSlice)
                             {
                                 if (((oldSelection.facePos == Face3D.FacePosition.Top) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.RightSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Right) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.BottomLayer)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Bottom) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.LeftSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Left) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.TopLayer)))
                                 {
                                     direction = false;
                                 }
                             }
                             if (commonLayer != Cube3D.RubikPosition.None)
                             {
                                 if (groupBox1.Enabled)
                                 {
                                     groupBox1.Enabled = false;
                                     rotationTicks     = 25;
                                     rubikManager.Rotate90(commonLayer, direction, rotationTicks);
                                     comboBox1.Text             = commonLayer.ToString();
                                     toolStripStatusLabel1.Text = "Rotating " + commonLayer.ToString() + " " + ((direction) ? "Clockwise" : "Counter-Clockwise");
                                 }
                             }
                             else
                             {
                                 toolStripStatusLabel1.Text = "Error: Invalid second selection, does not specify distinct layer";
                             }
                         }
                         else
                         {
                             toolStripStatusLabel1.Text = "Error: Invalid second selection, must match orientation of first selection";
                         }
                     }
                     else
                     {
                         toolStripStatusLabel1.Text = "Error: Invalid second selection, must not be a center";
                     }
                 }
                 else
                 {
                     toolStripStatusLabel1.Text = "Error: Invalid second selection, must not be first selection";
                 }
             }
             rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
             oldSelection = new RubikManager.PositionSpec()
             {
                 cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
             };
             currentSelection = new RubikManager.PositionSpec()
             {
                 cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
             };
         }
     }
 }