Exemple #1
0
 public Cone()
 {
     center        = new Point3();
     transtelation = 20;
 }
Exemple #2
0
 public Cylinder()
 {
     center        = new Point3();
     transtelation = 20;
 }
Exemple #3
0
        static public void DrawCone(Point3 center, float height, float radius1, float radius2, int transtelation, Color color, bool drawFaces = true, bool drawFrame = false)
        {
            MainWindow.gl.MatrixMode(OpenGL.GL_MODELVIEW);
            MainWindow.gl.PushMatrix();
            MainWindow.gl.Translate(center.x, center.y - height / 2, center.z + radius1);

            float division = 2 * (float)Math.PI / transtelation;

            POINTFLOAT p1 = new POINTFLOAT {
                x = radius1 * (float)Math.Cos(division), y = radius1 * (float)Math.Sin(division)
            };
            POINTFLOAT p2 = new POINTFLOAT {
                x = radius1 * (float)Math.Cos(division * 2), y = radius1 * (float)Math.Sin(division * 2)
            };
            float radius1Line  = (float)Math.Sqrt(Math.Pow(p2.x - p1.x, 2) + Math.Pow(p2.y - p1.y, 2));
            float transRadius1 = (float)Math.Sqrt(Math.Pow(radius1, 2) - Math.Pow(radius1Line / 2, 2));

            p1 = new POINTFLOAT {
                x = radius2 * (float)Math.Cos(division), y = radius2 * (float)Math.Sin(division)
            };
            p2 = new POINTFLOAT {
                x = radius2 * (float)Math.Cos(division * 2), y = radius2 * (float)Math.Sin(division * 2)
            };
            float radius2Line  = (float)Math.Sqrt(Math.Pow(p2.x - p1.x, 2) + Math.Pow(p2.y - p1.y, 2));
            float transRadius2 = (float)Math.Sqrt(Math.Pow(radius2, 2) - Math.Pow(radius2Line / 2, 2));

            p1 = new POINTFLOAT {
                x = 0, y = height
            };
            p2 = new POINTFLOAT {
                x = transRadius1 - transRadius2, y = height
            };

            float angleX = GetAngleDegrees(p1, p2);

            angleX = (radius1 < radius2) ? angleX : -angleX;

            POINTFLOAT normVect1, normVect2;
            POINTFLOAT p3;
            POINTFLOAT plane = new POINTFLOAT {
                x = 1, y = 0
            };

            if (radius1 == 0)
            {
                p1 = new POINTFLOAT {
                    x = radius2 * (float)Math.Cos(-Math.PI / 2), y = radius2 * (float)Math.Sin(-Math.PI / 2)
                };
                p2 = new POINTFLOAT {
                    x = radius2 * (float)Math.Cos(-Math.PI / 2 + division), y = radius2 * (float)Math.Sin(-Math.PI / 2 + division)
                };
                p3 = new POINTFLOAT {
                    x = radius2 * (float)Math.Cos(-Math.PI / 2 + division * 2), y = radius2 * (float)Math.Sin(-Math.PI / 2 + division * 2)
                };
            }
            else
            {
                p1 = new POINTFLOAT {
                    x = radius1 * (float)Math.Cos(-Math.PI / 2), y = radius1 * (float)Math.Sin(-Math.PI / 2)
                };
                p2 = new POINTFLOAT {
                    x = radius1 * (float)Math.Cos(-Math.PI / 2 + division), y = radius1 * (float)Math.Sin(-Math.PI / 2 + division)
                };
                p3 = new POINTFLOAT {
                    x = radius1 * (float)Math.Cos(-Math.PI / 2 + division * 2), y = radius1 * (float)Math.Sin(-Math.PI / 2 + division * 2)
                };
            }

            normVect1 = new POINTFLOAT {
                x = p2.x - p1.x, y = p2.y - p1.y
            };
            normVect2 = new POINTFLOAT {
                x = p3.x - p2.x, y = p3.y - p2.y
            };
            float initialAngleY = GetAngleDegrees(normVect1, plane);
            float angleY        = GetAngleDegrees(normVect1, normVect2);

            POINTFLOAT[] trapezeCoord = new POINTFLOAT[4];

            p1 = new POINTFLOAT {
                x = radius1 * (float)Math.Cos(division), y = radius1 * (float)Math.Sin(division)
            };
            p2 = new POINTFLOAT {
                x = radius1 * (float)Math.Cos(division * 2), y = radius1 * (float)Math.Sin(division * 2)
            };
            trapezeCoord[0] = new POINTFLOAT {
                x = 0, y = 0
            };
            trapezeCoord[1] = new POINTFLOAT {
                x = (float)Math.Sqrt((float)Math.Pow(p1.x - p2.x, 2) + Math.Pow(p1.y - p2.y, 2)), y = 0
            };

            p3 = new POINTFLOAT {
                x = radius2 * (float)Math.Cos(division), y = radius2 * (float)Math.Sin(division)
            };
            POINTFLOAT p4 = new POINTFLOAT {
                x = radius2 * (float)Math.Cos(division * 2), y = radius2 * (float)Math.Sin(division * 2)
            };

            float topLength     = (float)Math.Sqrt((float)Math.Pow(p3.x - p4.x, 2) + Math.Pow(p3.y - p4.y, 2));
            float trapezeHeight = (float)Math.Sqrt((float)Math.Pow(radius1 - radius2, 2) + Math.Pow(height, 2));

            trapezeHeight   = (float)Math.Sqrt(Math.Pow(height, 2) + Math.Pow(transRadius1 - transRadius2, 2));
            trapezeCoord[2] = new POINTFLOAT {
                x = (trapezeCoord[1].x - (topLength)) / 2, y = trapezeHeight
            };
            trapezeCoord[3] = new POINTFLOAT {
                x = trapezeCoord[2].x + (topLength), y = trapezeHeight
            };

            MainWindow.gl.Rotate(initialAngleY, 0, 1, 0);
            for (int i = 0; i < transtelation; i++)
            {
                MainWindow.gl.Rotate(angleX, 1.0f, 0.0f, 0.0f);
                DrawTriangle(trapezeCoord[0], trapezeCoord[1], trapezeCoord[2], color, drawFrame);
                DrawTriangle(trapezeCoord[3], trapezeCoord[1], trapezeCoord[2], color, drawFrame);
                MainWindow.gl.Rotate(-angleX, 1.0f, 0.0f, 0.0f);
                MainWindow.gl.Translate(trapezeCoord[1].x, 0, 0);
                MainWindow.gl.Rotate(angleY, 0, 1, 0);
            }

            MainWindow.gl.PopMatrix();
            if (drawFaces)
            {
                MainWindow.gl.PushMatrix();
                MainWindow.gl.Translate(center.x, center.y - height / 2, center.z + radius1);
                MainWindow.gl.Translate(0, 0, -radius1);
                MainWindow.gl.Rotate(-90, 1.0f, 0.0f, 0.0f);
                POINTFLOAT center1 = new POINTFLOAT {
                    x = 0, y = 0
                };
                DrawCircle(center1, radius1, transtelation, color, drawFrame);
                MainWindow.gl.Translate(0.0f, 0.0f, height);
                DrawCircle(center1, radius2, transtelation, color, drawFrame);
                MainWindow.gl.PopMatrix();
            }
        }