예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //creates the floor surface
            for (int j = -15; j < 15; j++)
            {
                for (int i = -15; i < 15; i++)
                {
                    Polygon3D aSide = new Polygon3D(this.ClientSize, null);
                    aSide.AddPoint(new Point3D(i * size, 0, j * size));
                    aSide.AddPoint(new Point3D(i * size, 0, j * size + size));
                    aSide.AddPoint(new Point3D(i * size + size, 0, j * size + size));
                    aSide.AddPoint(new Point3D(i * size + size, 0, j * size));
                    aSide.BackColor  = Color.Transparent;
                    aSide.FrontColor = Color.Transparent;

                    floor.Add(aSide);
                }
            }
            //foreach (Cube cube in cubes)
            //    Global.AllSides.AddRange(cube.Sides);

            Global.AllSides.AddRange(floor);

            axis.Add(new Line3D(new Point3D(-25, 0, 0), new Point3D(1000, 0, 0)));
            axis.Add(new Line3D(new Point3D(0, 25, 0), new Point3D(0, -1000, 0)));
            axis.Add(new Line3D(new Point3D(0, 0, -25), new Point3D(0, 0, 1000)));
        }
예제 #2
0
 public bool Contains(Polygon3D face)
 {
     foreach (Polygon3D s in sides)
     {
         if (s == face)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
        private void CheckClick(Point2D mouseLocation, bool leftClick)
        {
            //reorders sides to check the face you see on top as first
            Global.AllSides.Sort();
            Global.AllSides.Reverse();
            Polygon3D flag = new Polygon3D(this.ClientSize, null);

            foreach (Polygon3D side in Global.AllSides)
            {
                if (side.Contains(mouseLocation))
                {
                    //if left clicking on a face
                    if (leftClick)
                    {
                        //adds a new cube
                        Cube a = side.MakeNewCube(size, cubes, floor);
                        cubes.Add(a);
                        Global.AllSides.AddRange(a.Sides);
                        break;
                    }
                    //if right clicking on a face
                    else
                    {
                        //checks if shift is held and selection box isn't being drawn
                        if (shift && (mouseDown - mouseLastPos).Magnitude < 5)
                        {
                            flag = side;
                        }
                        break;
                    }
                }
            }
            flag.DeleteCube(cubes, floor);
            //reorders sides to draw
            Global.AllSides.Sort();
        }
예제 #4
0
        /// <summary>
        /// Creates the 6 faces of the cube
        /// </summary>
        private void CreateFaces()
        {
            Polygon3D aFace = new Polygon3D(clientSize, this);

            //front face
            aFace.AddPoint(new Point3D(min.X, min.Y, max.Z));
            aFace.AddPoint(new Point3D(max.X, min.Y, max.Z));
            aFace.AddPoint(new Point3D(max.X, max.Y, max.Z));
            aFace.AddPoint(new Point3D(min.X, max.Y, max.Z));
            aFace.FrontBrush = new SolidBrush(outside);
            aFace.BackBrush  = new SolidBrush(inside);
            sides.Add(aFace);

            //back face
            aFace = new Polygon3D(clientSize, this);
            aFace.AddPoint(new Point3D(max.X, min.Y, min.Z));
            aFace.AddPoint(new Point3D(min.X, min.Y, min.Z));
            aFace.AddPoint(new Point3D(min.X, max.Y, min.Z));
            aFace.AddPoint(new Point3D(max.X, max.Y, min.Z));
            aFace.FrontBrush = new SolidBrush(outside);
            aFace.BackBrush  = new SolidBrush(inside);
            sides.Add(aFace);

            //right face
            aFace = new Polygon3D(clientSize, this);
            aFace.AddPoint(new Point3D(max.X, min.Y, max.Z));
            aFace.AddPoint(new Point3D(max.X, min.Y, min.Z));
            aFace.AddPoint(new Point3D(max.X, max.Y, min.Z));
            aFace.AddPoint(new Point3D(max.X, max.Y, max.Z));
            aFace.FrontBrush = new SolidBrush(outside);
            aFace.BackBrush  = new SolidBrush(inside);
            sides.Add(aFace);

            //left face
            aFace = new Polygon3D(clientSize, this);
            aFace.AddPoint(new Point3D(min.X, min.Y, min.Z));
            aFace.AddPoint(new Point3D(min.X, min.Y, max.Z));
            aFace.AddPoint(new Point3D(min.X, max.Y, max.Z));
            aFace.AddPoint(new Point3D(min.X, max.Y, min.Z));
            aFace.FrontBrush = new SolidBrush(outside);
            aFace.BackBrush  = new SolidBrush(inside);
            sides.Add(aFace);

            //top face
            aFace = new Polygon3D(clientSize, this);
            aFace.AddPoint(new Point3D(min.X, min.Y, max.Z));
            aFace.AddPoint(new Point3D(min.X, min.Y, min.Z));
            aFace.AddPoint(new Point3D(max.X, min.Y, min.Z));
            aFace.AddPoint(new Point3D(max.X, min.Y, max.Z));
            aFace.FrontBrush = new SolidBrush(outside);
            aFace.BackBrush  = new SolidBrush(inside);
            sides.Add(aFace);

            //bottom face
            aFace = new Polygon3D(clientSize, this);
            aFace.AddPoint(new Point3D(max.X, max.Y, max.Z));
            aFace.AddPoint(new Point3D(max.X, max.Y, min.Z));
            aFace.AddPoint(new Point3D(min.X, max.Y, min.Z));
            aFace.AddPoint(new Point3D(min.X, max.Y, max.Z));
            aFace.FrontBrush = new SolidBrush(outside);
            aFace.BackBrush  = new SolidBrush(inside);
            sides.Add(aFace);
        }
예제 #5
0
        public Cube(int x = 100, int y = 100, int z = 100)
        {
            //back
            Polygon3D polygon = new Polygon3D();

            polygon.Add(new Point3D(-x, -y, -z));
            polygon.Add(new Point3D(x, -y, -z));
            polygon.Add(new Point3D(x, y, -z));
            polygon.Add(new Point3D(-x, y, -z));
            polygon.FGBrush = Brushes.Red;
            polygon.BGBrush = Brushes.Blue;
            polygon.Pen     = Pens.CornflowerBlue;
            polygons.Add(polygon);
            //left
            polygon = new Polygon3D();
            polygon.Add(new Point3D(-x, -y, -z));
            polygon.Add(new Point3D(-x, y, -z));
            polygon.Add(new Point3D(-x, y, z));
            polygon.Add(new Point3D(-x, -y, z));
            polygon.FGBrush = Brushes.Red;
            polygon.BGBrush = Brushes.Blue;
            polygon.Pen     = Pens.CornflowerBlue;
            polygons.Add(polygon);
            //right
            polygon = new Polygon3D();
            polygon.Add(new Point3D(x, y, -z));
            polygon.Add(new Point3D(x, -y, -z));
            polygon.Add(new Point3D(x, -y, z));
            polygon.Add(new Point3D(x, y, z));
            polygon.FGBrush = Brushes.Red;
            polygon.BGBrush = Brushes.Blue;
            polygon.Pen     = Pens.CornflowerBlue;
            polygons.Add(polygon);
            //front
            polygon = new Polygon3D();
            polygon.Add(new Point3D(x, -y, z));
            polygon.Add(new Point3D(-x, -y, z));
            polygon.Add(new Point3D(-x, y, z));
            polygon.Add(new Point3D(x, y, z));
            polygon.FGBrush = Brushes.Red;
            polygon.BGBrush = Brushes.Blue;
            polygon.Pen     = Pens.CornflowerBlue;
            polygons.Add(polygon);

            // bottom
            polygon = new Polygon3D();
            polygon.Add(new Point3D(-x, y, -z));
            polygon.Add(new Point3D(x, y, -z));
            polygon.Add(new Point3D(x, y, z));
            polygon.Add(new Point3D(-x, y, z));
            polygon.FGBrush = Brushes.Red;
            polygon.BGBrush = Brushes.Blue;
            polygon.Pen     = Pens.CornflowerBlue;
            polygons.Add(polygon);

            // top
            polygon = new Polygon3D();
            polygon.Add(new Point3D(x, -y, -z));
            polygon.Add(new Point3D(-x, -y, -z));
            polygon.Add(new Point3D(-x, -y, z));
            polygon.Add(new Point3D(x, -y, z));
            polygon.FGBrush = Brushes.Red;
            polygon.BGBrush = Brushes.Blue;
            polygon.Pen     = Pens.CornflowerBlue;
            polygons.Add(polygon);
        }