Exemple #1
0
 private void SqrPyramid_Click(object sender, EventArgs e)
 {
     points    = new _3DPoint[5];
     points[0] = new _3DPoint(size, size, -size);
     points[1] = new _3DPoint(-size, size, -size);
     points[2] = new _3DPoint(size, size, size);
     points[3] = new _3DPoint(-size, size, size);
     points[4] = new _3DPoint(0, -size, 0);
     ShapeNum  = 2;
 }
Exemple #2
0
        //Converts 3D Point to a float array
        float[,] VecToMatrix(_3DPoint v)
        {
            float[,] m = new float[3, 1];

            m[0, 0] = v.X;
            m[1, 0] = v.Y;
            m[2, 0] = v.Z;

            return(m);
        }
Exemple #3
0
 private void Octahedron_Click(object sender, EventArgs e)
 {
     points    = new _3DPoint[6];
     points[0] = new _3DPoint(size, 0, -size);
     points[1] = new _3DPoint(-size, 0, -size);
     points[2] = new _3DPoint(size, 0, size);
     points[3] = new _3DPoint(-size, 0, size);
     points[4] = new _3DPoint(0, -size, 0);
     points[5] = new _3DPoint(0, size, 0);
     ShapeNum  = 4;
 }
Exemple #4
0
 private void CubeButton_Click(object sender, EventArgs e)
 {
     points    = new _3DPoint[8];
     points[0] = new _3DPoint(-size, -size, -size);
     points[1] = new _3DPoint(size, -size, -size);
     points[2] = new _3DPoint(size, size, -size);
     points[3] = new _3DPoint(-size, size, -size);
     points[4] = new _3DPoint(-size, -size, size);
     points[5] = new _3DPoint(size, -size, size);
     points[6] = new _3DPoint(size, size, size);
     points[7] = new _3DPoint(-size, size, size);
     ShapeNum  = 0;
 }
Exemple #5
0
        //Converts Float array to a 3D Point
        _3DPoint MatrixToVec(float[,] m)
        {
            _3DPoint v = new _3DPoint();

            v.X = m[0, 0];
            v.Y = m[1, 0];

            if (m.GetLength(0) > 2)
            {
                v.Z = m[2, 0];
            }

            return(v);
        }
Exemple #6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            _resWidth  = 800;
            _resHeight = 600;

            Show();
            Focus();

            _gr         = CreateGraphics();
            _backBuffer = new Bitmap(_resWidth, _resHeight);
            points      = new _3DPoint[8];

            points[0] = new _3DPoint(-size, -size, -size);
            points[1] = new _3DPoint(size, -size, -size);
            points[2] = new _3DPoint(size, size, -size);
            points[3] = new _3DPoint(-size, size, -size);
            points[4] = new _3DPoint(-size, -size, size);
            points[5] = new _3DPoint(size, -size, size);
            points[6] = new _3DPoint(size, size, size);
            points[7] = new _3DPoint(-size, size, size);

            DrawLoop();
        }
Exemple #7
0
        private void PyramidButton_Click(object sender, EventArgs e)
        {
            points    = new _3DPoint[4];
            points[0] = new _3DPoint(
                ((8 / 9) * (8 / 9)) * size,
                0,
                -((1 / 3) * size)
                );

            points[1] = new _3DPoint(
                -(((2 / 9) * (2 / 9)) * size),
                ((2 / 3) * (2 / 3)) * size,
                -((1 / 3) * size)
                );

            points[2] = new _3DPoint(
                -(((2 / 9) * (2 / 9)) * size),
                -(((2 / 3) * (2 / 3)) * size),
                -((1 / 3) * size)
                );

            points[3] = new _3DPoint(0, 0, size);
            ShapeNum  = 1;
        }
