Exemplo n.º 1
6
        /// <summary>
        /// Handles the OpenGLDraw event of the openGLControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RenderEventArgs"/> instance containing the event data.</param>
        public void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
        {
            //  Get the OpenGL object.
            gl = openGLControl.OpenGL;

            //  Clear the color and depth buffer.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Load the identity matrix.
            gl.LoadIdentity();

            //  Rotate around the Y axis.
            //gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
            cord = ComInput.Coordinates.Instance;
            this.ModelRotater(gl);

            gl.Enable(OpenGL.GL_BLEND);
            gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);

            //  Draw a coloured parallelepiped.
            gl.Begin(OpenGL.GL_QUADS);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(-2.0f, -0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(2.0f, -0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(2.0f, 0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(-2.0f, 0.25f, -1.0f);
            //-------------------------------------
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(-2.0f, -0.25f, -1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(-2.0f, -0.25f, 1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(-2.0f, 0.25f, 1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(-2.0f, 0.25f, -1.0f);
            //-------------------------------------
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(-2.0f, -0.25f, 1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(2.0f, -0.25f, 1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(2.0f, 0.25f, 1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(-2.0f, 0.25f, 1.0f);
            //-------------------------------------
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(2.0f, -0.25f, 1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(2.0f, -0.25f, -1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(2.0f, 0.25f, -1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(2.0f, 0.25f, 1.0f);
            //-------------------------------------
            gl.Color(0.0f, 1.0f, 1.0f);
            gl.Vertex(-2.0f, 0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 1.0f);
            gl.Vertex(2.0f, 0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 1.0f);
            gl.Vertex(2.0f, 0.25f, 1.0f);

            gl.Color(0.0f, 1.0f, 1.0f);
            gl.Vertex(-2.0f, 0.25f, 1.0f);
            //--------------------------------------
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(-2.0f, -0.25f, -1.0f);

            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(2.0f, -0.25f, -1.0f);

            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(2.0f, -0.25f, 1.0f);

            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(-2.0f, -0.25f, 1.0f);

            gl.End();

            //-------------------Angle indicator prototype is here----------------------------------------------
            gl.LoadIdentity();

            gl.Rotate(cord.getX(), 1.0f, 0.0f, 0.0f);

            gl.Begin(OpenGL.GL_TRIANGLES);

            gl.Vertex(0.0f, 2.75f, 0.0f);
            gl.Vertex(0.25f, 3.25f, 0.0f);
            gl.Vertex(-0.25f, 3.25f, 0.0f);

            gl.End();

            gl.LoadIdentity();

            gl.Rotate(cord.getZ(), 0.0f, 1.0f, 0.0f);

            gl.Begin(OpenGL.GL_TRIANGLES);

            gl.Vertex(0.0f, 0.0f, 2.75f);
            gl.Vertex(0.0f, 0.25f, 3.25f);
            gl.Vertex(0.0f, -0.25f, 3.25f);

            gl.End();

            gl.LoadIdentity();

            gl.Rotate(cord.getY(), 0.0f, 0.0f, 1.0f);

            gl.Begin(OpenGL.GL_TRIANGLES);

            gl.Vertex(2.75f, 0.0f, 0.0f);
            gl.Vertex(3.25f, 0.0f, 0.25f);
            gl.Vertex(3.25f, 0.0f, -0.25f);

            gl.End();

            //------------------Circles of planes is here-----------------------------------------------

            gl.LoadIdentity();

            gl.Begin(OpenGL.GL_LINE_LOOP);
            for(int i = 0; i < 200; i++)
            {
                float theta = 2.0f * 3.1415926f * (float)i / 200f;//get the current angle

                float x = 3f * (float)System.Math.Cos(theta);//calculate the x component
                float y = 3f * (float)System.Math.Sin(theta);//calculate the y component

                gl.Color(0.0f, 1.0f, 0.0f);
                gl.Vertex(0f, y + 0.0f, x + 0.0f);//output vertex

            }
            gl.End();

            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int i = 0; i < 200; i++)
            {
                float theta = 2.0f * 3.1415926f * (float)i / 200f;//get the current angle

                float x = 3f * (float)System.Math.Cos(theta);//calculate the x component
                float y = 3f * (float)System.Math.Sin(theta);//calculate the y component

                gl.Vertex(x + 0.0f, 0.0f, y + 0.0f);//output vertex

            }
            gl.End();

            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int i = 0; i < 200; i++)
            {
                float theta = 2.0f * 3.1415926f * (float)i / 200f;//get the current angle

                float x = 3f * (float)System.Math.Cos(theta);//calculate the x component
                float y = 3f * (float)System.Math.Sin(theta);//calculate the y component

                gl.Vertex(x + 0.0f, y + 0.0f, 0.0f);//output vertex

            }
            gl.End();

            /* //--------------Coordinate axis's is here--------------------------------------------

            gl.LoadIdentity();

            gl.Begin(OpenGL.GL_LINE_STRIP);

            gl.Color(1.0f, 1.0f, 1.0f);

            gl.Vertex(-4.0f, 0.5f, 1.5f);
            gl.Vertex(2.5f, 0.5f, 1.5f);
            gl.Vertex(2.5f, 0.5f, -4.5f);
            gl.Vertex(2.5f, 0.5f, 1.5f);
            gl.Vertex(2.5f, 4.0f, 1.5f);

            gl.End();

            */ //------------Shpere is here-----------------------------

            gl.LoadIdentity();

            gl.Color(0.85f, 0.85f, 0.85f, 0.5f);

            gl.Begin(OpenGL.GL_QUADS);
            for (int i = 0; i < 1; i++)
            {
                this.draw_sphere(gl, 3);
            }
            gl.End();

            //---------------3D Text prototype is here-------------------

            gl.LoadIdentity();

            gl.Translate(0.0f, 3.5f, -3.0f);

            gl.Color(0.0f, 1.0f, 0.65f);

            gl.Rotate(270.0f, 0.0f, 1.0f, 0.0f);

            gl.DrawText3D("a", 0.2f,
                1.0f, 0.1f, "osX: 0");

            //  Nudge the rotation.
            rotation += 2.0f;
        }
Exemplo n.º 2
0
        public static void MyGrid(SharpGL.OpenGL gl, int iLo, int iHi, int jLo, int jHi)
        {
            const String ColumnAnnotationFont = "Times New Roman";
            const int    Ilo = 0;
            const int    Ihi = 10;
            const int    Jlo = 0;
            const int    Jhi = 10;

            gl.PushAttrib(SharpGL.OpenGL.GL_CURRENT_BIT | SharpGL.OpenGL.GL_ENABLE_BIT | SharpGL.OpenGL.GL_LINE_BIT);
            gl.Disable(SharpGL.OpenGL.GL_LIGHTING);
            gl.Disable(SharpGL.OpenGL.GL_TEXTURE_2D);
            gl.LineWidth(1.0f);

            //  Draw the grid lines.
            gl.Begin(SharpGL.OpenGL.GL_LINES);

            for (int i = iLo; i <= iHi; i++)
            {
                float fcol = ((i % 10) == 0) ? 0.3f : 0.15f;
                gl.Color(fcol, fcol, fcol);
                gl.Vertex(i, jLo, 0);
                gl.Vertex(i, jHi, 0);
            }
            for (int j = jLo; j <= jHi; j++)
            {
                float fcol = ((j % 10) == 0) ? 0.3f : 0.15f;
                gl.Vertex(iLo, j, 0);
                gl.Vertex(iHi, j, 0);
            }
            gl.End( );
            // Draw Spreadsheet boarders

            for (int i = iLo; i < iHi; i++)
            {
                gl.PushMatrix( );
                gl.Translate(i + 0.25, jLo - 0.5, 0);
                gl.Scale(0.5d, 0.5d, 0.5d);

                String Annotation = String.Format("{0,2} ", i);
                gl.DrawText3D(ColumnAnnotationFont, 8.0f, 0.0f, 0.1f, Annotation);
                gl.PopMatrix( );
            }

            for (int i = iLo; i < iHi; i++)
            {
                gl.PushMatrix( );
                gl.Translate(i + .25, jHi + 0.5, 0);
                gl.Scale(0.5d, 0.5d, 0.5d);
                String Annotation = String.Format("{0,2} ", i);
                gl.DrawText3D(ColumnAnnotationFont, 8.0f, 0.0f, 0.1f, Annotation);
                gl.PopMatrix( );
            }

            for (int j = jLo; j < jHi; j++)
            {
                gl.PushMatrix( );
                gl.Translate(iLo - 0.5, j + 0.25, 0);
                gl.Scale(0.5d, 0.5d, 0.5d);
                String Annotation = String.Format("{0,2} ", j + 1);
                gl.DrawText3D(ColumnAnnotationFont, 8.0f, 0.0f, 0.1f, Annotation);
                gl.PopMatrix( );
            }

            for (int j = jLo; j < jHi; j++)
            {
                gl.PushMatrix( );
                gl.Translate(iHi + 0.5, j + 0.25, 0);
                gl.Scale(0.5d, 0.5d, 0.5d);
                String Annotation = String.Format("{0,2} ", j + 1);
                gl.DrawText3D(ColumnAnnotationFont, 8.0f, 0.0f, 0.1f, Annotation);
                gl.PopMatrix( );
            }

            gl.LineWidth(2);
            gl.Color(.5, .2, .1);
            gl.Begin(SharpGL.OpenGL.GL_LINE_LOOP);
            gl.Vertex(Jlo, Ilo);
            gl.Vertex(Jlo, Ihi + 1);
            gl.Vertex(Jhi + 1, Ihi + 1);
            gl.Vertex(Jhi + 1, Ilo);
            gl.End( );

            gl.PopAttrib( );
        }
Exemplo n.º 3
0
        public static void MyGlobalAxis(SharpGL.OpenGL gl, int AxesLength = 20, int LineWidth               = 2, int Pointsize = 3, Boolean DoMinusTicks = true,
                                        Boolean TagOrigin             = true, Boolean DoXYZAnnotation       = true, Boolean DoMinusXYZAnnotation = true, Boolean DoUnitTicks = true,
                                        Boolean DoAnnotateZTicks      = true, Boolean DoAnnotateYTicks      = true, Boolean DoAnnotateXTicks     = true, Boolean DoPlusTicks = true, float tick_annotation_scale = 0.4f,
                                        Boolean Draw_Minus_Z_Axis_Leg = true, Boolean Draw_Minus_Y_Axis_Leg = true, Boolean Draw_Minus_X_Axis_Leg = true)
        {
            gl.PushMatrix( );

            gl.PushAttrib(SharpGL.OpenGL.GL_CURRENT_BIT | SharpGL.OpenGL.GL_ENABLE_BIT | SharpGL.OpenGL.GL_LINE_BIT | SharpGL.OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.Disable(SharpGL.OpenGL.GL_LIGHTING);
            gl.Disable(SharpGL.OpenGL.GL_TEXTURE_2D);
            gl.DepthFunc(SharpGL.OpenGL.GL_ALWAYS);

            gl.LineWidth(LineWidth);

            //  Draw the axis and annotate the ends.

            if (TagOrigin)
            {
                gl.Color(White);
                gl.PointSize(Pointsize);
                gl.Vertex(Origin);
                gl.PushMatrix( );
                gl.DrawText3D(AxisLabelFont, 10.0f, 0.0f, 0.2f, "0");
                gl.PopMatrix( );
            }

            gl.Color(Red);
            gl.Begin(SharpGL.OpenGL.GL_LINES);
            gl.Vertex(Origin);
            gl.Vertex(AxesLength, 0, 0);
            gl.End( );

            if (Draw_Minus_X_Axis_Leg)
            {
                gl.Color(Red);
                gl.Begin(SharpGL.OpenGL.GL_LINES);
                gl.Vertex(Origin);
                gl.Vertex(-AxesLength, 0, 0);
                gl.End( );
            }

            if (DoXYZAnnotation)
            {
                gl.PushMatrix( );
                gl.Translate(AxesLength, 0, 0);
                gl.DrawText3D(AxisLabelFont, 10.0f, 0.0f, 0.2f, "+X");
                gl.PopMatrix( );
            }

            if (DoMinusXYZAnnotation)
            {
                gl.PushMatrix( );
                gl.Translate(-AxesLength, 0, 0);
                gl.DrawText3D(AxisLabelFont, 10.0f, 0.0f, 0.2f, "-X");
                gl.PopMatrix( );
            }

            gl.Color(Green);
            gl.Begin(SharpGL.OpenGL.GL_LINES);
            gl.Vertex(Origin);
            gl.Vertex(0, AxesLength, 0);
            gl.End( );

            if (Draw_Minus_Y_Axis_Leg)
            {
                gl.Color(Green);
                gl.Begin(SharpGL.OpenGL.GL_LINES);
                gl.Vertex(Origin);
                gl.Vertex(0, -AxesLength, 0);
                gl.End( );
            }

            if (DoXYZAnnotation)
            {
                gl.PushMatrix( );
                gl.Translate(0, AxesLength, 0);
                gl.DrawText3D(AxisLabelFont, 10.0f, 0.0f, 0.1f, "+Y");
                gl.PopMatrix( );
            }

            if (DoMinusXYZAnnotation)
            {
                gl.PushMatrix( );
                gl.Translate(0, -AxesLength, 0);
                gl.DrawText3D(AxisLabelFont, 10.0f, 0.0f, 0.1f, "-Y");
                gl.PopMatrix( );
            }

            if (true)
            {
                gl.Color(Blue);
                gl.Begin(SharpGL.OpenGL.GL_LINES);
                gl.Vertex(Origin);
                gl.Vertex(0, 0, AxesLength);
                gl.End( );
            }

            if (Draw_Minus_Z_Axis_Leg)
            {
                gl.Color(Blue);
                gl.Begin(SharpGL.OpenGL.GL_LINES);
                gl.Vertex(Origin);
                gl.Vertex(0, 0, -AxesLength);
                gl.End( );
            }

            if (DoXYZAnnotation)
            {
                gl.PushMatrix( );
                gl.Translate(0, 0, AxesLength);
                gl.DrawText3D(AxisLabelFont, 10.0f, 0.0f, 0.05f, "+Z");
                gl.PopMatrix( );
            }

            if (DoMinusXYZAnnotation && Draw_Minus_Z_Axis_Leg)
            {
                gl.PushMatrix( );
                gl.Translate(0, 0, -AxesLength);
                gl.DrawText3D(AxisLabelFont, 10.0f, 0.0f, 0.05f, "-Z");
                gl.PopMatrix( );
            }

            if (DoUnitTicks)
            {
                gl.PointSize(Pointsize);
                gl.Color(White);
                for (int i = 0; i < AxesLength; i++)
                {
                    if (DoPlusTicks)
                    {
                        gl.Begin(SharpGL.Enumerations.BeginMode.Points);
                        gl.Vertex(i, 0, 0);
                        gl.Vertex(0, i, 0);
                        gl.Vertex(0, 0, i);
                        gl.End( );
                    }

                    if (DoMinusTicks)
                    {
                        gl.Begin(SharpGL.Enumerations.BeginMode.Points);
                        gl.Vertex(-i, 0, 0);
                        gl.Vertex(0, -i, 0);
                        if (Draw_Minus_Z_Axis_Leg)
                        {
                            gl.Vertex(0, 0, -i);
                        }

                        gl.End( );
                    }

                    if (DoAnnotateZTicks)
                    {
                        gl.PushMatrix( );
                        gl.Translate(0, 0, i);
                        gl.Scale(tick_annotation_scale, tick_annotation_scale, tick_annotation_scale);
                        gl.DrawText3D(faceName: AxisLabelFont, fontSize: .1f, deviation: 0.0f, extrusion: 0.05f, text: i.ToString( ));
                        gl.PopMatrix( );
                    }

                    if (DoMinusTicks && Draw_Minus_Z_Axis_Leg)
                    {
                        gl.PushMatrix( );
                        gl.Translate(0, 0, -i);
                        gl.Scale(tick_annotation_scale, tick_annotation_scale, tick_annotation_scale);
                        gl.DrawText3D(faceName: AxisLabelFont, fontSize: .1f, deviation: 0.0f, extrusion: 0.05f, text: (-i).ToString( ));
                        gl.PopMatrix( );
                    }
                    if (DoAnnotateYTicks)
                    {
                        gl.PushMatrix( );
                        gl.Translate(0, i, 0);
                        gl.Scale(tick_annotation_scale, tick_annotation_scale, tick_annotation_scale);
                        gl.DrawText3D(faceName: AxisLabelFont, fontSize: .1f, deviation: 0.0f, extrusion: 0.05f, text: i.ToString( ));
                        gl.PopMatrix( );
                    }
                    if (DoMinusTicks)
                    {
                        gl.PushMatrix( );
                        gl.Translate(0, -i, 0);
                        gl.Scale(tick_annotation_scale, tick_annotation_scale, tick_annotation_scale);
                        gl.DrawText3D(faceName: AxisLabelFont, fontSize: .1f, deviation: 0.0f, extrusion: 0.05f, text: (-i).ToString( ));
                        gl.PopMatrix( );
                    }
                    if (DoAnnotateXTicks)
                    {
                        gl.PushMatrix( );
                        gl.Translate(i, 0, 0);
                        gl.Scale(tick_annotation_scale, tick_annotation_scale, tick_annotation_scale);
                        gl.DrawText3D(faceName: AxisLabelFont, fontSize: .1f, deviation: 0.0f, extrusion: 0.05f, text: i.ToString( ));
                        gl.PopMatrix( );
                    }
                    if (DoMinusTicks)
                    {
                        gl.PushMatrix( );
                        gl.Translate(-i, 0, 0);
                        gl.Scale(tick_annotation_scale, tick_annotation_scale, tick_annotation_scale);
                        gl.DrawText3D(faceName: AxisLabelFont, fontSize: .1f, deviation: 0.0f, extrusion: 0.05f, text: (-i).ToString( ));
                        gl.PopMatrix( );
                    }
                }
            }
            //  Restore attributes.
            gl.PopAttrib( );
            gl.PopMatrix( );
        }