Пример #1
0
        public static void Draw(this RubikCube2 cube, Graphics g, Camera cam)
        {
            var pts2d = cam.GetProjection(cube.Points);//.Select<Point, PointF>(x => new PointF((float)(x.X), (float)(x.Y))).ToArray();

            Point[][] face = new Point[6][];
            face[0] = new Point[] { pts2d[0], pts2d[1], pts2d[2], pts2d[3] };
            face[1] = new Point[] { pts2d[5], pts2d[1], pts2d[0], pts2d[4] };
            face[2] = new Point[] { pts2d[1], pts2d[5], pts2d[6], pts2d[2] };
            face[3] = new Point[] { pts2d[2], pts2d[6], pts2d[7], pts2d[3] };
            face[4] = new Point[] { pts2d[3], pts2d[7], pts2d[4], pts2d[0] };
            face[5] = new Point[] { pts2d[4], pts2d[7], pts2d[6], pts2d[5] };

            for (int i = 0; i < 6; i++)
            {
                bool isout = false;
                for (int j = 0; j < 4; j++)
                {
                    if (face[i][j] == new Point(float.MaxValue, float.MaxValue))
                    {
                        isout = true;
                        continue;
                    }
                }
                if (!isout)
                {
                    if (cube.DrawingLine)
                        g.DrawPolygon(new Pen(Color.Blue, 2.0f), FromD3Points(face[i]));
                    if (Vector.IsClockwise(face[i][0], face[i][1], face[i][2])) // the face can be seen by camera
                    {
                        if (cube.FillingFace)
                            g.FillPolygon(new SolidBrush(Color.FromArgb((int)(cube.FaceColors[i]))), FromD3Points(face[i]));
                    }
                }
            }
        }
Пример #2
0
 public void Draw(Graphics g, Camera cam)
 {
     foreach (var cuboid in cuboids)
     {
         cuboid.Draw(g, cam);
     }
 }
Пример #3
0
 private void button14_Click(object sender, EventArgs e)
 {
     cub = new Cuboid(150, 150, 150);
     cam = new Camera();
     cub.Center = new Point3D(400, 240, 0);
     cam.Location = new Point3D(400, 240, -500);
     ReDraw();
     i = 0;
     bmp = new Bitmap[6];
     labelMx.Text = cam.Location.X.ToString();
     labelMy.Text = cam.Location.Y.ToString();
     labelMz.Text = cam.Location.Z.ToString();
     labelCx.Text = cub.Center.X.ToString();
     labelCy.Text = cub.Center.Y.ToString();
     labelCz.Text = cub.Center.Z.ToString();
     cameraX = 0; cameraY = 0; cameraZ = 0; cubeX = 0; cubeY = 0; cubeZ = 0;
     labelCrX.Text = "0";
     labelCrY.Text = "0";
     labelCrZ.Text = "0";
     labelMrX.Text = "0";
     labelMrY.Text = "0";
     labelMrZ.Text = "0";
 }