Exemple #8
0
        void DrawImported()
        {
            float[,] rotationX =
            {
                { 1,                                  0,                                   0 },
                { 0, Convert.ToSingle(Math.Cos(AngleX)), Convert.ToSingle(-Math.Sin(AngleX)) },
                { 0, Convert.ToSingle(Math.Sin(AngleX)), Convert.ToSingle(Math.Cos(AngleX))  }
            };
            float[,] rotationAutoX =
            {
                { 1,                                      0,                                       0 },
                { 0, Convert.ToSingle(Math.Cos(AutoAngleX)), Convert.ToSingle(-Math.Sin(AutoAngleX)) },
                { 0, Convert.ToSingle(Math.Sin(AutoAngleX)), Convert.ToSingle(Math.Cos(AutoAngleX))  }
            };

            float[,] rotationZ =
            {
                { Convert.ToSingle(Math.Cos(AngleZ)), Convert.ToSingle(-Math.Sin(AngleZ)), 0 },
                { Convert.ToSingle(Math.Sin(AngleZ)), Convert.ToSingle(Math.Cos(AngleZ)),  0 },
                {                                  0,                                   0, 1 }
            };
            float[,] rotationAutoZ =
            {
                { Convert.ToSingle(Math.Cos(AutoAngleZ)), Convert.ToSingle(-Math.Sin(AutoAngleZ)), 0 },
                { Convert.ToSingle(Math.Sin(AutoAngleZ)), Convert.ToSingle(Math.Cos(AutoAngleZ)),  0 },
                {                                      0,                                       0, 1 }
            };

            float[,] rotationY =
            {
                { Convert.ToSingle(Math.Cos(AngleY)), 0, Convert.ToSingle(-Math.Sin(AngleY)) },
                {                                  0, 1,                                   0 },
                { Convert.ToSingle(Math.Sin(AngleY)), 0, Convert.ToSingle(Math.Cos(AngleY))  }
            };
            float[,] rotationAutoY =
            {
                { Convert.ToSingle(Math.Cos(AutoAngleY)), 0, Convert.ToSingle(-Math.Sin(AutoAngleY)) },
                {                                      0, 1,                                       0 },
                { Convert.ToSingle(Math.Sin(AutoAngleY)), 0, Convert.ToSingle(Math.Cos(AutoAngleY))  }
            };

            _3DPoint[] Projected = new _3DPoint[ImportedVertices.Count];

            int index = 0;

            foreach (var i in ImportedVertices)
            {
                _3DPoint rotated = i;

                if (AutoXTick.Checked)
                {
                    rotated = Matrix.MatrixMultiply(rotationAutoX, rotated);
                    try
                    {
                        if (XNum.Text == "")
                        {
                        }
                        else
                        {
                            AutoAngleX += Convert.ToDouble(XNum.Text) / 1000000;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (AutoYTick.Checked)
                {
                    rotated = Matrix.MatrixMultiply(rotationAutoY, rotated);
                    try
                    {
                        if (YNum.Text == "")
                        {
                        }
                        else
                        {
                            AutoAngleY += Convert.ToDouble(YNum.Text) / 1000000;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (AutoZTick.Checked)
                {
                    rotated = Matrix.MatrixMultiply(rotationAutoZ, rotated);
                    try
                    {
                        if (ZNum.Text == "")
                        {
                        }
                        else
                        {
                            AutoAngleZ += Convert.ToDouble(ZNum.Text) / 1000000;
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }

                rotated = Matrix.MatrixMultiply(rotationY, rotated);
                rotated = Matrix.MatrixMultiply(rotationX, rotated);
                rotated = Matrix.MatrixMultiply(rotationZ, rotated);
                _3DPoint projected2D = Matrix.MatrixMultiply(_projection, rotated);

                Projected[index] = projected2D;
                index++;
            }

            for (int i = 0; i < ListOfFaces.Count;)
            {
                for (int j = 0; j < ListOfFaces[i].Count;)
                {
                    if (ListOfFaces[i][j] == ListOfFaces[i][ListOfFaces[i].Count - 1])
                    {
                        int PointA = Convert.ToInt16(ListOfFaces[i][j]);
                        int PointB = Convert.ToInt16(ListOfFaces[i][0]);
                        ImportedConnectPoints(PointA, PointB, Projected, 0);
                    }
                    else
                    {
                        int PointA = Convert.ToInt16(ListOfFaces[i][j]);
                        int PointB = Convert.ToInt16(ListOfFaces[i][j + 1]);
                        ImportedConnectPoints(PointA, PointB, Projected, 0);
                    }

                    j++;
                }

                i++;
            }
        }
Exemple #9
0
        void DrawOctohedron()
        {
            float[,] rotationX =
            {
                { 1,                                  0,                                   0 },
                { 0, Convert.ToSingle(Math.Cos(AngleX)), Convert.ToSingle(-Math.Sin(AngleX)) },
                { 0, Convert.ToSingle(Math.Sin(AngleX)), Convert.ToSingle(Math.Cos(AngleX))  }
            };
            float[,] rotationAutoX =
            {
                { 1,                                      0,                                       0 },
                { 0, Convert.ToSingle(Math.Cos(AutoAngleX)), Convert.ToSingle(-Math.Sin(AutoAngleX)) },
                { 0, Convert.ToSingle(Math.Sin(AutoAngleX)), Convert.ToSingle(Math.Cos(AutoAngleX))  }
            };

            float[,] rotationZ =
            {
                { Convert.ToSingle(Math.Cos(AngleZ)), Convert.ToSingle(-Math.Sin(AngleZ)), 0 },
                { Convert.ToSingle(Math.Sin(AngleZ)), Convert.ToSingle(Math.Cos(AngleZ)),  0 },
                {                                  0,                                   0, 1 }
            };
            float[,] rotationAutoZ =
            {
                { Convert.ToSingle(Math.Cos(AutoAngleZ)), Convert.ToSingle(-Math.Sin(AutoAngleZ)), 0 },
                { Convert.ToSingle(Math.Sin(AutoAngleZ)), Convert.ToSingle(Math.Cos(AutoAngleZ)),  0 },
                {                                      0,                                       0, 1 }
            };

            float[,] rotationY =
            {
                { Convert.ToSingle(Math.Cos(AngleY)), 0, Convert.ToSingle(-Math.Sin(AngleY)) },
                {                                  0, 1,                                   0 },
                { Convert.ToSingle(Math.Sin(AngleY)), 0, Convert.ToSingle(Math.Cos(AngleY))  }
            };
            float[,] rotationAutoY =
            {
                { Convert.ToSingle(Math.Cos(AutoAngleY)), 0, Convert.ToSingle(-Math.Sin(AutoAngleY)) },
                {                                      0, 1,                                       0 },
                { Convert.ToSingle(Math.Sin(AutoAngleY)), 0, Convert.ToSingle(Math.Cos(AutoAngleY))  }
            };

            _3DPoint[] Projected = new _3DPoint[6];

            int index = 0;

            foreach (var i in points)
            {
                _3DPoint rotated = i;

                if (AutoXTick.Checked)
                {
                    rotated = Matrix.MatrixMultiply(rotationAutoX, rotated);
                    try
                    {
                        AutoAngleX += Convert.ToDouble(XNum.Text) / 10000;
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (AutoYTick.Checked)
                {
                    rotated = Matrix.MatrixMultiply(rotationAutoY, rotated);
                    try
                    {
                        AutoAngleY += Convert.ToDouble(YNum.Text) / 10000;
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (AutoZTick.Checked)
                {
                    rotated = Matrix.MatrixMultiply(rotationAutoZ, rotated);
                    try
                    {
                        AutoAngleZ += Convert.ToDouble(ZNum.Text) / 10000;
                    }
                    catch (Exception e)
                    {
                    }
                }

                rotated = Matrix.MatrixMultiply(rotationY, rotated);
                rotated = Matrix.MatrixMultiply(rotationX, rotated);
                rotated = Matrix.MatrixMultiply(rotationZ, rotated);
                _3DPoint projected2D = Matrix.MatrixMultiply(_projection, rotated);

                Projected[index] = projected2D;
                index++;
            }

            /*
             * int PickColour = 0;
             * for (int i = 0; i < 4; i++)
             * {
             *  PickColour++;
             *  ConnectPoints(i, (i + 1) % 4, Projected, PickColour);
             *
             *  PickColour++;
             *  ConnectPoints(i + 4, ((i + 1) % 4) + 4, Projected, PickColour);
             *
             *  PickColour++;
             *  ConnectPoints(i, i + 4, Projected, PickColour);
             * }
             */


            ConnectPoints(0, 1, Projected, 0);
            ConnectPoints(1, 3, Projected, 0);
            ConnectPoints(3, 2, Projected, 0);
            ConnectPoints(2, 0, Projected, 0);

            ConnectPoints(0, 4, Projected, 0);
            ConnectPoints(1, 4, Projected, 0);
            ConnectPoints(2, 4, Projected, 0);
            ConnectPoints(3, 4, Projected, 0);

            ConnectPoints(0, 5, Projected, 0);
            ConnectPoints(1, 5, Projected, 0);
            ConnectPoints(2, 5, Projected, 0);
            ConnectPoints(3, 5, Projected, 0);
        }
Exemple #10
0
        void DrawDodechedron()
        {
            float[,] rotationX =
            {
                { 1,                                  0,                                   0 },
                { 0, Convert.ToSingle(Math.Cos(AngleX)), Convert.ToSingle(-Math.Sin(AngleX)) },
                { 0, Convert.ToSingle(Math.Sin(AngleX)), Convert.ToSingle(Math.Cos(AngleX))  }
            };
            float[,] rotationAutoX =
            {
                { 1,                                      0,                                       0 },
                { 0, Convert.ToSingle(Math.Cos(AutoAngleX)), Convert.ToSingle(-Math.Sin(AutoAngleX)) },
                { 0, Convert.ToSingle(Math.Sin(AutoAngleX)), Convert.ToSingle(Math.Cos(AutoAngleX))  }
            };

            float[,] rotationZ =
            {
                { Convert.ToSingle(Math.Cos(AngleZ)), Convert.ToSingle(-Math.Sin(AngleZ)), 0 },
                { Convert.ToSingle(Math.Sin(AngleZ)), Convert.ToSingle(Math.Cos(AngleZ)),  0 },
                {                                  0,                                   0, 1 }
            };
            float[,] rotationAutoZ =
            {
                { Convert.ToSingle(Math.Cos(AutoAngleZ)), Convert.ToSingle(-Math.Sin(AutoAngleZ)), 0 },
                { Convert.ToSingle(Math.Sin(AutoAngleZ)), Convert.ToSingle(Math.Cos(AutoAngleZ)),  0 },
                {                                      0,                                       0, 1 }
            };

            float[,] rotationY =
            {
                { Convert.ToSingle(Math.Cos(AngleY)), 0, Convert.ToSingle(-Math.Sin(AngleY)) },
                {                                  0, 1,                                   0 },
                { Convert.ToSingle(Math.Sin(AngleY)), 0, Convert.ToSingle(Math.Cos(AngleY))  }
            };
            float[,] rotationAutoY =
            {
                { Convert.ToSingle(Math.Cos(AutoAngleY)), 0, Convert.ToSingle(-Math.Sin(AutoAngleY)) },
                {                                      0, 1,                                       0 },
                { Convert.ToSingle(Math.Sin(AutoAngleY)), 0, Convert.ToSingle(Math.Cos(AutoAngleY))  }
            };

            _3DPoint[]      Projected = new _3DPoint[20];
            List <_3DPoint> Vertices  = MakeDodecahedron(size);

            int index = 0;

            foreach (var i in Vertices)
            {
                _3DPoint rotated = i;

                if (AutoXTick.Checked)
                {
                    rotated = Matrix.MatrixMultiply(rotationAutoX, rotated);
                    try
                    {
                        AutoAngleX += Convert.ToDouble(XNum.Text) / 10000;
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (AutoYTick.Checked)
                {
                    rotated = Matrix.MatrixMultiply(rotationAutoY, rotated);
                    try
                    {
                        AutoAngleY += Convert.ToDouble(YNum.Text) / 10000;
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (AutoZTick.Checked)
                {
                    rotated = Matrix.MatrixMultiply(rotationAutoZ, rotated);
                    try
                    {
                        AutoAngleZ += Convert.ToDouble(ZNum.Text) / 10000;
                    }
                    catch (Exception e)
                    {
                    }
                }

                rotated = Matrix.MatrixMultiply(rotationY, rotated);
                rotated = Matrix.MatrixMultiply(rotationX, rotated);
                rotated = Matrix.MatrixMultiply(rotationZ, rotated);
                _3DPoint projected2D = Matrix.MatrixMultiply(_projection, rotated);

                Projected[index] = projected2D;

                //_gr.DrawString(index.ToString(), Font, Brushes.Red, Projected[index].X, Projected[index].Y);

                index++;
            }

            /*
             * int PickColour = 0;
             * for (int i = 0; i < 4; i++)
             * {
             *  PickColour++;
             *  ConnectPoints(i, (i + 1) % 4, Projected, PickColour);
             *
             *  PickColour++;
             *  ConnectPoints(i + 4, ((i + 1) % 4) + 4, Projected, PickColour);
             *
             *  PickColour++;
             *  ConnectPoints(i, i + 4, Projected, PickColour);
             * }
             */

            ConnectPoints(17, 12, Projected, 0);
            ConnectPoints(12, 18, Projected, 0);
            ConnectPoints(18, 16, Projected, 0);
            ConnectPoints(16, 19, Projected, 0);
            ConnectPoints(19, 17, Projected, 0);

            ConnectPoints(2, 7, Projected, 0);
            ConnectPoints(7, 9, Projected, 0);
            ConnectPoints(9, 6, Projected, 0);
            ConnectPoints(6, 8, Projected, 0);
            ConnectPoints(8, 2, Projected, 0);

            ConnectPoints(11, 14, Projected, 0);
            ConnectPoints(14, 17, Projected, 0);
            ConnectPoints(17, 12, Projected, 0);
            ConnectPoints(12, 13, Projected, 0);
            ConnectPoints(13, 11, Projected, 0);

            ConnectPoints(14, 5, Projected, 0);
            ConnectPoints(5, 15, Projected, 0);
            ConnectPoints(15, 19, Projected, 0);
            ConnectPoints(19, 17, Projected, 0);
            ConnectPoints(17, 14, Projected, 0);

            ConnectPoints(15, 9, Projected, 0);
            ConnectPoints(9, 6, Projected, 0);
            ConnectPoints(6, 16, Projected, 0);
            ConnectPoints(16, 19, Projected, 0);
            ConnectPoints(19, 15, Projected, 0);

            ConnectPoints(3, 2, Projected, 0);
            ConnectPoints(4, 1, Projected, 0);
            ConnectPoints(13, 0, Projected, 0);
            ConnectPoints(0, 10, Projected, 0);
            ConnectPoints(10, 18, Projected, 0);

            ConnectPoints(10, 8, Projected, 0);
            ConnectPoints(0, 3, Projected, 0);
            ConnectPoints(3, 1, Projected, 0);
            ConnectPoints(1, 11, Projected, 0);
            ConnectPoints(7, 4, Projected, 0);

            ConnectPoints(4, 5, Projected, 0);
        }
Exemple #11
0
 public _3DPoint MatrixMultiply(float[,] a, _3DPoint b)
 {
     float[,] m = VecToMatrix(b);
     return(MatrixToVec(MatrixMultiply(a, m)));
 }