示例#1
0
        /// <summary>
        /// Creates the display list. This function draws the
        /// geometry as well as compiling it.
        /// </summary>
        private void CreateDisplayList(OpenGL gl)
        {
            //  Create the display list.
            displayList = new DisplayList();

            //  Generate the display list and
            displayList.Generate(gl);
            displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute);

            //  Push attributes, set the color.
            gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
                OpenGL.GL_LINE_BIT);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.LineWidth(1.0f);

            //  Draw the grid lines.
            gl.Begin(OpenGL.GL_LINES);
            for (int i = -10; i <= 10; i++)
            {
                float fcol = ((i % 10) == 0) ? 0.3f : 0.15f;
                gl.Color(fcol, fcol, fcol);
                gl.Vertex(i, -10, 0);
                gl.Vertex(i, 10, 0);
                gl.Vertex(-10, i, 0);
                gl.Vertex(10, i, 0);
            }
            gl.End();

            //  Restore attributes.
            gl.PopAttrib();

            //  End the display list.
            displayList.End(gl);
        }
示例#2
0
        /// <summary>
        /// Render to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        public override void Render(OpenGL gl, RenderMode renderMode)
        {
            //	Create the evaluator.
            gl.Map1(OpenGL.GL_MAP1_VERTEX_3,//	Use and produce 3D points.
                0,								//	Low order value of 'u'.
                1,								//	High order value of 'u'.
                3,								//	Size (bytes) of a control point.
                ControlPoints.Width,			//	Order (i.e degree plus one).
                ControlPoints.ToFloatArray());	//	The control points.

            //	Enable the type of evaluator we wish to use.
            gl.Enable(OpenGL.GL_MAP1_VERTEX_3);

            //	Beging drawing a line strip.
            gl.Begin(OpenGL.GL_LINE_STRIP);

            //	Now draw it.
            for (int i = 0; i <= segments; i++)
                gl.EvalCoord1((float)i / segments);

            gl.End();

            //	Draw the control points.
            ControlPoints.Draw(gl, DrawControlPoints, DrawControlGrid);
        }
示例#3
0
        /// <summary>
        /// Creates the display list. This function draws the
        /// geometry as well as compiling it.
        /// </summary>
        private void CreateDisplayList(OpenGL gl)
        {
            //  Create the display list. 
            displayList = new DisplayList();

            //  Generate the display list and 
            displayList.Generate(gl);
            displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute);

            //  Push all attributes, disable lighting and depth testing.
            gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
                OpenGL.GL_LINE_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.DepthFunc(OpenGL.GL_ALWAYS);

            //  Set a nice fat line width.
            gl.LineWidth(1.50f);

            //  Draw the axies.
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1f, 0f, 0f, 1f);
            gl.Vertex(0, 0, 0);
            gl.Vertex(3, 0, 0);
            gl.Color(0f, 1f, 0f, 1f);
            gl.Vertex(0, 0, 0);
            gl.Vertex(0, 3, 0);
            gl.Color(0f, 0f, 1f, 1f);
            gl.Vertex(0, 0, 0);
            gl.Vertex(0, 0, 3);
            gl.End();

            //  Restore attributes.
            gl.PopAttrib();

            //  End the display list.
            displayList.End(gl);
        }
        public override void Draw(OpenGL gl)
        {
            gl.Rotate(RotateX, RotateY, RotateZ);

            //set drawing color
            gl.Color(ObjColor.R / 255.0, ObjColor.G / 255.0, ObjColor.B / 255.0);

            gl.Enable(OpenGL.GL_TEXTURE_2D);

            //Bind the texture.
            Texture.Bind(gl);

            gl.Begin(OpenGL.GL_QUADS);

            // Front Face
            float x1 = (float)(Center.X - ScaleX);
            float y1 = (float)(Center.Y - ScaleY);
            float z1 = (float)(Center.Z - ScaleZ);
            float x2 = (float)(Center.X + ScaleX);
            float y2 = (float)(Center.Y + ScaleY);
            float z2 = (float)(Center.Z + ScaleZ);

            gl.TexCoord(0.0f, 0.0f); gl.Vertex(x1, y1, z1);             // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(Center.X, y2, Center.Z); // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(x2, y1, z1);             // Top Right Of The Texture and Quad

            gl.TexCoord(0.0f, 0.0f); gl.Vertex(x1, y1, z1);             // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(Center.X, y2, Center.Z); // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(x1, y1, z2);             // Top Right Of The Texture and Quad

            gl.TexCoord(0.0f, 0.0f); gl.Vertex(x2, y1, z2);             // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(Center.X, y2, Center.Z); // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(x2, y1, z1);             // Top Right Of The Texture and Quad

            gl.TexCoord(0.0f, 0.0f); gl.Vertex(x2, y1, z2);             // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(Center.X, y2, Center.Z); // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(x1, y1, z2);             // Top Right Of The Texture and Quad

            // Bottom Face
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(x1, y1, z1); // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(x2, y1, z1); // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(x2, y1, z2); // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(x1, y1, z2); // Bottom Right Of The Texture and Quad

            gl.End();

            //draw control line
            gl.Color(OutlineColor.R / 255.0, OutlineColor.G / 255.0, OutlineColor.B / 255.0);
            gl.LineWidth(OutlineWeight);
            gl.Begin(OpenGL.GL_LINE_LOOP);

            gl.Vertex(x1, y1, z1);
            gl.Vertex(Center.X, y2, Center.Z);
            gl.Vertex(x2, y1, z1);

            gl.Vertex(x1, y1, z1);
            gl.Vertex(Center.X, y2, Center.Z);
            gl.Vertex(x1, y1, z2);

            gl.Vertex(x2, y1, z2);
            gl.Vertex(Center.X, y2, Center.Z);
            gl.Vertex(x2, y1, z1);

            gl.Vertex(x2, y1, z2);
            gl.Vertex(Center.X, y2, Center.Z);
            gl.Vertex(x1, y1, z2);

            gl.Vertex(x1, y1, z1);
            gl.Vertex(x2, y1, z1);
            gl.Vertex(x2, y1, z2);
            gl.Vertex(x1, y1, z2);

            gl.End();

            gl.Disable(OpenGL.GL_TEXTURE_2D);

            gl.Flush();

            gl.Rotate(-RotateX, -RotateY, -RotateZ);
        }
示例#5
0
        private void OpenGLControl1_OpenGLDraw(object sender, RenderEventArgs args)
        {
            if (Ready)
            {
                model = new ObjModel(ObjFile);

                OpenGL gl = this.openGLControl1.OpenGL;
                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
                gl.LoadIdentity();

                currentX = Math.Sin(angle) * radius;
                currentZ = Math.Cos(angle) * radius;
                var centerPoint = calculateCenterPoint(model);

                gl.LookAt(
                    currentX, 0, currentZ,
                    centerPoint.X, centerPoint.Y, centerPoint.Z,
                    0, 1, 0);

                gl.Rotate(-rotation, 0, 1, 0);
                rotation += 3.0f;

                for (int i = 0; i < model.Faces.Length; i++)
                {
                    var face = model.Faces[i];
                    if (face.IsQuad)
                    {
                        gl.Begin(OpenGL.GL_QUADS);
                        {
                            var v1  = model.Vertics[face.Points[0].VertexIndex - 1];
                            var vn1 = model.VertexNormals[face.Points[0].NormalIndex - 1];
                            var vt1 = model.VertexTextures[face.Points[0].TextureIndex - 1];

                            var v2  = model.Vertics[face.Points[1].VertexIndex - 1];
                            var vn2 = model.VertexNormals[face.Points[1].NormalIndex - 1];
                            var vt2 = model.VertexTextures[face.Points[1].TextureIndex - 1];

                            var v3  = model.Vertics[face.Points[2].VertexIndex - 1];
                            var vn3 = model.VertexNormals[face.Points[2].NormalIndex - 1];
                            var vt3 = model.VertexTextures[face.Points[2].TextureIndex - 1];

                            var v4  = model.Vertics[face.Points[3].VertexIndex - 1];
                            var vn4 = model.VertexNormals[face.Points[3].NormalIndex - 1];
                            var vt4 = model.VertexTextures[face.Points[3].TextureIndex - 1];

                            gl.TexCoord(vt1.X, vt1.Y * -1);
                            gl.Normal(vn1.X, vn1.Y, vn1.Z);
                            gl.Vertex(v1.X, v1.Y, v1.Z);

                            gl.TexCoord(vt2.X, vt2.Y * -1);
                            gl.Normal(vn2.X, vn2.Y, vn2.Z);
                            gl.Vertex(v2.X, v2.Y, v2.Z);

                            gl.TexCoord(vt3.X, vt3.Y * -1);
                            gl.Normal(vn3.X, vn3.Y, vn3.Z);
                            gl.Vertex(v3.X, v3.Y, v3.Z);

                            gl.TexCoord(vt4.X, vt4.Y * -1);
                            gl.Normal(vn4.X, vn4.Y, vn4.Z);
                            gl.Vertex(v4.X, v4.Y, v4.Z);
                        }
                        gl.End();
                    }
                    else
                    {
                        gl.Begin(SharpGL.Enumerations.BeginMode.Triangles);
                        {
                            var v1  = model.Vertics[face.Points[0].VertexIndex - 1];
                            var vn1 = model.VertexNormals[face.Points[0].NormalIndex - 1];
                            var vt1 = model.VertexTextures[face.Points[0].TextureIndex - 1];

                            var v2  = model.Vertics[face.Points[1].VertexIndex - 1];
                            var vn2 = model.VertexNormals[face.Points[1].NormalIndex - 1];
                            var vt2 = model.VertexTextures[face.Points[1].TextureIndex - 1];

                            var v3  = model.Vertics[face.Points[2].VertexIndex - 1];
                            var vn3 = model.VertexNormals[face.Points[2].NormalIndex - 1];
                            var vt3 = model.VertexTextures[face.Points[2].TextureIndex - 1];

                            gl.TexCoord(vt1.X, vt1.Y * -1);
                            gl.Normal(vn1.X, vn1.Y, vn1.Z);
                            gl.Vertex(v1.X, v1.Y, v1.Z);

                            gl.TexCoord(vt2.X, vt2.Y * -1);
                            gl.Normal(vn2.X, vn2.Y, vn2.Z);
                            gl.Vertex(v2.X, v2.Y, v2.Z);

                            gl.TexCoord(vt3.X, vt3.Y * -1);
                            gl.Normal(vn3.X, vn3.Y, vn3.Z);
                            gl.Vertex(v3.X, v3.Y, v3.Z);
                        }
                        gl.End();
                    }
                    gl.Flush();
                }
            }
        }
示例#6
0
        private void openGLHead_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            OpenGL glh = openGLHead.OpenGL;

            glh.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
            glh.LoadIdentity();                                                 // Reset The View

            CalculateMinMax();

            //back the camera up
            glh.Translate(0, 0, -maxFieldDistance);

            //translate to that spot in the world
            glh.Translate(-fieldCenterX, -fieldCenterY, 0);

            //calculate the frustum for the section control window
            mf.CalcFrustum(glh);

            //to draw or not the triangle patch
            bool isDraw;

            glh.Color(0.2f, 0.5f, 0.4f);

            //draw patches j= # of sections
            for (int j = 0; j < mf.vehicle.numSuperSection; j++)
            {
                //every time the section turns off and on is a new patch
                int patchCount = mf.section[j].patchList.Count;

                if (patchCount > 0)
                {
                    //for every new chunk of patch
                    foreach (var triList in mf.section[j].patchList)
                    {
                        isDraw = false;
                        int count2 = triList.Count;
                        for (int i = 0; i < count2; i += 3)
                        {
                            //determine if point is in frustum or not since 2d only 4 planes required
                            if ((mf.frustum[0] * triList[i].easting) + (mf.frustum[1] * triList[i].northing) + mf.frustum[3] <= 0)
                            {
                                continue;//right
                            }
                            if ((mf.frustum[4] * triList[i].easting) + (mf.frustum[5] * triList[i].northing) + mf.frustum[7] <= 0)
                            {
                                continue;//left
                            }
                            if ((mf.frustum[16] * triList[i].easting) + (mf.frustum[17] * triList[i].northing) + mf.frustum[19] <= 0)
                            {
                                continue;//bottom
                            }
                            if ((mf.frustum[20] * triList[i].easting) + (mf.frustum[21] * triList[i].northing) + mf.frustum[23] <= 0)
                            {
                                continue;//top
                            }
                            //point is in frustum so draw the entire patch
                            isDraw = true;
                            break;
                        }

                        if (isDraw)
                        {
                            //draw the triangle in each triangle strip
                            glh.Begin(OpenGL.GL_TRIANGLE_STRIP);
                            count2 = triList.Count;
                            const int mipmap = 8;

                            //if large enough patch and camera zoomed out, fake mipmap the patches, skip triangles
                            if (count2 >= (mipmap + 2))
                            {
                                int step = mipmap;
                                for (int i = 0; i < count2; i += step)
                                {
                                    glh.Vertex(triList[i].easting, triList[i].northing, 0); i++;
                                    glh.Vertex(triList[i].easting, triList[i].northing, 0); i++;

                                    //too small to mipmap it
                                    if (count2 - i <= (mipmap + 2))
                                    {
                                        step = 0;
                                    }
                                }
                            }
                            else
                            {
                                for (int i = 0; i < count2; i++)
                                {
                                    glh.Vertex(triList[i].easting, triList[i].northing, 0);
                                }
                            }
                            glh.End();
                        }
                    }
                }
            } //end of section patches

            glh.PointSize(8.0f);
            glh.Begin(OpenGL.GL_POINTS);
            glh.Color(0.95f, 0.90f, 0.60f);

#pragma warning disable CS1690 // Accessing a member on a field of a marshal-by-reference class may cause a runtime exception
            glh.Vertex(mf.pivotAxlePos.easting, mf.pivotAxlePos.northing, 0.0);
#pragma warning restore CS1690 // Accessing a member on a field of a marshal-by-reference class may cause a runtime exception

            //draw the pivot, startPt and Heading Pt and line
            glh.Color(0.95f, 0.0f, 0.0f);
            glh.Vertex(mf.hl.startPoint.easting, mf.hl.startPoint.northing, 0);
            glh.Color(0.90f, 0.90f, 0.0f);
            glh.Vertex(mf.hl.headingPoint.easting, mf.hl.headingPoint.northing, 0);
            glh.End();

            if (mf.hl.isStartPointSet)
            {
                glh.LineWidth(4);
                glh.Color(0.95f, 0.0f, 0.30f);
                glh.Begin(OpenGL.GL_LINE_STRIP);
                glh.Vertex(mf.hl.startPoint.easting, mf.hl.startPoint.northing, 0);
                glh.Color(0.90f, 0.90f, 0.30f);
                glh.Vertex(mf.hl.headingPoint.easting, mf.hl.headingPoint.northing, 0);
                glh.End();
            }

            //set pointsize
            glh.PointSize(4.0f);

            ////draw the outside boundary
            glh.LineWidth(2);

            int ptCount = mf.boundz.ptList.Count;
            if (ptCount > 0)
            {
                glh.Color(0.98f, 0.2f, 0.90f);
                glh.Begin(OpenGL.GL_LINE_STRIP);
                for (int h = 0; h < ptCount; h++)
                {
                    glh.Vertex(mf.boundz.ptList[h].easting, mf.boundz.ptList[h].northing, 0);
                }
                glh.End();

                //the "close the loop" line
                //glh.LineWidth(4);
                glh.Color(0.0f, 0.990f, 0.0f);
                glh.Begin(OpenGL.GL_LINE_STRIP);
                glh.Vertex(mf.boundz.ptList[ptCount - 1].easting, mf.boundz.ptList[ptCount - 1].northing, 0);
                glh.Vertex(mf.boundz.ptList[0].easting, mf.boundz.ptList[0].northing, 0);
                glh.End();
            }

            ////draw the headland line
            ptCount = mf.hl.ptList.Count;
            if (ptCount > 0)
            {
                glh.Color(0.009038f, 0.9892f, 0.10f);
                glh.Begin(OpenGL.GL_POINTS);
                for (int h = 0; h < ptCount; h++)
                {
                    glh.Vertex(mf.hl.ptList[h].easting, mf.hl.ptList[h].northing, 0);
                }
                glh.End();
            }

            //plot the touch points so far
            if (isDrawingHeadland)
            {
                ////draw the headland line so far
                ptCount = mf.hl.ptList.Count;
                if (ptCount > 0)
                {
                    glh.Color(0.08f, 0.9892f, 0.2710f);
                    glh.Begin(OpenGL.GL_LINE_STRIP);
                    for (int h = 0; h < ptCount; h++)
                    {
                        glh.Vertex(mf.hl.ptList[h].easting, mf.hl.ptList[h].northing, 0);
                    }
                    glh.End();

                    glh.Color(0.978f, 0.392f, 0.10f);
                    //the "close the loop" line
                    glh.Begin(OpenGL.GL_LINE_STRIP);
                    glh.Vertex(mf.hl.ptList[ptCount - 1].easting, mf.hl.ptList[ptCount - 1].northing, 0);
                    glh.Vertex(mf.hl.ptList[0].easting, mf.hl.ptList[0].northing, 0);
                    glh.End();
                }
            }

            //draw the ABLine
            if (mf.ABLine.isABLineSet | mf.ABLine.isABLineBeingSet)
            {
                //Draw reference AB line
                glh.LineWidth(1);
                glh.Enable(OpenGL.GL_LINE_STIPPLE);
                glh.LineStipple(1, 0x00F0);

                glh.Begin(OpenGL.GL_LINES);
                glh.Color(0.9f, 0.45f, 0.87f);
                glh.Vertex(mf.ABLine.refABLineP1.easting, mf.ABLine.refABLineP1.northing, 0);
                glh.Vertex(mf.ABLine.refABLineP2.easting, mf.ABLine.refABLineP2.northing, 0);
                glh.End();
                glh.Disable(OpenGL.GL_LINE_STIPPLE);

                //raw current AB Line
                glh.Begin(OpenGL.GL_LINES);
                glh.Color(0.9f, 0.0f, 0.50f);
                glh.Vertex(mf.ABLine.currentABLineP1.easting, mf.ABLine.currentABLineP1.northing, 0.0);
                glh.Vertex(mf.ABLine.currentABLineP2.easting, mf.ABLine.currentABLineP2.northing, 0.0);
                glh.End();
            }

            //draw curve if there is one
            if (mf.curve.isCurveSet)
            {
                int ptC = mf.curve.curList.Count;
                if (ptC > 0)
                {
                    glh.LineWidth(2);
                    glh.Color(0.95f, 0.25f, 0.50f);
                    glh.Begin(OpenGL.GL_LINE_STRIP);
                    for (int h = 0; h < ptC; h++)
                    {
                        glh.Vertex(mf.curve.curList[h].easting, mf.curve.curList[h].northing, 0);
                    }
                    glh.End();
                }
            }

            glh.PointSize(1.0f);
        }
示例#7
0
        /// <summary>
        ///  Rekurzivna metoda zaduzena za iscrtavanje objekata u sceni koji su reprezentovani cvorovima.
        ///  U zavisnosti od karakteristika objekata podesavaju se odgovarajuce promenjive stanja (GL_LIGHTING, GL_COLOR_MATERIAL, GL_TEXTURE_2D).
        /// </summary>
        /// <param name="node">Cvor koji ce biti iscrtan.</param>
        private void RenderNode(Node node)
        {
            gl.PushMatrix();

            // Primena tranformacija, definisanih za dati cvor.
            float[] matrix = new float[16] {
                node.Transform.A1, node.Transform.B1, node.Transform.C1, node.Transform.D1, node.Transform.A2, node.Transform.B2, node.Transform.C2, node.Transform.D2, node.Transform.A3, node.Transform.B3, node.Transform.C3, node.Transform.D3, node.Transform.A4, node.Transform.B4, node.Transform.C4, node.Transform.D4
            };
            gl.MultMatrix(matrix);

            // Iscrtavanje objekata u sceni koji su reprezentovani datim cvorom.
            if (node.HasMeshes)
            {
                foreach (int meshIndex in node.MeshIndices)
                {
                    Mesh     mesh     = m_scene.Meshes[meshIndex];
                    Material material = m_scene.Materials[mesh.MaterialIndex];

                    // Primena komponenti materijala datog objekta.
                    ApplyMaterial(material);

                    // Primena teksture u slucaju da je ista definisana za dati materijal.
                    if (material.GetAllTextures().Length > 0)
                    {
                        gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_texMappings[material.GetAllTextures()[0]]);
                    }

                    // Podesavanje proracuna osvetljenja za dati objekat.
                    bool hasNormals = mesh.HasNormals;
                    if (hasNormals)
                    {
                        gl.Enable(OpenGL.GL_LIGHTING);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_LIGHTING);
                    }

                    // Podesavanje color tracking mehanizma za dati objekat.
                    bool hasColors = mesh.HasVertexColors(0);
                    if (hasColors)
                    {
                        gl.Enable(OpenGL.GL_COLOR_MATERIAL);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_COLOR_MATERIAL);
                    }

                    // Podesavanje rezima mapiranja na teksture.
                    bool hasTexCoords = material.GetAllTextures().Length > 0 && mesh.HasTextureCoords(0);
                    if (hasTexCoords)
                    {
                        gl.Enable(OpenGL.GL_TEXTURE_2D);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_TEXTURE_2D);
                    }

                    // Iscrtavanje primitiva koji cine dati objekat.
                    // U zavisnosti od broja temena, moguce je iscrtavanje tacaka, linija, trouglova ili poligona.
                    foreach (Assimp.Face face in mesh.Faces)
                    {
                        switch (face.IndexCount)
                        {
                        case 1:
                            gl.Begin(OpenGL.GL_POINTS);
                            break;

                        case 2:
                            gl.Begin(OpenGL.GL_LINES);
                            break;

                        case 3:
                            gl.Begin(OpenGL.GL_TRIANGLES);
                            break;

                        default:
                            gl.Begin(OpenGL.GL_POLYGON);
                            break;
                        }

                        for (int i = 0; i < face.IndexCount; i++)
                        {
                            uint indice = face.Indices[i];

                            // Definisanje boje temena.
                            if (hasColors)
                            {
                                gl.Color(mesh.GetVertexColors(0)[indice].R, mesh.GetVertexColors(0)[indice].G, mesh.GetVertexColors(0)[indice].B, mesh.GetVertexColors(0)[indice].A);
                            }

                            // Definisanje normale temena.
                            if (hasNormals)
                            {
                                gl.Normal(mesh.Normals[indice].X, mesh.Normals[indice].Y, mesh.Normals[indice].Z);
                            }

                            // Definisanje koordinata teksture temena.
                            if (hasTexCoords)
                            {
                                gl.TexCoord(mesh.GetTextureCoords(0)[indice].X, 1 - mesh.GetTextureCoords(0)[indice].Y);
                            }

                            // Definisanje temena primitive.
                            gl.Vertex(mesh.Vertices[indice].X, mesh.Vertices[indice].Y, mesh.Vertices[indice].Z);
                        }
                        gl.End();
                    }
                }
            }

            // Rekurzivno scrtavanje podcvorova datog cvora.
            for (int i = 0; i < node.ChildCount; i++)
            {
                RenderNode(node.Children[i]);
            }
            gl.PopMatrix();
        }
示例#8
0
        private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs e)
        {
            UpdateLabelInfo();

            //  Get the OpenGL object, just to clean up the code.
            OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
            gl.LoadIdentity();                                                 // Reset The View

            // gl.Color(1.0f, 1.0f, 1.0f);
            // gl.FontBitmaps.DrawText(gl, 0, 0, "Arial", "Argh");
            var width  = this.openGLControl1.Width;
            var height = this.openGLControl1.Height;

            //gl.Ortho(-width / 2, width / 2, -height / 2, height / 2, -100, 100);
            //gl.LookAt()


            gl.Translate(-1.5f, 0.0f, -6.0f);           // Move Left And Into The Screen

            gl.Rotate(rtri, 0.0f, 1.0f, 0.0f);          // Rotate The Pyramid On It's Y Axis

            gl.Begin(OpenGL.GL_TRIANGLES);              // Start Drawing The Pyramid

            gl.Color(1.0f, 0.0f, 0.0f);                 // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                // Top Of Triangle (Front)
            gl.Color(0.0f, 1.0f, 0.0f);                 // Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Left Of Triangle (Front)
            gl.Color(0.0f, 0.0f, 1.0f);                 // Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Right Of Triangle (Front)

            gl.Color(1.0f, 0.0f, 0.0f);                 // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                // Top Of Triangle (Right)
            gl.Color(0.0f, 0.0f, 1.0f);                 // Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Left Of Triangle (Right)
            gl.Color(0.0f, 1.0f, 0.0f);                 // Green
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Right Of Triangle (Right)

            gl.Color(1.0f, 0.0f, 0.0f);                 // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                // Top Of Triangle (Back)
            gl.Color(0.0f, 1.0f, 0.0f);                 // Green
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Left Of Triangle (Back)
            gl.Color(0.0f, 0.0f, 1.0f);                 // Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Right Of Triangle (Back)

            gl.Color(1.0f, 0.0f, 0.0f);                 // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                // Top Of Triangle (Left)
            gl.Color(0.0f, 0.0f, 1.0f);                 // Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Left Of Triangle (Left)
            gl.Color(0.0f, 1.0f, 0.0f);                 // Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Right Of Triangle (Left)
            gl.End();                                   // Done Drawing The Pyramid

            gl.LoadIdentity();
            gl.Translate(1.5f, 0.0f, -7.0f);            // Move Right And Into The Screen

            gl.Rotate(rquad, 1.0f, 1.0f, 1.0f);         // Rotate The Cube On X, Y & Z

            gl.Begin(OpenGL.GL_QUADS);                  // Start Drawing The Cube

            gl.Color(0.0f, 1.0f, 0.0f);                 // Set The Color To Green
            gl.Vertex(1.0f, 1.0f, -1.0f);               // Top Right Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, -1.0f);              // Top Left Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, 1.0f);               // Bottom Left Of The Quad (Top)
            gl.Vertex(1.0f, 1.0f, 1.0f);                // Bottom Right Of The Quad (Top)


            gl.Color(1.0f, 0.5f, 0.0f);                 // Set The Color To Orange
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Top Right Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Top Left Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Bottom Left Of The Quad (Bottom)
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Bottom Right Of The Quad (Bottom)

            gl.Color(1.0f, 0.0f, 0.0f);                 // Set The Color To Red
            gl.Vertex(1.0f, 1.0f, 1.0f);                // Top Right Of The Quad (Front)
            gl.Vertex(-1.0f, 1.0f, 1.0f);               // Top Left Of The Quad (Front)
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Bottom Left Of The Quad (Front)
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Bottom Right Of The Quad (Front)

            gl.Color(1.0f, 1.0f, 0.0f);                 // Set The Color To Yellow
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Bottom Left Of The Quad (Back)
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Bottom Right Of The Quad (Back)
            gl.Vertex(-1.0f, 1.0f, -1.0f);              // Top Right Of The Quad (Back)
            gl.Vertex(1.0f, 1.0f, -1.0f);               // Top Left Of The Quad (Back)

            gl.Color(0.0f, 0.0f, 1.0f);                 // Set The Color To Blue
            gl.Vertex(-1.0f, 1.0f, 1.0f);               // Top Right Of The Quad (Left)
            gl.Vertex(-1.0f, 1.0f, -1.0f);              // Top Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Bottom Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Bottom Right Of The Quad (Left)

            gl.Color(1.0f, 0.0f, 1.0f);                 // Set The Color To Violet
            gl.Vertex(1.0f, 1.0f, -1.0f);               // Top Right Of The Quad (Right)
            gl.Vertex(1.0f, 1.0f, 1.0f);                // Top Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Bottom Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Bottom Right Of The Quad (Right)
            gl.End();                                   // Done Drawing The Q

            gl.Flush();

            rtri  += 3.0f; // 0.2f;						// Increase The Rotation Variable For The Triangle
            rquad -= 3.0f; // 0.15f;						// Decrease The Rotation Variable For The Quad
        }
示例#9
0
文件: Points.cs 项目: nromik/sharpgl
        /// <summary>
        /// Draw the points.
        /// </summary>
        public override void Draw(OpenGL gl)
        {
            if(pointsRaw == null)
                return;

            //	If you want you're custom object to be drawn, then override this function.

            //	The drawing of points is very simple, go through the point array, set
            //	the intensity, draw the point.

            //	This is the first function that must be called, DoPreDraw. It basicly
            //	sets up certain settings and organises the stack so that what you draw
            //	now doesn't interfere with what you will draw next. You actually
            //	only need to draw it it returns true, when it returns false
            //	the object is actually drawn via a display list.
            if(DoPreDraw(gl))
            {
                //	This next code saves the current point attributes, then sets the point
                //	attributes for this set of points, so that the previous attributes
                //	are not lost (we restore them later).
                pointAttributes.Set(gl);

                //	Begin drawing lines.
                gl.Begin(OpenGL.POINTS);

                //	Get the points count.
                int count = pointsRaw.Length / 4;
                for(int i=0, index=0; i < count; i++,index+=4)
                {
                    //	Set the colour.
                    float intensity = pointsRaw[index + 3];
                    gl.Color(intensity, intensity, intensity, intensity);

                    //	Draw the point.
                    gl.Vertex(pointsRaw[index], pointsRaw[index+1], pointsRaw[index+2]);
                }

                //	End the drawing.
                gl.End();

                //	Restore the previous point settings.
                pointAttributes.Restore(gl);

                //	Finalise the drawing process.
                DoPostDraw(gl);
            }
        }
示例#10
0
		/// <summary>
		/// This is part of the shadow casting code, it does a shadowpass for the
		/// polygon using the specified light.
		/// </summary>
		/// <param name="gl">The OpenGL object.</param>
		/// <param name="light">The light casting the shadow.</param>
		/// <param name="visibleArray">An array of bools.</param>
		private void DoShadowPass(OpenGL gl, Vertex lightPos, bool[] visibleArray)
		{
            //  Helpful references.
            var faces = ParentPolygon.Faces;
            var vertices = ParentPolygon.Vertices;

			//	Go through each face.
			for(int i = 0; i < faces.Count; i++)
			{
				//	Get a reference to the face.
				Face face = faces[i];
				
				//	Is the face visible...
				if(visibleArray[i])
				{
					//	Go through each edge...
					for(int j = 0; j < face.Indices.Count; j++)
					{
						//	Get the neighbour of this edge.
                        int neighbourIndex = face.NeighbourIndices[j];

						//	If there's no neighbour, or the neighbour ain't visible, it's
						//	an edge...
						if(neighbourIndex == -1 || visibleArray[neighbourIndex] == false )
						{
							//	Get the edge vertices.
							Vertex v1 = vertices[face.Indices[j].Vertex];
							Vertex v2 = vertices[face.Indices[(j+1)%face.Indices.Count].Vertex];
						
							//	Create the two distant vertices.
							Vertex v3 = (v1 - lightPos) * 100;
							Vertex v4 = (v2 - lightPos) * 100;
							
							//	Draw the shadow volume.
                            gl.Begin(OpenGL.GL_TRIANGLE_STRIP);
							gl.Vertex(v1);
							gl.Vertex(v1 + v3);
							gl.Vertex(v2);
							gl.Vertex(v2 + v4);
							gl.End();
						}
					}
				}
			}			
		}
示例#11
0
        //draw the red follow me line
        public void DrawContourLine()
        {
            //gl.Color(0.98f, 0.98f, 0.50f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            ////for (int h = 0; h < ptCount; h++) gl.Vertex(guideList[h].x, 0, guideList[h].z);
            //gl.Vertex(boxA.x, 0, boxA.z);
            //gl.Vertex(boxB.x, 0, boxB.z);
            //gl.Vertex(boxC.x, 0, boxC.z);
            //gl.Vertex(boxD.x, 0, boxD.z);
            //gl.Vertex(boxA.x, 0, boxA.z);
            //gl.End();

            ////draw the guidance line
            int ptCount = guideList.Count;
            gl.LineWidth(2);
            gl.Color(0.98f, 0.2f, 0.0f);
            gl.Begin(OpenGL.GL_LINE_STRIP);
            for (int h = 0; h < ptCount; h++) gl.Vertex(guideList[h].x, 0, guideList[h].z);
            gl.End();

            ////draw the reference line
            //gl.PointSize(3.0f);
            ////if (isContourBtnOn)
            //{
            //    ptCount = stripList.Count;
            //    if (ptCount > 0)
            //    {
            //        ptCount = stripList[closestRefPatch].Count;
            //        gl.Begin(OpenGL.GL_POINTS);
            //        for (int i = 0; i < ptCount; i++)
            //        {
            //            gl.Vertex(stripList[closestRefPatch][i].x, 0, stripList[closestRefPatch][i].z);
            //        }
            //        gl.End();
            //    }
            //}


            //ptCount = conList.Count;
            //if (ptCount > 0)
            //{
            //    //draw closest point and side of line points
            //    gl.Color(0.5f, 0.900f, 0.90f);
            //    gl.PointSize(4.0f);
            //    gl.Begin(OpenGL.GL_POINTS);

            //    for (int i = 0; i < ptCount; i++)
            //    {
            //        gl.Vertex(conList[i].x, 0, conList[i].z);
            //    }

            //    gl.End();


            //    //draw closest point and side of line points
            //    gl.Color(0.35f, 0.30f, 0.90f);
            //    gl.PointSize(6.0f);
            //    gl.Begin(OpenGL.GL_POINTS);
            //    gl.Vertex(conList[closestRefPoint].x, 0, conList[closestRefPoint].z);
            //    gl.End();

            //}

        }
示例#12
0
        public void loadFloor(OpenGL gl)
        {
            gl.PushMatrix();
            gl.Translate(-100f, -300f, 550f);
            gl.Scale(80, 20, 90);

            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.BETON]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_DECAL);
            gl.MatrixMode(OpenGL.GL_TEXTURE);
            //gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PushMatrix();
            gl.Begin(OpenGL.GL_QUADS);

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

            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(30, 1, 15);
            gl.TexCoord(1, 0);
            gl.Vertex(30, 1, -15);
            gl.TexCoord(0, 0);
            gl.Vertex(-30, 1, -15);
            gl.TexCoord(0, 1);
            gl.Vertex(-30, 1, 15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(30, 1, 15);
            gl.TexCoord(1, 0);
            gl.Vertex(-30, 1, 15);
            gl.TexCoord(0, 0);
            gl.Vertex(-30, -1, 15);
            gl.TexCoord(0, 1);
            gl.Vertex(30, -1, 15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(30, -1, 15);
            gl.TexCoord(1, 0);
            gl.Vertex(30, -1, -15);
            gl.TexCoord(0, 0);
            gl.Vertex(30, 1, -15);
            gl.TexCoord(0, 1);
            gl.Vertex(30, 1, 15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(-30, -1, 15);
            gl.TexCoord(1, 0);
            gl.Vertex(-30, -1, -15);
            gl.TexCoord(0, 0);
            gl.Vertex(30, -1, -15);
            gl.TexCoord(0, 1);
            gl.Vertex(30, -1, 15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(-30, -1, -15);
            gl.TexCoord(1, 0);
            gl.Vertex(-30, -1, 15);
            gl.TexCoord(0, 0);
            gl.Vertex(-30, 1, 15);
            gl.TexCoord(0, 1);
            gl.Vertex(-30, 1, -15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(-30, 1, -15);
            gl.TexCoord(1, 0);
            gl.Vertex(30, 1, -15);
            gl.TexCoord(0, 0);
            gl.Vertex(30, -1, -15);
            gl.TexCoord(0, 1);
            gl.Vertex(-30, -1, -15);

            gl.End();

            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);

            gl.PopMatrix();
        }
示例#13
0
        private void RenderNode(Node node)
        {
            gl.PushMatrix();

            float[] matrix = new float[16] {
                node.Transform.A1, node.Transform.B1, node.Transform.C1, node.Transform.D1, node.Transform.A2, node.Transform.B2, node.Transform.C2, node.Transform.D2, node.Transform.A3, node.Transform.B3, node.Transform.C3, node.Transform.D3, node.Transform.A4, node.Transform.B4, node.Transform.C4, node.Transform.D4
            };
            gl.MultMatrix(matrix);

            if (node.HasMeshes)
            {
                foreach (int meshIndex in node.MeshIndices)
                {
                    Mesh mesh = m_scene.Meshes[meshIndex];

                    bool hasColors = mesh.HasVertexColors(0);
                    uint brojPoli  = mesh.Faces[0].IndexCount;

                    foreach (Assimp.Face face in mesh.Faces)
                    {
                        switch (face.IndexCount)
                        {
                        case 1:
                            gl.Begin(OpenGL.GL_POINTS);
                            break;

                        case 2:
                            gl.Begin(OpenGL.GL_LINES);
                            break;

                        case 3:
                            gl.Begin(OpenGL.GL_TRIANGLES);
                            break;

                        default:
                            gl.Begin(OpenGL.GL_POLYGON);
                            break;
                        }

                        for (int i = 0; i < face.IndexCount; i++)
                        {
                            uint vertexIndex = face.Indices[i];

                            if (hasColors)
                            {
                                gl.Color(mesh.GetVertexColors(0)[vertexIndex].R, mesh.GetVertexColors(0)[vertexIndex].G, mesh.GetVertexColors(0)[vertexIndex].B, mesh.GetVertexColors(0)[vertexIndex].A);
                            }
                            else
                            {
                                if (vertexIndex % 2 == 0)
                                {
                                    gl.Color(0.3f, 0.3f, 0.3f);
                                }
                                else
                                {
                                    gl.Color(0.4f, 0.4f, 0.4f);
                                }
                            }

                            gl.Vertex(mesh.Vertices[vertexIndex].X, mesh.Vertices[vertexIndex].Y, mesh.Vertices[vertexIndex].Z);
                        }
                        gl.End();
                    }
                }
            }

            for (int i = 0; i < node.ChildCount; i++)
            {
                RenderNode(node.Children[i]);
            }
            gl.PopMatrix();
        }
示例#14
0
        public void DrawParallelepiped(OpenGL gl, float x, float y, float z, float widthX, float widthY, float widthZ)
        {
            gl.Begin(OpenGL.GL_QUADS);

            // bottom facet
            gl.Normal(0.0f, -1.0f, 0.0f);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(x, y, z);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(x, y, z + widthZ);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(x + widthX, y, z + widthZ);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(x + widthX, y, z);


            // top facet
            gl.Normal(0.0f, 1.0f, 0.0f);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(x, y + widthY, z);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(x, y + widthY, z + widthZ);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(x + widthX, y + widthY, z + widthZ);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(x + widthX, y + widthY, z);

            // right facet
            gl.Normal(0.0f, 0.0f, 1.0f);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(x, y, z + widthZ);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(x + widthX, y, z + widthZ);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(x + widthX, y + widthY, z + widthZ);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(x, y + widthY, z + widthZ);

            // left facet
            gl.Normal(0.0f, 0.0f, -1.0f);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(x, y, z);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(x + widthX, y, z);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(x + widthX, y + widthY, z);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(x, y + widthY, z);

            // back facet
            gl.Normal(1.0f, 0.0f, 0.0f);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(x + widthX, y, z);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(x + widthX, y, z + widthZ);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(x + widthX, y + widthY, z + widthZ);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(x + widthX, y + widthY, z);

            // front facet
            gl.Normal(-1.0f, 0.0f, 0.0f);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(x, y, z);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(x, y, z + widthZ);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(x, y + widthY, z + widthZ);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(x, y + widthY, z);

            gl.End();
        }
示例#15
0
        public override void Draw(OpenGL gl)
        {
            gl.Color(lineColor.R / 255.0, lineColor.G / 255.0, lineColor.B / 255.0);
            gl.PointSize(lineWidth);
            if (isDrawn)
            {
                gl.Begin(OpenGL.GL_POINTS);
                foreach (var v in vertexs)
                {
                    gl.Vertex(v.X, v.Y);
                }
                gl.End();
                gl.Flush();
                return;
            }
            isDrawn = true;
            vertexs = new List <Point>();
            gl.Begin(OpenGL.GL_POINTS);
            /* Xác định các đại lượng cơ bản của hình ellipse */
            /* Bán kính rx, ry*/
            int rX = Math.Abs(startPoint.X - endPoint.X) / 2;
            int rY = Math.Abs(startPoint.Y - endPoint.Y) / 2;
            int rX2 = rX * rX;
            int rY2 = rY * rY;
            int rX22 = 2 * rX2, rY22 = 2 * rY2;
            /* Tâm hình ellipse*/
            int xCenter = (startPoint.X + endPoint.X) / 2;
            int yCenter = (startPoint.Y + endPoint.Y) / 2;
            int x = 0, y = rY;
            int pX = 0, pY = rX22 * y;

            /* Vẽ đối xứng qua tâm*/
            gl.Vertex(xCenter + x, gl.RenderContextProvider.Height - (yCenter + y));
            gl.Vertex(xCenter - x, gl.RenderContextProvider.Height - (yCenter + y));
            gl.Vertex(xCenter + x, gl.RenderContextProvider.Height - (yCenter - y));
            gl.Vertex(xCenter - x, gl.RenderContextProvider.Height - (yCenter - y));
            vertexs.Add(new Point(xCenter + x, gl.RenderContextProvider.Height - (yCenter + y)));
            vertexs.Add(new Point(xCenter - x, gl.RenderContextProvider.Height - (yCenter + y)));
            vertexs.Add(new Point(xCenter + x, gl.RenderContextProvider.Height - (yCenter - y)));
            vertexs.Add(new Point(xCenter - x, gl.RenderContextProvider.Height - (yCenter - y)));
            /* Vùng 1: dy/dx <= 1*/
            int p = (int)(Math.Round(rY2 - rX2 * rY + 0.25 * rX2));

            while (pX < pY)
            {
                x++;
                pX += rY22;
                if (p < 0)
                {
                    p += rY2 + pX;
                }
                else
                {
                    y--;
                    pY -= rX22;
                    p  += rY2 + pX - pY;
                }
                /* Vẽ đối xứng qua tâm*/
                gl.Vertex(xCenter + x, gl.RenderContextProvider.Height - (yCenter + y));
                gl.Vertex(xCenter - x, gl.RenderContextProvider.Height - (yCenter + y));
                gl.Vertex(xCenter + x, gl.RenderContextProvider.Height - (yCenter - y));
                gl.Vertex(xCenter - x, gl.RenderContextProvider.Height - (yCenter - y));
                vertexs.Add(new Point(xCenter + x, gl.RenderContextProvider.Height - (yCenter + y)));
                vertexs.Add(new Point(xCenter - x, gl.RenderContextProvider.Height - (yCenter + y)));
                vertexs.Add(new Point(xCenter + x, gl.RenderContextProvider.Height - (yCenter - y)));
                vertexs.Add(new Point(xCenter - x, gl.RenderContextProvider.Height - (yCenter - y)));
            }

            /* Vùng 2*/
            p = (int)(Math.Round(rY2 * (x + 0.5) * (x + 0.5) + rX2 * (y - 1) * (y - 1) - rX2 * rY2));
            while (y > 0)
            {
                y--;
                pY -= rX22;
                if (p > 0)
                {
                    p += rX2 - pY;
                }
                else
                {
                    x++;
                    pX += rY22;
                    p  += rX2 - pY + pX;
                }
                /* Vẽ đối xứng qua tâm*/
                gl.Vertex(xCenter + x, gl.RenderContextProvider.Height - (yCenter + y));
                gl.Vertex(xCenter - x, gl.RenderContextProvider.Height - (yCenter + y));
                gl.Vertex(xCenter + x, gl.RenderContextProvider.Height - (yCenter - y));
                gl.Vertex(xCenter - x, gl.RenderContextProvider.Height - (yCenter - y));
                vertexs.Add(new Point(xCenter + x, gl.RenderContextProvider.Height - (yCenter + y)));
                vertexs.Add(new Point(xCenter - x, gl.RenderContextProvider.Height - (yCenter + y)));
                vertexs.Add(new Point(xCenter + x, gl.RenderContextProvider.Height - (yCenter - y)));
                vertexs.Add(new Point(xCenter - x, gl.RenderContextProvider.Height - (yCenter - y)));
            }

            gl.End();
            gl.Flush();
        }
示例#16
0
        public override void Draw(OpenGL gl)
        {
            gl.Color(lineColor.R / 255.0, lineColor.G / 255.0, lineColor.B / 255.0);
            gl.PointSize(lineWidth);
            if (isDrawn)
            {
                gl.Begin(OpenGL.GL_POINTS);
                foreach (var v in vertexs)
                {
                    gl.Vertex(v.X, v.Y);
                }
                gl.End();
                gl.Flush();
                return;
            }
            isDrawn = true;
            vertexs = new List <Point>();
            gl.Begin(OpenGL.GL_POINTS);

            int r = Math.Abs(startPoint.X - endPoint.X);
            int centerX = startPoint.X, centerY = startPoint.Y;

            int x = 0, y = r;
            int x2 = 2 * x;
            int y2 = 2 * y;
            int p  = (int)Math.Round(5.0 / 4.0 - (double)r);

            /* Vẽ đối xứng qua tâm */
            gl.Vertex(centerX + x, gl.RenderContextProvider.Height - (centerY + y));
            gl.Vertex(centerX - x, gl.RenderContextProvider.Height - (centerY - y));
            gl.Vertex(centerX - r, gl.RenderContextProvider.Height - (centerY - 0));
            gl.Vertex(centerX + r, gl.RenderContextProvider.Height - (centerY + 0));
            /* Thêm vào list Vertex */
            vertexs.Add(new Point(centerX + x, gl.RenderContextProvider.Height - (centerY + y)));
            vertexs.Add(new Point(centerX - x, gl.RenderContextProvider.Height - (centerY - y)));
            vertexs.Add(new Point(centerX - r, gl.RenderContextProvider.Height - (centerY - 0)));
            vertexs.Add(new Point(centerX + r, gl.RenderContextProvider.Height - (centerY + 0)));
            /* Tiến hành vẽ các điểm trên đường tròn */
            while (x < y)
            {
                x++;
                x2 = 2 * x;
                if (p < 0)
                {
                    p = p + x2 + 1;
                }
                else
                {
                    y--;
                    y2 = 2 * y;
                    p  = p + x2 - y2 + 1;
                }
                /* Vẽ đối xứng qua tâm*/
                gl.Vertex(centerX + x, gl.RenderContextProvider.Height - (centerY + y));
                gl.Vertex(centerX - x, gl.RenderContextProvider.Height - (centerY + y));
                gl.Vertex(centerX + x, gl.RenderContextProvider.Height - (centerY - y));
                gl.Vertex(centerX - x, gl.RenderContextProvider.Height - (centerY - y));
                /* điểm đối xứng với (x,y) qua đường thẳng y = x */
                int xSym = (x + y) - x;
                int ySym = (x + y) - y;
                gl.Vertex(centerX + xSym, gl.RenderContextProvider.Height - (centerY + ySym));
                gl.Vertex(centerX - xSym, gl.RenderContextProvider.Height - (centerY + ySym));
                gl.Vertex(centerX + xSym, gl.RenderContextProvider.Height - (centerY - ySym));
                gl.Vertex(centerX - xSym, gl.RenderContextProvider.Height - (centerY - ySym));
                vertexs.Add(new Point(centerX + x, gl.RenderContextProvider.Height - (centerY + y)));
                vertexs.Add(new Point(centerX - x, gl.RenderContextProvider.Height - (centerY + y)));
                vertexs.Add(new Point(centerX + x, gl.RenderContextProvider.Height - (centerY - y)));
                vertexs.Add(new Point(centerX - x, gl.RenderContextProvider.Height - (centerY - y)));
                vertexs.Add(new Point(centerX + xSym, gl.RenderContextProvider.Height - (centerY + ySym)));
                vertexs.Add(new Point(centerX - xSym, gl.RenderContextProvider.Height - (centerY + ySym)));
                vertexs.Add(new Point(centerX + xSym, gl.RenderContextProvider.Height - (centerY - ySym)));
                vertexs.Add(new Point(centerX - xSym, gl.RenderContextProvider.Height - (centerY - ySym)));
            }

            gl.End();
            gl.Flush();
        }
示例#17
0
        public void DrawCube(OpenGL gl, byte r = 28, byte g = 120, byte b = 186)
        {
            //Line
            gl.LineWidth(2);
            gl.Color(0, 0, 0);
            gl.Begin(OpenGL.GL_LINE_LOOP);
            //Front face
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);

            //Right face
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y + this.Scale.y, this.Position.z - this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y - this.Scale.y, this.Position.z - this.Scale.z);

            //Back face
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z - this.Scale.z);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z - this.Scale.z);
            //Left face

            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);

            gl.End();

            gl.Begin(OpenGL.GL_LINE_LOOP);
            //Top face
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z - this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y + this.Scale.y, this.Position.z - this.Scale.z);
            gl.End();

            gl.Begin(OpenGL.GL_LINE_LOOP);
            //Bottom face
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z - this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y - this.Scale.y, this.Position.z - this.Scale.z);
            gl.End();

            //POLYGON
            gl.Color(r, g, b);
            gl.Begin(OpenGL.GL_TRIANGLE_STRIP);
            //Front face
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);

            //Right face
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y + this.Scale.y, this.Position.z - this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y - this.Scale.y, this.Position.z - this.Scale.z);

            //Back face
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z - this.Scale.z);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z - this.Scale.z);
            //Left face

            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);
            gl.End();

            gl.Begin(OpenGL.GL_TRIANGLE_STRIP);
            //Top face
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y + this.Scale.y, this.Position.z + this.Scale.z);
            //gl.Color(0, 0, 0);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y + this.Scale.y, this.Position.z - this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y + this.Scale.y, this.Position.z - this.Scale.z);
            gl.End();

            gl.Begin(OpenGL.GL_TRIANGLE_STRIP);
            //Bottom face
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y - this.Scale.y, this.Position.z + this.Scale.z);
            gl.Vertex(this.Position.x - this.Scale.x, this.Position.y - this.Scale.y, this.Position.z - this.Scale.z);
            gl.Vertex(this.Position.x + this.Scale.x, this.Position.y - this.Scale.y, this.Position.z - this.Scale.z);
            gl.End();

            UpdateMotion();
        }
示例#18
0
文件: Polygon.cs 项目: nromik/sharpgl
        /// <summary>
        /// This function draws the polygon.
        /// </summary>
        /// <param name="gl">OpenGL.</param>
        public override void Draw(OpenGL gl)
        {
            if(DoPreDraw(gl))
            {
                polyAttributes.Set(gl);

                foreach(Face face in faces)
                {
                    //	Begin drawing a polygon.
                    if(face.Indices.Count == 2)
                        gl.Begin(OpenGL.LINES);
                    else
                        gl.Begin(OpenGL.POLYGON);

                    foreach(Index index in face.Indices)
                    {
                        //	Set a texture coord (if any).
                        if(index.UV != -1)
                            gl.TexCoord(uvs[index.UV]);

                        //	Set a normal, or generate one.
                        if(index.Normal != -1)
                            gl.Normal(normals[index.Normal]);
                        else
                        {
                            //	Do we have enough vertices for a normal?
                            if(face.Indices.Count >= 3)
                            {
                                //	Create a normal.
                                Vertex vNormal = face.GetSurfaceNormal(this);
                                vNormal.UnitLength();

                                //	Add it to the normals, setting the index for next time.
                                index.Normal = normals.Add(new Normal(vNormal));

                                gl.Normal(vNormal);
                            }
                        }

                        //	Set the vertex.
                        gl.Vertex(vertices[index.Vertex]);
                    }

                    gl.End();
                }

                //	If the current context is edit vertices, draw the vertices.
                if(currentContext == Context.EditVertices)
                {
                    //	Push all the attributes.
                    gl.PushAttrib(OpenGL.ALL_ATTRIB_BITS);

                    //	Set the colour to red, large points, no lighting.
                    gl.Color(1, 0, 0, 1);
                    gl.PointSize(5);
                    gl.Disable(OpenGL.LIGHTING);

                    //	Draw the control points.
                    for(int point = 0; point < vertices.Count; point++)
                    {
                        //	Name the point, then draw it.
                        gl.PushName((uint)point);

                        gl.Begin(OpenGL.POINTS);
                        gl.Vertex(vertices[point]);
                        gl.End();
                        gl.PopName();
                    }

                    //	Restore the attributes.
                    gl.PopAttrib();
                }

                //	If the current context is edit normals, draw the normals.
                if(currentContext == Context.EditNormals)
                {
                    //	We're going to disable lighting.
                    Attributes.Lighting lighting = new Attributes.Lighting();
                    lighting.Enable = false;
                    lighting.Set(gl);

                    gl.Color(1, 0, 0);
                    gl.Begin(OpenGL.LINES);

                    //	Draw the normals points.
                    foreach(Face face in faces)
                    {
                        foreach(Index index in face.Indices)
                        {
                            if(index.Normal == -1)
                                continue;
                            //	Translate to that vertex.
                            Vertex v = vertices[index.Vertex];
                            gl.PushName((uint)index.Normal);
                            gl.Vertex(v);
                            gl.Vertex(v + normals[index.Normal]);
                            gl.PopName();
                        }
                    }

                    gl.End();

                    lighting.Restore(gl);
                }

                if(currentContext == Context.EditFaces)
                {
                    for(int i = 0; i<Faces.Count; i++)
                    {
                        //	Push the face name.
                        gl.PushName((uint)i);

                        //	Set the parent poly.
                        faces[i].parentpoly = this;

                        //	Draw it.
                        ((IInteractable)faces[i]).DrawPick(gl);

                        //	Pop the name.
                        gl.PopName();
                    }

                }

                //	Draw normals if we have to.
                if(drawNormals)
                {
                    //	Set the colour to red.
                    gl.PushAttrib(OpenGL.ALL_ATTRIB_BITS);
                    gl.Color(1, 0, 0, 1);
                    gl.Disable(OpenGL.LIGHTING);

                    //	Go through each face.
                    foreach(Face face in faces)
                    {
                        //	Go though each index.
                        foreach(Index index in face.Indices)
                        {
                            //	Make sure it's got a normal, and a vertex.
                            if(index.Normal != -1 && index.Vertex != -1)
                            {
                                //	Get the vertex.
                                Vertex vertex = vertices[index.Vertex];

                                //	Get the normal vertex.
                                Normal normal = normals[index.Normal];
                                Vertex vertex2 = vertex + normal;

                                gl.Begin(OpenGL.LINES);
                                gl.Vertex(vertex);
                                gl.Vertex(vertex2);
                                gl.End();
                            }
                        }
                    }

                    //	Restore the attributes.
                    gl.PopAttrib();
                }

                polyAttributes.Restore(gl);

                DoPostDraw(gl);
            }
        }
示例#19
0
        public void DrawBasketBall(OpenGL gl, int Resolution = 50, byte r = 28, byte g = 120, byte b = 186)
        {
            this.Type  = "Circle";
            Resolution = (int)GameUtils.Constrain(Resolution, 10, 100);

            gl.Color(r, g, b);

            //Main Circle
            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int ii = 0; ii < Resolution; ii++)
            {
                double angle = 2.0f * Math.PI * ii / Resolution;
                double x     = Radius * Math.Cos(angle);
                double y     = Radius * Math.Sin(angle);
                gl.Vertex(x + this.Position.x, y + this.Position.y, this.Position.z);
            }
            gl.End();

            //Circle Center
            gl.PushMatrix();
            gl.Translate(this.Position.x, this.Position.y, this.Position.z);
            gl.Rotate(0, 0, this.Rotation);
            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int ii = 0; ii < Resolution; ii++)
            {
                double angle = 2.0f * Math.PI * ii / Resolution;
                double x     = Radius * Math.Sin(angle);
                double z     = Radius * Math.Cos(angle);

                gl.Vertex(x, 0, z);
            }
            gl.End();
            gl.PopMatrix();

            //Circle perpendicular to center
            gl.PushMatrix();
            gl.Translate(this.Position.x, this.Position.y, this.Position.z);
            gl.Rotate(0, 0, this.Rotation - 90);
            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int ii = 0; ii < Resolution; ii++)
            {
                double angle = 2.0f * Math.PI * ii / Resolution;
                double x     = Radius * Math.Sin(angle);
                double z     = Radius * Math.Cos(angle);

                gl.Vertex(x, 0, z);
            }
            gl.End();
            gl.PopMatrix();

            //Draw Right Curve
            gl.Color(0.7, 0.5, 0);
            gl.Begin(OpenGL.GL_POLYGON);
            for (int ii = 0; ii < Resolution; ii++)
            {
                double angle = 2.0f * Math.PI * ii / Resolution;
                double x     = Radius * Math.Cos(angle);
                double y     = Radius * Math.Sin(angle);
                gl.Vertex(x + this.Position.x, y + this.Position.y, this.Position.z);
            }
            gl.End();

            UpdateMotion();
        }
示例#20
0
        public RoundColumn(OpenGL gl, string name, Circle circle, float bottomPoint, float topPoint) : base()
        {
            this.Name        = name;
            this.circle      = circle;
            this.bottomPoint = bottomPoint;
            this.topPoint    = topPoint;

            boundingVolumeHelper = new BoundingVolumeHelper();

            Vertex startPoint  = circle.StartPoint;
            Vertex secondPoint = circle.SecondPoint;
            Vertex endPoint    = circle.EndPoint;

            // ==== Create bottom circle of column ====
            startPoint.Z  = bottomPoint;
            secondPoint.Z = bottomPoint;
            endPoint.Z    = bottomPoint;


            DepthBufferAttributes depthBufferAttributes = new DepthBufferAttributes();

            depthBufferAttributes.DepthFunction   = DepthFunction.LessThanOrEqual;
            depthBufferAttributes.EnableDepthTest = true;

            PolygonAttributes polygonAttributes = new PolygonAttributes();

            polygonAttributes.PolygonMode = PolygonMode.Lines;

            polygonAttributes.EnableOffsetLine = true;
            polygonAttributes.OffsetFactor     = -.9f;
            polygonAttributes.OffsetBias       = -.9f;

            OpenGLAttributesEffect openGLAttributesEffect = new OpenGLAttributesEffect();

            openGLAttributesEffect.PolygonAttributes = polygonAttributes;
            //openGLAttributesEffect.DepthBufferAttributes = depthBufferAttributes;

            Circle bottomCircle = new Circle(new Vertex(startPoint), new Vertex(secondPoint), new Vertex(endPoint));

            bottomCircle.Material = Materials.DarkGrey(gl);
            bottomCircle.AddEffect(openGLAttributesEffect);
            AddChild(bottomCircle);

            // ==== Create top circle of column ====
            startPoint.Z  = topPoint;
            secondPoint.Z = topPoint;
            endPoint.Z    = topPoint;

            Circle topCircle = new Circle(new Vertex(startPoint), new Vertex(secondPoint), new Vertex(endPoint));

            topCircle.Material = Materials.DarkGrey(gl);
            topCircle.AddEffect(openGLAttributesEffect);
            AddChild(topCircle);

            // ==== Create column body ====
            // Create the display list.

            this.Material = Materials.Purple(gl);

            displayList = new DisplayList();

            // Generate the display list and
            displayList.Generate(gl);

            displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute);


            gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL);
            gl.Begin(BeginMode.QuadStrip);
            double angle = 0;

            while (angle <= 2 * Math.PI * 1.01)
            {
                double xTmp = circle.Radius * Math.Cos(angle);
                double yTmp = circle.Radius * Math.Sin(angle);

                gl.Vertex(circle.Center.X + xTmp, circle.Center.Y + yTmp, bottomPoint);
                gl.Vertex(circle.Center.X + xTmp, circle.Center.Y + yTmp, topPoint);
                angle += 0.1;
            }
            gl.End();

            // End the display list.
            displayList.End(gl);
        }
示例#21
0
        public virtual void DrawCircle(OpenGL gl)
        {
            //	Start drawing a line.
            gl.Begin(OpenGL.LINE_LOOP);

            //	Make a circle of points.
            for (int i = 0; i < 12; i++)
            {
                double angle = 2 * Math.PI * i / 12;

                //	Draw the point.
                gl.Vertex(Math.Cos(angle), 0, Math.Sin(angle));
            }

            //	End the line drawing.
            gl.End();
        }
示例#22
0
        /// <summary>
        ///  Iscrtavanje OpenGL kontrole.
        /// </summary>
        public void Draw(OpenGL gl)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.Viewport(0, 0, m_width, m_height);

            gl.PushMatrix();
            gl.LookAt(-m_sceneDistance, 0f, 0f, 0f, 0f, 0, 0f, 1f, 0f);//sa leve strane je - deo X-ose
            // gl.Translate(0.0f, 0.0f, -m_sceneDistance);
            gl.Rotate(m_xRotation, 0.0f, 0.0f, 1.0f);
            gl.Rotate(m_yRotation, 0.0f, 1.0f, 0.0f);

            ///REFLEKTOR
            float[] rc = new float[] { r, g, b, 1.0f };

            //BOJA REGLEKTORA
            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_AMBIENT, rc);
            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_DIFFUSE, rc);
            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_SPECULAR, rc);

            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_POSITION, new float[] { 0, 100, 195, 1.0f });       //svetlo iznad mola
            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_SPOT_DIRECTION, new float[] { 0.0f, -1.0f, 0.0f }); //sija na dole

            //podloga vode
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.WATER]); //VODA ZA PODLOGU
            //bindujemo teksturu
            gl.MatrixMode(OpenGL.GL_TEXTURE);                                            // UINUTAR TEXT MATRICE SE SKALIRA ,mora da bi mogle transformacije sa teksturama
            gl.PushMatrix();                                                             //unutar texture space se sad sve ovo radi
            gl.Scale(10, 10, 1);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);                                          //vracamo na model view

            gl.PushMatrix();
            //gl.Translate(0.0f, 0.0f, -120f);
            gl.Begin(OpenGL.GL_QUADS);
            gl.Normal(0f, 1f, 0f); //normala za podlogu
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.TexCoord(0f, 0f);   //koordinate teksture za podlogu
            gl.Vertex(200f, -0.5f, -200f);
            gl.TexCoord(0f, 1f);
            gl.Vertex(-200f, -0.5f, -200f);
            gl.TexCoord(1f, 1f);
            gl.Vertex(-200f, -0.5f, 200f);
            gl.TexCoord(1f, 0f);
            gl.Vertex(200f, -0.5f, 200f);
            gl.End();
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.WOOD]); //drvo za mol i stubove

            if (Modulate)
            {
                gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            }


            gl.Translate(0.0f, 0.0f, 120f);
            //cube
            Cube cube = new Cube();

            gl.PushMatrix();
            gl.Color(0.5f, 0.5f, 0.5f);
            gl.Translate(0.0f, 20.0f, 70.0f);
            gl.Scale(30.0f, 5.0f, 30.0f); //dimenzije
            cube.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            //gl.Scale(size, size, size); //dimenzije

            //cilindar1
            gl.PushMatrix();
            gl.Translate(-20.0f, -2.0f, 90.0f);
            gl.Translate(0, 25, 0);     //I VRATI ZA 25 NA GORE DA GORNNJA IVICA BUDE ISPOD KOCKE (3)
            gl.Scale(size, size, size); //SKLIARA SE ZA ONO SA SLEJDERA (2)
            gl.Translate(0, -25, 0);    //VISINA IM JE 25, ZATO -25 DA BUDE GORANJA IVICA NA 0 JER TADA SKALIRANJE SIRI STUB SAMO DOLE (1)

            gl.Rotate(-90f, 0f, 0f);

            gl.Scale(5.0f, 5.0f, 5.0f); //dimenzije
            Cylinder cil = new Cylinder();

            cil.TextureCoords = true;//KOORDIANTE TEKSTURA ZA CILINDRE
            cil.CreateInContext(gl);
            cil.BaseRadius = 0.5;
            cil.Height     = 5;
            cil.TopRadius  = 0.5;
            cil.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //cilindar2
            gl.PushMatrix();
            gl.Translate(20.0f, -2.0f, 90.0f);
            gl.Translate(0, 25, 0);
            gl.Scale(size, size, size);//SKALIRANJE
            gl.Translate(0, -25, 0);
            gl.Rotate(-90f, 0f, 0f);
            gl.Scale(5.0f, 5.0f, 5.0f); //dimenzije
            cil.CreateInContext(gl);
            cil.BaseRadius = 0.5;
            cil.Height     = 5;
            cil.TopRadius  = 0.5;
            cil.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //cilindar3
            gl.PushMatrix();
            gl.Translate(20.0f, -2.0f, 50.0f);
            gl.Translate(0, 25, 0);
            gl.Scale(size, size, size);//SKALIRANJE
            gl.Translate(0, -25, 0);
            gl.Rotate(-90f, 0f, 0f);
            gl.Scale(5.0f, 5.0f, 5.0f); //dimenzije
            cil.CreateInContext(gl);
            cil.BaseRadius = 0.5;
            cil.Height     = 5;
            cil.TopRadius  = 0.5;
            cil.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //cilindar4
            gl.PushMatrix();
            gl.Translate(-20.0f, -2.0f, 50.0f);
            gl.Translate(0, 25, 0);
            gl.Scale(size, size, size);//SKALIRANJE
            gl.Translate(0, -25, 0);
            gl.Rotate(-90f, 0f, 0f);
            gl.Scale(5.0f, 5.0f, 5.0f); //dimenzije
            cil.CreateInContext(gl);
            cil.BaseRadius = 0.5;
            cil.Height     = 5;
            cil.TopRadius  = 0.5;
            cil.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();


            //cube stepenice(vrata)
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.METAL]); //metal za stepenice
            gl.PushMatrix();
            gl.Translate(0.0f + shipOffsetX, 0.0f, 50.0f + shipOffsetZ);                 //pomera brod
            gl.Rotate(0, shipRotation, 0);
            Cube cubeStairs = new Cube();

            gl.PushMatrix();
            gl.Color(0.5f, 0.50f, 0.50f);
            gl.Translate(0.0f, stairsY, -53.0f); //poemri da se ivica poklopi sa brodom, stairsY KAD NEMA ANIMACIJE JE 40, TOKOM ANIMACIJE JE NA POCETKU -20 KASNIJE SE PODIZE
            gl.Rotate(-stairs, 1f, 0.0f, 0.0f);  //ROTIRA ZA ONO SA SLAJDERA, TOKOM ANIMACIJE SE ISTO OVO MENJA
            gl.Scale(30.0f, 1.0f, 30.0f);        //dimenzije
            gl.Translate(0, 1, 1);               //pomeri se da bi se skalirao samo na gore u prema molu
            cube.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD); //za brod je stapanje ADD
            gl.Translate(-20.0f, 0f, 0.0f);                                              //priblizi se brod molu
            gl.Color(0.5f, 0.50f, 0.50f);

            gl.Scale(0.2f, 0.32f, 0.32f);
            m_scene.Draw();

            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_DECAL); //ZA OSTALO OPET VRATIMO NA DECAL
            gl.PopMatrix();



            gl.PopMatrix();
            // Oznaci kraj iscrtavanja
            //Tekst
            gl.PushMatrix();
            gl.DrawText(m_width - 200, 90, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Predmet:Racunarska grafika");
            gl.DrawText(m_width - 200, 90, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "_______________________");
            gl.DrawText(m_width - 200, 70, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Sk.god: 2020/21.");
            gl.DrawText(m_width - 200, 70, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "______________");
            gl.DrawText(m_width - 200, 50, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Ime: Maja ");
            gl.DrawText(m_width - 200, 50, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "________");
            gl.DrawText(m_width - 200, 30, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Prezime: Dragojlovic");
            gl.DrawText(m_width - 200, 30, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "________________");
            gl.DrawText(m_width - 200, 10, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Sifra zad: 10.1");
            gl.DrawText(m_width - 200, 10, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "____________");
            gl.PopMatrix();
            gl.Flush();
        }
示例#23
0
        /// <summary>
        /// Renders the scene in immediate mode.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public void RenderImmediateMode(OpenGL gl)
        {
            //  Setup the modelview matrix.
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.LoadIdentity();
            gl.MultMatrix(modelviewMatrix.to_array());

            //  Push the polygon attributes and set line mode.
            gl.PushAttrib(OpenGL.GL_POLYGON_BIT);
            gl.PolygonMode(FaceMode.FrontAndBack, PolygonMode.Lines);

            //  Render the trefoil.
            var vertices = trefoilKnot.Vertices;
            gl.Begin(BeginMode.Triangles);
            foreach (var index in trefoilKnot.Indices)
                gl.Vertex(vertices[index].x, vertices[index].y, vertices[index].z);
            gl.End();

            //  Pop the attributes, restoring all polygon state.
            gl.PopAttrib();
        }
示例#24
0
        private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args)
        {
            gl = (gl == null) ? this.openGLControl1.OpenGL : gl;
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
            gl.LoadIdentity();                                                 // Reset The View

            gl.Viewport(0, 0, this.Width, this.Height);
            gl.MatrixMode(MatrixMode.Projection);
            gl.Ortho(-this.Width / 2, this.Width / 2, -this.Height / 2, this.Height / 2, -1, 1);

            gl.Enable(OpenGL.GL_TEXTURE_2D);

            switch (mode)
            {
            case Mode.Normal:
                texture0.Bind(gl);
                break;

            case Mode.E:
                texture1.Bind(gl);
                break;

            case Mode.NE:
                texture2.Bind(gl);
                break;

            case Mode.N:
                texture3.Bind(gl);
                break;

            case Mode.NW:
                texture4.Bind(gl);
                break;

            case Mode.W:
                texture5.Bind(gl);
                break;

            case Mode.SW:
                texture6.Bind(gl);
                break;

            case Mode.S:
                texture7.Bind(gl);
                break;

            case Mode.SE:
                texture8.Bind(gl);
                break;

            case Mode.W_LP1:
                texture9.Bind(gl);
                break;

            case Mode.W_LP2:
                texture10.Bind(gl);
                break;

            case Mode.W_LP3:
                texture11.Bind(gl);
                break;

            default:
                break;
            }

            gl.Begin(BeginMode.Quads);
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-dd.width / 2 - 80, -dd.height / 2 - 50);
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(dd.width / 2 - 80, -dd.height / 2 - 50);
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(dd.width / 2 - 80, dd.height / 2 - 50);
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-dd.width / 2 - 80, dd.height / 2 - 50);
            gl.End();

            gl.Flush();
        }
示例#25
0
        /// <summary>
        ///  Rekurzivna metoda zaduzena za iscrtavanje objekata u sceni koji su reprezentovani cvorovima.
        ///  U zavisnosti od karakteristika objekata podesavaju se odgovarajuce promenjive stanja (GL_LIGHTING, GL_COLOR_MATERIAL, GL_TEXTURE_2D).
        /// </summary>
        /// <param name="node">Cvor koji ce biti iscrtan.</param>
        private void RenderNode(Node node)
        {
            gl.PushMatrix();

            // Primena tranformacija, definisanih za dati cvor.
            float[] matrix = new float[16] {
                node.Transform.A1, node.Transform.B1, node.Transform.C1, node.Transform.D1, node.Transform.A2, node.Transform.B2, node.Transform.C2, node.Transform.D2, node.Transform.A3, node.Transform.B3, node.Transform.C3, node.Transform.D3, node.Transform.A4, node.Transform.B4, node.Transform.C4, node.Transform.D4
            };
            gl.MultMatrix(matrix);
            x++;
            // Iscrtavanje objekata u sceni koji su reprezentovani datim cvorom.
            if (node.HasMeshes)
            {
                foreach (int meshIndex in node.MeshIndices)
                {
                    Mesh mesh = m_scene.Meshes[meshIndex];
                    y++;
                    bool hasColors = mesh.HasVertexColors(0);
                    uint brojPoli  = mesh.Faces[0].IndexCount;

                    // Iscrtavanje primitiva koji cine dati objekat.
                    // U zavisnosti od broja temena, moguce je iscrtavanje tacaka, linija, trouglova ili poligona.
                    foreach (Assimp.Face face in mesh.Faces)
                    {
                        //gl.Begin(OpenGL.GL_TRIANGLES);
                        switch (face.IndexCount)
                        {
                        case 1:
                            gl.Begin(OpenGL.GL_POINTS);
                            break;

                        case 2:
                            gl.Begin(OpenGL.GL_LINES);
                            break;

                        case 3:
                            gl.Begin(OpenGL.GL_TRIANGLES);
                            break;

                        default:
                            gl.Begin(OpenGL.GL_POLYGON);
                            break;
                        }
                        //gl.Begin(OpenGL.GL_TRIANGLES);

                        for (int i = 0; i < face.IndexCount; i++)
                        {
                            uint vertexIndex = face.Indices[i];

                            // Definisanje boje temena.
                            if (hasColors)
                            {
                                gl.Color(mesh.GetVertexColors(0)[vertexIndex].R, mesh.GetVertexColors(0)[vertexIndex].G, mesh.GetVertexColors(0)[vertexIndex].B, mesh.GetVertexColors(0)[vertexIndex].A);
                            }
                            else
                            {
                                // Permutacija boje poligona u zavisnosti od parnosti indeksa
                                if (vertexIndex % 2 == 0)
                                {
                                    gl.Color(0.3f, 0.3f, 0.3f);
                                }
                                else
                                {
                                    gl.Color(0.4f, 0.4f, 0.4f);
                                }
                            }
                            // Definisanje temena primitive.
                            gl.Vertex(mesh.Vertices[vertexIndex].X, mesh.Vertices[vertexIndex].Y, mesh.Vertices[vertexIndex].Z);
                        }
                        gl.End();
                    }
                }
            }

            // Rekurzivno scrtavanje podcvorova datog cvora.
            for (int i = 0; i < node.ChildCount; i++)
            {
                RenderNode(node.Children[i]);
            }
            gl.PopMatrix();
        }
示例#26
0
        /// <summary>
        /// Render to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        public virtual void Render(OpenGL gl, RenderMode renderMode)
        {
            //  If we're frozen, use the helper.
            if (freezableHelper.IsFrozen)
            {
                freezableHelper.Render(gl);
                return;
            }

            //  Go through each face.
            foreach (Face face in faces)
            {
                //  If the face has its own material, push it.
                if (face.Material != null)
                {
                    face.Material.Push(gl);
                }

                //	Begin drawing a polygon.
                if (face.Indices.Count == 2)
                {
                    gl.Begin(OpenGL.GL_LINES);
                }
                else
                {
                    gl.Begin(OpenGL.GL_POLYGON);
                }

                foreach (Index index in face.Indices)
                {
                    //	Set a texture coord (if any).
                    if (index.UV != -1)
                    {
                        gl.TexCoord(uvs[index.UV]);
                    }

                    //	Set a normal, or generate one.
                    if (index.Normal != -1)
                    {
                        gl.Normal(normals[index.Normal]);
                    }
                    else
                    {
                        //	Do we have enough vertices for a normal?
                        if (face.Indices.Count >= 3)
                        {
                            //	Create a normal.
                            Vertex vNormal = face.GetSurfaceNormal(this);
                            vNormal.UnitLength();

                            // todo use auto smoothing instead
                            //	Add it to the normals, setting the index for next time.
                            normals.Add(vNormal);
                            index.Normal = normals.Count - 1;

                            gl.Normal(vNormal);
                        }
                    }

                    //	Set the vertex.
                    gl.Vertex(vertices[index.Vertex]);
                }

                gl.End();

                //  If the face has its own material, pop it.
                if (face.Material != null)
                {
                    face.Material.Pop(gl);
                }
            }

            //	Draw normals if we have to.
            if (drawNormals)
            {
                //	Set the colour to red.
                gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);
                gl.Color(1, 0, 0, 1);
                gl.Disable(OpenGL.GL_LIGHTING);

                //	Go through each face.
                foreach (Face face in faces)
                {
                    //	Go though each index.
                    foreach (Index index in face.Indices)
                    {
                        //	Make sure it's got a normal, and a vertex.
                        if (index.Normal != -1 && index.Vertex != -1)
                        {
                            //	Get the vertex.
                            Vertex vertex = vertices[index.Vertex];

                            //	Get the normal vertex.
                            Vertex normal  = normals[index.Normal];
                            Vertex vertex2 = vertex + normal;

                            gl.Begin(OpenGL.GL_LINES);
                            gl.Vertex(vertex);
                            gl.Vertex(vertex2);
                            gl.End();
                        }
                    }
                }

                //	Restore the attributes.
                gl.PopAttrib();
            }
        }
示例#27
0
        /// <summary>
        ///  Iscrtavanje OpenGL kontrole.
        /// </summary>
        public void Draw(OpenGL gl)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.Enable(OpenGL.GL_DEPTH_TEST);
            gl.Enable(OpenGL.GL_CULL_FACE);
            gl.LoadIdentity();

            gl.LookAt(0f, eyey, m_sceneDistance,
                      0f, centery, -10f,
                      0f, 1f, 0f);

            SetupLighting(gl); //mora ovim redoslijedom da bi bio izvor svjetlosti stacionaran!!!

            gl.PushMatrix();
            //gl.Translate(0.0f, 0.0f, -m_sceneDistance);   //0.0f za z osu
            gl.Rotate(m_xRotation, 1.0f, 0.0f, 0.0f);
            gl.Rotate(m_yRotation, 0.0f, 1.0f, 0.0f);

            gl.Viewport(0, 0, m_width, m_height);

            //zamak
            gl.PushMatrix();
            //gl.Color(0f, 0f, 1f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Castle]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);   //nacin spajanja teksture sa materijalom na modulate
            gl.Scale(0.1f, 0.1f, 0.1f);
            castle_scene.Draw();
            gl.PopMatrix();

            //strijela
            gl.PushMatrix();
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Castle]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            gl.Translate(arrow_translateX, arrow_translateY, arrow_translateZ);
            gl.Rotate(arrow_rotateX, arrow_rotateY, arrow_rotateZ);
            gl.Scale(arrow_scale, arrow_scale, arrow_scale);
            //gl.Scale(30f, 30f, 30f);
            arrow_scene.Draw();
            gl.PopMatrix();

            //podloga
            gl.PushMatrix();
            //gl.Color(0.3f, 50.4f, 0.3f);
            gl.Translate(0f, -0.1f, -20f);
            gl.Disable(OpenGL.GL_CULL_FACE);    //iskljucio da bi mi se vidjela podloga
            gl.Enable(OpenGL.GL_NORMALIZE);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Grass]);

            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.LoadIdentity();
            //gl.Scale(5, 5, 5);      //skaliranje teksture
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.Begin(OpenGL.GL_QUADS);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(-90f, 0f, 100f);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(-90f, 0f, -30f);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(90f, 0f, -30f);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(90f, 0f, 100f);
            gl.End();
            gl.PopMatrix();

            //staza
            gl.PushMatrix();
            //gl.Color(0.36f, 0.25f, 0.20f);
            gl.Translate(0f, 0f, 0f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Mud]);
            gl.Enable(OpenGL.GL_NORMALIZE);
            gl.Begin(OpenGL.GL_QUADS);      //crtano u x i z ravni
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(-5f, 0f, 80f);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(-5f, 0f, 0f);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(5f, 0f, 0f);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(5f, 0f, 80f);
            gl.End();
            gl.PopMatrix();

            //lijevi zid
            gl.PushMatrix();
            //gl.Color(0.85f, 0.53f, 0.10f);
            gl.Translate(-wall_translateX, 15.0f, 0f);
            //gl.Translate(-65.0f, 15.0f, 0f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Fence]);
            gl.Scale(3.0f, 15.0f, 40.0f);   //kolika je visina zida, toliko sam stavio da bude i translacija
            zid.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //desni zid
            gl.PushMatrix();
            //gl.Color(0.85f, 0.53f, 0.10f);
            gl.Translate(65.0f, 15.0f, 0f);
            gl.Rotate(0.0f, wall_rotateY, 0.0f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Fence]);
            gl.Scale(3.0f, 15.0f, 40.0f);   //kolika je visina zida, toliko sam stavio da bude i translacija
            zid.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //text
            DrawText1(gl);

            gl.PopMatrix();

            // Oznaci kraj iscrtavanja
            gl.Flush();
        }
示例#28
0
        public void DrawABLines()
        {
            //Draw AB Points
            gl.PointSize(8.0f);
            gl.Begin(OpenGL.GL_POINTS);

            gl.Color(0.5f, 0.0f, 0.0f);
            gl.Vertex(refPoint1.easting, refPoint1.northing, 0.0);
            gl.Color(0.0f, 0.0f, 0.5f);
            gl.Vertex(refPoint2.easting, refPoint2.northing, 0.0);

            //gl.Color(0.6f, 0.95f, 0.95f);
            //gl.Vertex(radiusPointAB.easting, radiusPointAB.northing, 0.0);

            gl.End();
            gl.PointSize(1.0f);

            if (isABLineSet)
            {
                //Draw reference AB line
                gl.LineWidth(2);
                gl.Enable(OpenGL.GL_LINE_STIPPLE);
                gl.LineStipple(1, 0x07F0);
                gl.Begin(OpenGL.GL_LINES);
                gl.Color(0.9f, 0.5f, 0.7f);
                gl.Vertex(refABLineP1.easting, refABLineP1.northing, 0);
                gl.Vertex(refABLineP2.easting, refABLineP2.northing, 0);

                gl.End();
                gl.Disable(OpenGL.GL_LINE_STIPPLE);

                //draw current AB Line
                gl.LineWidth(3);
                gl.Begin(OpenGL.GL_LINES);
                gl.Color(0.9f, 0.0f, 0.0f);

                //calculate if tram line is here
                if (tramPassEvery != 0)
                {
                    int pass = (int)passNumber + (tramPassEvery * 300) - passBasedOn;
                    if (pass % tramPassEvery != 0)
                    {
                        gl.Color(0.9f, 0.0f, 0.0f);
                    }
                    else
                    {
                        gl.Color(0, 0.9, 0);
                    }
                }

                //based on line pass, make ref purple
                if (Math.Abs(passBasedOn - passNumber) < 0.0000000001 && tramPassEvery != 0)
                {
                    gl.Color(0.990f, 0.190f, 0.990f);
                }

                gl.Vertex(currentABLineP1.easting, currentABLineP1.northing, 0.0);
                gl.Vertex(currentABLineP2.easting, currentABLineP2.northing, 0.0);
                gl.End();

                if (mf.isSideGuideLines)
                {
                    //get the tool offset and width
                    double toolOffset = mf.vehicle.toolOffset * 2;
                    double toolWidth  = mf.vehicle.toolWidth - mf.vehicle.toolOverlap;

                    gl.Color(0.0f, 0.90f, 0.50f);
                    gl.LineWidth(1);
                    gl.Begin(OpenGL.GL_LINES);

                    //precalculate sin cos
                    double cosHeading = Math.Cos(-abHeading);
                    double sinHeading = Math.Sin(-abHeading);

                    if (isABSameAsFixHeading)
                    {
                        gl.Vertex((cosHeading * (toolWidth + toolOffset)) + currentABLineP1.easting, (sinHeading * (toolWidth + toolOffset)) + currentABLineP1.northing, 0);
                        gl.Vertex((cosHeading * (toolWidth + toolOffset)) + currentABLineP2.easting, (sinHeading * (toolWidth + toolOffset)) + currentABLineP2.northing, 0);
                        gl.Vertex((cosHeading * (-toolWidth + toolOffset)) + currentABLineP1.easting, (sinHeading * (-toolWidth + toolOffset)) + currentABLineP1.northing, 0);
                        gl.Vertex((cosHeading * (-toolWidth + toolOffset)) + currentABLineP2.easting, (sinHeading * (-toolWidth + toolOffset)) + currentABLineP2.northing, 0);

                        toolWidth *= 2;
                        gl.Vertex((cosHeading * (toolWidth)) + currentABLineP1.easting, (sinHeading * (toolWidth)) + currentABLineP1.northing, 0);
                        gl.Vertex((cosHeading * (toolWidth)) + currentABLineP2.easting, (sinHeading * (toolWidth)) + currentABLineP2.northing, 0);
                        gl.Vertex((cosHeading * (-toolWidth)) + currentABLineP1.easting, (sinHeading * (-toolWidth)) + currentABLineP1.northing, 0);
                        gl.Vertex((cosHeading * (-toolWidth)) + currentABLineP2.easting, (sinHeading * (-toolWidth)) + currentABLineP2.northing, 0);
                    }
                    else
                    {
                        gl.Vertex((cosHeading * (toolWidth - toolOffset)) + currentABLineP1.easting, (sinHeading * (toolWidth - toolOffset)) + currentABLineP1.northing, 0);
                        gl.Vertex((cosHeading * (toolWidth - toolOffset)) + currentABLineP2.easting, (sinHeading * (toolWidth - toolOffset)) + currentABLineP2.northing, 0);
                        gl.Vertex((cosHeading * (-toolWidth - toolOffset)) + currentABLineP1.easting, (sinHeading * (-toolWidth - toolOffset)) + currentABLineP1.northing, 0);
                        gl.Vertex((cosHeading * (-toolWidth - toolOffset)) + currentABLineP2.easting, (sinHeading * (-toolWidth - toolOffset)) + currentABLineP2.northing, 0);

                        toolWidth *= 2;
                        gl.Vertex((cosHeading * (toolWidth)) + currentABLineP1.easting, (sinHeading * (toolWidth)) + currentABLineP1.northing, 0);
                        gl.Vertex((cosHeading * (toolWidth)) + currentABLineP2.easting, (sinHeading * (toolWidth)) + currentABLineP2.northing, 0);
                        gl.Vertex((cosHeading * (-toolWidth)) + currentABLineP1.easting, (sinHeading * (-toolWidth)) + currentABLineP1.northing, 0);
                        gl.Vertex((cosHeading * (-toolWidth)) + currentABLineP2.easting, (sinHeading * (-toolWidth)) + currentABLineP2.northing, 0);
                    }
                    gl.End();
                }

                if (mf.isPureDisplayOn)
                {
                    //draw the guidance circle
                    const int numSegments = 100;
                    {
                        gl.Color(0.95f, 0.30f, 0.950f);
                        double theta = glm.twoPI / numSegments;
                        double c     = Math.Cos(theta);//precalculate the sine and cosine
                        double s     = Math.Sin(theta);

                        double x = ppRadiusAB;//we start at angle = 0
                        double y = 0;

                        gl.LineWidth(1);
                        gl.Begin(OpenGL.GL_LINE_LOOP);
                        for (int ii = 0; ii < numSegments; ii++)
                        {
                            //output vertex
                            gl.Vertex(x + radiusPointAB.easting, y + radiusPointAB.northing);

                            //apply the rotation matrix
                            double t = x;
                            x = (c * x) - (s * y);
                            y = (s * t) + (c * y);
                        }
                        gl.End();
                    }
                    //Draw lookahead Point
                    gl.PointSize(4.0f);
                    gl.Begin(OpenGL.GL_POINTS);
                    gl.Color(1.0f, 0.5f, 0.95f);
                    gl.Vertex(goalPointAB.easting, goalPointAB.northing, 0.0);
                    //gl.Color(0.6f, 0.95f, 0.95f);
                    //gl.Vertex(mf.at.rEastAT, mf.at.rNorthAT, 0.0);
                    //gl.Color(0.6f, 0.95f, 0.95f);
                    //gl.Vertex(mf.at.turnRadiusPt.easting, mf.at.turnRadiusPt.northing, 0.0);
                    gl.End();
                    gl.PointSize(1.0f);
                }

                if (mf.yt.isYouTurnOn)
                {
                    gl.Color(0.95f, 0.95f, 0.25f);
                    gl.LineWidth(2);
                    int ptCount = mf.yt.ytList.Count;
                    if (ptCount > 0)
                    {
                        gl.Begin(OpenGL.GL_LINE_STRIP);
                        for (int i = 0; i < ptCount; i++)
                        {
                            gl.Vertex(mf.yt.ytList[i].x, mf.yt.ytList[i].z, 0);
                        }
                        gl.End();
                    }

                    gl.Color(0.95f, 0.05f, 0.05f);
                }

                if (mf.yt.isRecordingYouTurn)
                {
                    gl.Color(0.05f, 0.05f, 0.95f);
                    gl.PointSize(4.0f);
                    int ptCount = mf.yt.youFileList.Count;
                    if (ptCount > 1)
                    {
                        gl.Begin(OpenGL.GL_POINTS);
                        for (int i = 1; i < ptCount; i++)
                        {
                            gl.Vertex(mf.yt.youFileList[i].easting + mf.yt.youFileList[0].easting, mf.yt.youFileList[i].northing + mf.yt.youFileList[0].northing, 0);
                        }
                        gl.End();
                    }
                }

                gl.PointSize(1.0f);
                gl.LineWidth(1);
            }
        }
示例#29
0
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            OpenGL gl = GLcontrol.OpenGL;

            IntPtr quad = gl.NewQuadric();

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            if (p_flag == true)
            {
                gl.LookAt(e_x, e_y, e_z, c_x, c_y, c_z, u_x, u_y, u_z);
            }
            if (rot_flag == true)

            {
                if (clock == true)
                {
                    gl.Rotate(rotation, 0.0f, 0.0f, 1.0f);
                }
                else
                {
                    gl.Rotate(rotation, 1.0f, 1.0f, 1.0f);
                }
            }

            gl.Translate(0.0f, 0.0f, 0.0f);
            if (kb.IsChecked == true || Z_o.IsChecked == true)
            {
                gl.Scale(40.3, 40.3, 40.3);
            }
            gl.Scale(0.3, 0.3, 0.3);
            gl.PushMatrix();
            gl.Color(1.0f, 1.0f, 0.0f);
            if (zil.IsChecked == true)
            {
                gl.Cylinder(quad, 50, 30, 30, 20, 20);
                clock = false;
            }
            if (sf.IsChecked == true)
            {
                gl.Sphere(quad, 50, 100, 100);
                clock = false;
            }
            if (ds.IsChecked == true)
            {
                gl.Disk(quad, 40, 50, 50, 50);
                clock = false;
            }
            if (ds_m.IsChecked == true)
            {
                gl.PartialDisk(quad, 40, 50, 50, 50, 50, 50);
                clock = false;
            }
            if (tp.IsChecked == true)
            {
                Teapot tp = new Teapot();
                tp.Draw(gl, 50, 51, OpenGL.GL_FILL);
                clock = false;
            }
            if (kb.IsChecked == true)
            {
                Cube cube = new Cube();
                cube.Render(gl, RenderMode.Render);
                clock = false;
            }
            if (Z_o.IsChecked == true)
            {
                clock = false;
                int   i, N = 20;
                float angleStep    = 360.0f / N;
                float angleCurrent = 0f;
                float Radius1      = 1.0f;
                for (i = 0; i < N; i++)
                {
                    angleCurrent = i * angleStep * 3.14f / 180;
                    gl.PushMatrix();
                    gl.Translate(Radius1 * Math.Sin(angleCurrent), 0, Radius1 * Math.Cos(angleCurrent));
                    gl.Sphere(quad, 0.3, 24, 24);
                    gl.PopMatrix();
                }
            }
            if (S_S.IsChecked == true)
            {
                clock = false;
                //рисуем солнце
                gl.Color(1.0, 1.0, 0.0);
                gl.Sphere(quad, 30, 50, 50);
                gl.Translate(60, 0, 0);
                // Рисуем планету
                gl.Color(0.0, 1.0, 0.0);
                gl.Sphere(quad, 10, 50, 50);
                gl.PopMatrix();
                gl.Flush();
            }
            if (O_O.IsChecked == true)
            {
                clock = false;
                gl.Color(0.7, 0.1, 0.0);
                gl.Sphere(quad, 30, 40, 40);
                gl.Translate(0, 0, 0);
                gl.Color(0.1, 0.3, 0.9);
                int   i, N = 20;
                float angleStep    = 360.0f / N;
                float angleCurrent = 0f;
                float Radius1      = 45.0f;
                for (i = 0; i < N; i++)
                {
                    angleCurrent = i * angleStep * 3.14f / 180;
                    gl.PushMatrix();
                    gl.Translate(Radius1 * Math.Sin(angleCurrent), 0, Radius1 * Math.Cos(angleCurrent));
                    gl.Sphere(quad, 9.9, 40, 40);
                    gl.PopMatrix();
                }
                gl.LookAt(1.1, 1.1, 1.5, 1.1, 1.1, 5.7, 1.1, 0, 0);
                for (i = 0; i < N; i++)
                {
                    angleCurrent = i * angleStep * 3.14f / 180;
                    gl.PushMatrix();
                    gl.Translate(Radius1 * Math.Sin(angleCurrent), 0, Radius1 * Math.Cos(angleCurrent));
                    gl.Sphere(quad, 9.9, 40, 40);
                    gl.PopMatrix();
                }
            }
            if (O_k.IsChecked == true)
            {
                clock = false;
                gl.LineWidth(2.5f);
                gl.Scale(50.3, 50.3, 50.3);
                gl.Begin(OpenGL.GL_LINES);
                gl.Color(1.0, 0.0, 0.0);
                gl.Vertex(-1, -1, 0); //х
                gl.Vertex(1, -1, 0);
                gl.Vertex(-1, 1, 0);  //у
                gl.Vertex(-1, -1, 0);
                gl.Vertex(-1, -1, 0); //z
                gl.Vertex(-1, -1, 2);
                gl.End();
            }
            if (kv.IsChecked == true)
            {
                clock = false;
                gl.MatrixMode(OpenGL.GL_MODELVIEW);
                gl.LoadIdentity();
                gl.PushMatrix();
                gl.Rotate(rotation, 0.0, 0.0, 1.0);
                gl.Color(1.0, 1.0, 1.0);
                gl.Rect(-20.0, -20.0, 20.0, 20.0);
                gl.PopMatrix();
            }
            if (asd.IsChecked == true)
            {
                clock = false;
                gl.LineWidth(3.5f);
                gl.Scale(20.3, 20.3, 20.3);
                gl.Begin(OpenGL.GL_LINE_STRIP);
                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
                gl.Rotate(rotation, 0.0, 0.0, 1.0);
                gl.Color(1.0, 0.0, 0.0);
                gl.Vertex(0, 0);
                gl.Vertex(0, 3);
                gl.Vertex(2, 2);
                gl.Vertex(4, 3);
                gl.Vertex(4, 0);
                gl.Vertex(3, 0);
                gl.Vertex(3, 1);
                gl.Vertex(1, 1);
                gl.Vertex(1, 0);
                gl.Vertex(0, 0);
                gl.End();
            }
            if (cl.IsChecked == true)
            {
                clock = false;
                gl.LineWidth(3.5f);
                gl.MatrixMode(OpenGL.GL_MODELVIEW);
                gl.LoadIdentity();
                gl.PushMatrix();
                gl.Rotate(rotation, 0.0, 0.0, 1.0);
                gl.Color(1.0, 1.0, 1.0);
                gl.Rect(-0.91, -20.9, 1.0, 1.0);
                gl.PopMatrix();
                gl.Color(0.0f, 1.0f, 0.0f);
                gl.Begin(OpenGL.GL_LINE_LOOP);
                for (int i = 0; i < 100; i++)
                {
                    double a = (float)i / 25.0f * 3.1415f * 2.0f;
                    gl.Vertex(Math.Cos(a) * 28.0f, Math.Sin(a) * 28.0f);
                }
                gl.End();
                gl.Begin(OpenGL.GL_LINE_STRIP);
                gl.PushMatrix();
                gl.Vertex(-21, 0);
                gl.Vertex(-25, 0);
                gl.Vertex(-21, 3);
                gl.Vertex(-25, 6);
                gl.Vertex(-21, 6);
                gl.End();
                gl.Begin(OpenGL.GL_LINE_STRIP);
                gl.Vertex(25, 0);
                gl.Vertex(21, 0);
                gl.Vertex(21, 3);
                gl.Vertex(25, 3);
                gl.Vertex(25, 6);
                gl.Vertex(21, 6);
                gl.Vertex(21, 3);
                gl.End();
                gl.Begin(OpenGL.GL_LINE_STRIP);
                gl.Vertex(2, 25);
                gl.Vertex(1, 27);
                gl.Vertex(1, 23);
                gl.End();
                gl.Begin(OpenGL.GL_LINE_STRIP);
                gl.Vertex(-1, 27);
                gl.Vertex(-3, 27);
                gl.Vertex(-1, 23);
                gl.Vertex(-3, 23);
                gl.End();
                gl.Begin(OpenGL.GL_LINE_STRIP);
                gl.Vertex(-1, -20);
                gl.Vertex(3, -20);
                gl.Vertex(3, -26);
                gl.Vertex(-1, -26);
                gl.Vertex(-1, -23);
                gl.Vertex(3, -23);
                gl.End();
            }
            gl.PopMatrix();
            rotation += Convert.ToSingle(sl.Value);
        }
示例#30
0
        /// <summary>
        /// Draw axis with all lines
        /// </summary>
        /// <param name="gl"></param>
        private void DrawAxis(OpenGL gl, double width, double height)
        {
            //Get the axis color, secondary lines color and ticks color
            var axisLineColor          = AxisBrush.GetRGBAf();
            var axisSecondaryLineColor = SecondaryGridBrush.GetRGBAf();
            var ticksColor             = TicksBrush.GetRGBAf();
            var ticksScaleColor        = TicksScaleBrush.GetRGBAf();

            // Get length of Tick line
            double tickWidth = 5;

            #region Draw YTicks and labels
            // Ticks line of axis-Y and ticks
            double gapY            = height / (YGapCount + 1);
            double realValueOfGapY = (MaxY - MinY) / (YGapCount + 1);
            for (int num = 0; num <= YGapCount + 1; num++)
            {
                double posX = tickWidth;
                double posY = gapY * num;

                // Draw secondary line
                if (IsSecondaryLineVisible)
                {
                    gl.PushAttrib(OpenGL.GL_ENABLE_BIT);

                    if (IsDotDash)
                    {
                        gl.LineStipple(1, 0xAAAA);
                        gl.Enable(OpenGL.GL_LINE_STIPPLE);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_LINE_STIPPLE);
                    }

                    gl.Color(axisSecondaryLineColor[0], axisSecondaryLineColor[1], axisSecondaryLineColor[2]);// will be chaged by drawText if without it
                    gl.Begin(OpenGL.GL_LINES);
                    gl.Vertex(0.0d, posY);
                    gl.Vertex(width, posY);
                    gl.End();
                    gl.PopAttrib();
                }

                // Draw ticks line
                gl.Color(ticksScaleColor[0], ticksScaleColor[1], ticksScaleColor[2]);// will be chaged by drawText if without it
                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(0.0d, posY);
                gl.Vertex(tickWidth, posY);
                gl.End();

                // Draw ticks
                string dispText = (num * realValueOfGapY + MinY).ToString("f2");
                double textWidth = 0, textHeight = 0;
                GetSizeOfText(gl, dispText, ref textWidth, ref textHeight);

                double textPosX = 2 * tickWidth;
                double textPosY = num == YGapCount + 1 ? posY - textHeight : (num == 0 ? posY + 2 : posY);

                DrawString(gl, dispText, (int)textPosX, (int)textPosY, ticksColor);
            }
            #endregion

            #region Draw XTicks and labels
            // Ticks line of axis-X and ticks
            double gapX            = width / (XGapCount + 1);
            double realValueOfGapX = (MaxX - MinX).TotalMilliseconds / (XGapCount + 1);// Milliseconds in one gap
            for (int num = 0; num <= XGapCount + 1; num++)
            {
                double posX = num * gapX;

                // Draw secondary line
                if (IsSecondaryLineVisible)
                {
                    gl.PushAttrib(OpenGL.GL_ENABLE_BIT);

                    if (IsDotDash)
                    {
                        gl.LineStipple(1, 0xAAAA);
                        gl.Enable(OpenGL.GL_LINE_STIPPLE);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_LINE_STIPPLE);
                    }

                    gl.Color(axisSecondaryLineColor[0], axisSecondaryLineColor[1], axisSecondaryLineColor[2]);// will be chaged by drawText if without it
                    gl.Begin(OpenGL.GL_LINES);
                    gl.Vertex(posX, 0.0d);
                    gl.Vertex(posX, height);
                    gl.End();
                    gl.PopAttrib();
                }

                // Draw ticks line
                gl.Color(ticksScaleColor[0], ticksScaleColor[1], ticksScaleColor[2]);// will be chaged by drawText if without it
                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(posX, 0.0d);
                gl.Vertex(posX, tickWidth);
                gl.End();

                // Draw text
                string dispText = (MinX + TimeSpan.FromMilliseconds(realValueOfGapX * num)).ToString("HH:mm:ss");
                double textWidth = 0, textHeight = 0;
                GetSizeOfText(gl, dispText, ref textWidth, ref textHeight);

                double textPosX = num == XGapCount + 1 ? posX - textWidth - 5 : posX - textWidth / 2;
                double textPosY = tickWidth + textHeight / 2;

                DrawString(gl, dispText, (int)textPosX, (int)textPosY, ticksColor);
            }
            #endregion

            #region Draw Axis-X and Axis-Y
            // Left line of axis-Y
            gl.Color(axisLineColor[0], axisLineColor[1], axisLineColor[2]);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(0.0d, 0.0d);
            gl.Vertex(0.0d, height);
            gl.End();

            // Draw right line when the axis is boxed
            if (IsBoxed)
            {
                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(width, 0.0d);
                gl.Vertex(width, height);
                gl.End();
            }

            // Left line of axis-Y
            gl.Color(axisLineColor[0], axisLineColor[1], axisLineColor[2]);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(0.0d, 0.0d);
            gl.Vertex(width, 0.0d);
            gl.End();

            // Draw right line when the axis is boxed
            if (IsBoxed)
            {
                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(0.0d, height);
                gl.Vertex(width, height);
                gl.End();
            }
            #endregion
        }
示例#31
0
        /// <summary>
        /// Use this to draw the vertex grid.
        /// </summary>
        /// <param name="gl">OpenGL object.</param>
        /// <param name="points">Draw each individual vertex (with selection names).</param>
        /// <param name="lines">Draw the lines connecting the points.</param>
        public virtual void Draw(OpenGL gl, bool points, bool lines)
        {
            //    Save the attributes.
            gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Color(1, 0, 0, 1);

            if (points)
            {
                int name = 0;

                gl.PointSize(5);

                //    Add a new name (the vertex name).
                gl.PushName(0);

                foreach (Vertex v in vertices)
                {
                    //    Set the name, draw the vertex.
                    gl.LoadName((uint)name++);
                    //todo draw vertex
                    //((IInteractable)v).DrawPick(gl);
                }

                //    Pop the name.
                gl.PopName();
            }

            if (lines)
            {
                //    Draw lines along each row, then along each column.
                gl.DepthFunc(OpenGL.GL_ALWAYS);

                gl.LineWidth(1);
                gl.Disable(OpenGL.GL_LINE_SMOOTH);

                for (int col = 0; col < y; col++)
                {
                    for (int row = 0; row < x; row++)
                    {
                        //    Create vertex indicies.
                        int nTopLeft    = (col * x) + row;
                        int nBottomLeft = ((col + 1) * x) + row;

                        gl.Begin(OpenGL.GL_LINES);
                        if (row < (x - 1))
                        {
                            gl.Vertex(vertices[nTopLeft]);
                            gl.Vertex(vertices[nTopLeft + 1]);
                        }
                        if (col < (y - 1))
                        {
                            gl.Vertex(vertices[nTopLeft]);
                            gl.Vertex(vertices[nBottomLeft]);
                        }
                        gl.End();
                    }
                }
                gl.DepthFunc(OpenGL.GL_LESS);
            }

            gl.PopAttrib();
        }
示例#32
0
        //vẽ hình
        static void Repaint(Point pStart, Point pEnd, int Shape, int Size, Scolor Color, bool checkClickDown, ref Sgraph temp, ref OpenGL gl)
        {
            double Rx, Ry;
            Point  pTemp = new Point();

            gl.Color(Color.R / 255.0, Color.G / 255.0, Color.B / 255.0, 0);
            gl.LineWidth(Size);
            switch (Shape)
            {
            case 0:                        //vẽ đoạn thẳng

                gl.Begin(OpenGL.GL_LINES); // chọn chế độ vẽ đường thẳng
                gl.Vertex(pStart.X, gl.RenderContextProvider.Height - pStart.Y);
                gl.Vertex(pEnd.X, gl.RenderContextProvider.Height - pEnd.Y);

                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian



                break;

            case 1:    //vẽ hình tròn
                double thetar;
                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2) + Math.Pow(pStart.Y - pEnd.Y, 2));
                gl.Begin(OpenGL.GL_LINE_LOOP);
                for (int i = 0; i < 360; i++)
                {
                    thetar = i * Math.PI / 180;
                    gl.Vertex(pStart.X + Rx * Math.Cos(thetar), gl.RenderContextProvider.Height - pStart.Y + Rx * Math.Sin(thetar));
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                break;

            case 2:    //ve hình chữ nhật

                gl.Begin(OpenGL.GL_LINE_LOOP);
                gl.Vertex(pStart.X, gl.RenderContextProvider.Height - pStart.Y);
                gl.Vertex(pStart.X, gl.RenderContextProvider.Height - pEnd.Y);
                gl.Vertex(pEnd.X, gl.RenderContextProvider.Height - pEnd.Y);
                gl.Vertex(pEnd.X, gl.RenderContextProvider.Height - pStart.Y);

                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                if (checkClickDown == false)
                {
                    temp.List_Graph_Point.Clear();
                    temp.List_Graph_Point.Add(pStart);
                    pTemp.X = pStart.X;
                    pTemp.Y = pEnd.Y;
                    temp.List_Graph_Point.Add(pTemp);
                    temp.List_Graph_Point.Add(pEnd);
                    pTemp.X = pEnd.X;
                    pTemp.Y = pStart.Y;
                    temp.List_Graph_Point.Add(pTemp);
                }
                break;

            case 3:    //ve elip
                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2));
                Ry = Math.Sqrt(Math.Pow(pStart.Y - pEnd.Y, 2));
                double x, y;

                gl.Begin(OpenGL.GL_LINE_LOOP);
                for (int i = 0; i < 360; i++)
                {
                    thetar = i * Math.PI / 180;
                    x      = pStart.X + Rx * Math.Cos(thetar);
                    y      = gl.RenderContextProvider.Height - pStart.Y + Ry * Math.Sin(thetar);
                    gl.Vertex(x, y);
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                break;

            case 4:    //ve tam giac deu

                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2) + Math.Pow(pStart.Y - pEnd.Y, 2));

                gl.Begin(OpenGL.GL_LINE_LOOP);

                for (int i = 0; i < 360; i += 120)
                {
                    {
                        thetar = i * Math.PI / 180;
                        gl.Vertex(pStart.X + Rx * Math.Cos(thetar - Math.PI / 2), gl.RenderContextProvider.Height - pStart.Y - Rx * Math.Sin(thetar - Math.PI / 2));
                    }
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                if (checkClickDown == false)
                {
                    temp.List_Graph_Point.Clear();
                    for (int i = 0; i < 360; i += 120)
                    {
                        {
                            thetar  = i * Math.PI / 180;
                            pTemp.X = (int)(pStart.X + Rx * Math.Cos(thetar - Math.PI / 2));
                            pTemp.Y = (int)(pStart.Y + Rx * Math.Sin(thetar - Math.PI / 2));
                            temp.List_Graph_Point.Add(pTemp);
                        }
                    }
                }
                break;

            case 5:    //ve ngu giac deu

                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2) + Math.Pow(pStart.Y - pEnd.Y, 2));

                gl.Begin(OpenGL.GL_LINE_LOOP);
                for (int i = 0; i < 360; i += 72)
                {
                    //if (i % 72 == 0)
                    {
                        thetar = i * Math.PI / 180;
                        gl.Vertex(pStart.X + Rx * Math.Cos(thetar + Math.PI / 2), gl.RenderContextProvider.Height - pStart.Y + Rx * Math.Sin(thetar + Math.PI / 2));
                    }
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                if (checkClickDown == false)
                {
                    temp.List_Graph_Point.Clear();
                    for (int i = 0; i < 360; i += 72)
                    {
                        {
                            thetar  = i * Math.PI / 180;
                            pTemp.X = (int)(pStart.X + Rx * Math.Cos(thetar + Math.PI / 2));
                            pTemp.Y = (int)(pStart.Y - Rx * Math.Sin(thetar + Math.PI / 2));
                            temp.List_Graph_Point.Add(pTemp);
                        }
                    }
                }
                break;

            case 6:    //ve luc giac deu
                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2) + Math.Pow(pStart.Y - pEnd.Y, 2));

                gl.Begin(OpenGL.GL_LINE_LOOP);
                for (int i = 1; i < 360; i++)
                {
                    if (i % 30 == 0 && i % 60 != 0)
                    {
                        thetar = i * Math.PI / 180;
                        gl.Vertex(pStart.X + Rx * Math.Cos(thetar + Math.PI / 2), gl.RenderContextProvider.Height - pStart.Y + Rx * Math.Sin(thetar + Math.PI / 2));
                    }
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                if (checkClickDown == false)
                {
                    temp.List_Graph_Point.Clear();
                    for (int i = 0; i < 360; i++)
                    {
                        if (i % 30 == 0 && i % 60 != 0)
                        {
                            thetar  = i * Math.PI / 180;
                            pTemp.X = (int)(pStart.X + Rx * Math.Cos(thetar + Math.PI / 2));
                            pTemp.Y = (int)(pStart.Y - Rx * Math.Sin(thetar + Math.PI / 2));
                            temp.List_Graph_Point.Add(pTemp);
                        }
                    }
                }
                break;
            }
        }
示例#33
0
		/// <summary>
		/// Use this to draw the vertex grid.
		/// </summary>
		/// <param name="gl">OpenGL object.</param>
		/// <param name="points">Draw each individual vertex (with selection names).</param>
		/// <param name="lines">Draw the lines connecting the points.</param>
		public virtual void Draw(OpenGL gl, bool points, bool lines)
		{
			//	Save the attributes.
            gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);
            gl.Disable(OpenGL.GL_LIGHTING);
			gl.Color(1, 0, 0, 1);

			if(points)
			{
                int name = 0;

				gl.PointSize(5);

				//	Add a new name (the vertex name).
				gl.PushName(0);

				foreach(Vertex v in vertices)
				{
					//	Set the name, draw the vertex.
					gl.LoadName((uint)name++);
					//todo draw vertex
                    //((IInteractable)v).DrawPick(gl);
				}

				//	Pop the name.
				gl.PopName();
			}

			if(lines)
			{
				//	Draw lines along each row, then along each column.
                gl.DepthFunc(OpenGL.GL_ALWAYS);

				gl.LineWidth(1);
                gl.Disable(OpenGL.GL_LINE_SMOOTH);

				for(int col=0; col < y; col++)
				{
					for(int row=0; row < x; row++)
					{
						//	Create vertex indicies.
						int nTopLeft = (col * x) + row;
						int nBottomLeft = ((col + 1) * x) + row;

                        gl.Begin(OpenGL.GL_LINES);
						if(row < (x-1))
						{
							gl.Vertex(vertices[nTopLeft]);
							gl.Vertex(vertices[nTopLeft + 1]);
						}
						if(col < (y-1))
						{
							gl.Vertex(vertices[nTopLeft]);
							gl.Vertex(vertices[nBottomLeft]);
						}
						gl.End();
					}
				}
                gl.DepthFunc(OpenGL.GL_LESS);
			}

			gl.PopAttrib();
		}
示例#34
0
        /// <summary>
        /// Render to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        public void Render(OpenGL gl, RenderMode renderMode)
        {
            //  Push attributes, disable lighting.
            gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
                OpenGL.GL_LINE_BIT | OpenGL.GL_POLYGON_BIT);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.LineWidth(1.0f);
            gl.Color(1f, 0.2f, 0.2f, 0.6f);
            gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, 
                renderMode == RenderMode.HitTest ? (uint)PolygonMode.Filled : (uint)PolygonMode.Lines);
            
            gl.Begin(OpenGL.GL_QUADS);		// Draw The Cube Using quads
            gl.Vertex(hhl);	// Top Right Of The Quad (Top)
            gl.Vertex(lhl);	// Top Left Of The Quad (Top)
            gl.Vertex(lhh);	// Bottom Left Of The Quad (Top)
            gl.Vertex(hhh);	// Bottom Right Of The Quad (Top)
            gl.Vertex(hlh);	// Top Right Of The Quad (Bottom)
            gl.Vertex(llh);	// Top Left Of The Quad (Bottom)
            gl.Vertex(lll);	// Bottom Left Of The Quad (Bottom)
            gl.Vertex(hll);	// Bottom Right Of The Quad (Bottom)
            gl.Vertex(hhh);	// Top Right Of The Quad (Front)
            gl.Vertex(lhh);	// Top Left Of The Quad (Front)
            gl.Vertex(llh);	// Bottom Left Of The Quad (Front)
            gl.Vertex(hlh);	// Bottom Right Of The Quad (Front)
            gl.Vertex(hll);	// Top Right Of The Quad (Back)
            gl.Vertex(lll);	// Top Left Of The Quad (Back)
            gl.Vertex(lhl);	// Bottom Left Of The Quad (Back)
            gl.Vertex(hhl);	// Bottom Right Of The Quad (Back)
            gl.Vertex(lhh);	// Top Right Of The Quad (Left)
            gl.Vertex(lhl);	// Top Left Of The Quad (Left)
            gl.Vertex(lll);	// Bottom Left Of The Quad (Left)
            gl.Vertex(llh);	// Bottom Right Of The Quad (Left)
            gl.Vertex(hhl);	// Top Right Of The Quad (Right)
            gl.Vertex(hhh);	// Top Left Of The Quad (Right)
            gl.Vertex(hlh);	// Bottom Left Of The Quad (Right)
            gl.Vertex(hll);	// Bottom Right Of The Quad (Right)
            gl.End();			// End Drawing The Cube

            //  Pop attributes.
            gl.PopAttrib();
        }
示例#35
0
        public override void Draw(OpenGL gl)
        {
            gl.Color(color.R, color.G, color.B, life);

            gl.Begin(OpenGL.TRIANGLE_STRIP);
            gl.Vertex(position.X+0.1f, position.Y+0.1f, position.Z+0.1f);
            gl.Vertex(position.X-0.1f, position.Y+0.1f, position.Z);
            gl.Vertex(position.X+0.1f, position.Y-0.1f, position.Z);
            gl.Vertex(position.X-0.1f, position.Y-0.1f, position.Z);

            gl.End();
        }
示例#36
0
        // Draw mesh surface
        public void SystemDraw(OpenGL gl)
        {
            gl.ClearColor(128.0f / 255.0f, 128.0f / 255.0f, 128.0f / 255.0f, 100.0f / 255.0f); // dark gray
            gl.Color(1.0f, 1.0f, 1.0f);
            gl.LineWidth(1.0f);
            int nTiles = 30;

            for (int i = -30; i <= 30; i++)
            {
                gl.Begin(OpenGL.GL_LINES);
                // Vẽ song song với Oz
                gl.Vertex(i, 0, nTiles);
                gl.Vertex(i, 0, -nTiles);
                // Vẽ song song với Ox
                gl.Vertex(-nTiles, 0, i);
                gl.Vertex(nTiles, 0, i);
                gl.End();
                gl.Flush();
            }
            #region Draw global axis
            //float a = 20.0f;
            //float b = a - 1.0f;

            //gl.LineWidth(4.0f);
            //// Ve Ox
            //gl.Color(255.0 / 255.0, 0.0, 0.0);
            //gl.Begin(OpenGL.GL_LINES);
            //gl.Vertex(0, 0, 0);
            //gl.Vertex(a, 0, 0);
            //gl.End();
            //gl.Flush();
            //gl.Begin(OpenGL.GL_TRIANGLES);
            //gl.Vertex(b, 0, 1);
            //gl.Vertex(b, 0, -1);
            //gl.Vertex(a, 0, 0);
            //gl.End();
            //gl.Flush();

            //// Ve Oy
            //gl.Color(0.0f, 255.0 / 255.0, 0.0);
            //gl.Begin(OpenGL.GL_LINES);
            //gl.Vertex(0, 0, 0);
            //gl.Vertex(0, a, 0);
            //gl.End();
            //gl.Flush();
            //gl.Begin(OpenGL.GL_TRIANGLES);
            //gl.Vertex(-1, b, 0);
            //gl.Vertex(1, b, 0);
            //gl.Vertex(0, a, 0);
            //gl.End();
            //gl.Flush();
            //// Ve Oz
            //gl.Color(0.0f, 0.0f, 255.0 / 255.0);
            //gl.Begin(OpenGL.GL_LINES);
            //gl.Vertex(0, 0, 0);
            //gl.Vertex(0, 0, a);
            //gl.End();
            //gl.Flush();
            //gl.Begin(OpenGL.GL_TRIANGLES);
            //gl.Vertex(1, 0, b);
            //gl.Vertex(-1, 0, b);
            //gl.Vertex(0, 0, a);
            //gl.End();
            //gl.Flush();

            //gl.LineWidth(1.0f); // Reset lai do day net ve
            #endregion
        }
        private void SampleRendering(OpenGL gl, float rX, float rY, float rZ)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
            gl.LoadIdentity();					// Reset The View
            gl.Translate(-1.5f, 0.0f, -6.0f);				// Move Left And Into The Screen

            gl.Rotate(rtri, rX, rY, rZ);				// Rotate The Pyramid On It's Y Axis

            gl.Begin(OpenGL.GL_TRIANGLES);					// Start Drawing The Pyramid

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Front)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Left Of Triangle (Front)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Right Of Triangle (Front)

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Right)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Left Of Triangle (Right)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Right Of Triangle (Right)

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Back)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Left Of Triangle (Back)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Right Of Triangle (Back)

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Left)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Left Of Triangle (Left)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Right Of Triangle (Left)
            gl.End();						// Done Drawing The Pyramid

            gl.LoadIdentity();
            gl.Translate(1.5f, 0.0f, -7.0f);				// Move Right And Into The Screen

            gl.Rotate(rquad, rX, rY, rZ);			// Rotate The Cube On X, Y & Z

            gl.Begin(OpenGL.GL_QUADS);					// Start Drawing The Cube

            gl.Color(0.0f, 1.0f, 0.0f);			// Set The Color To Green
            gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, 1.0f);			// Bottom Left Of The Quad (Top)
            gl.Vertex(1.0f, 1.0f, 1.0f);			// Bottom Right Of The Quad (Top)

            gl.Color(1.0f, 0.5f, 0.0f);			// Set The Color To Orange
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Top Right Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Top Left Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Bottom)
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Bottom)

            gl.Color(1.0f, 0.0f, 0.0f);			// Set The Color To Red
            gl.Vertex(1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Front)
            gl.Vertex(-1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Front)
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Bottom Left Of The Quad (Front)
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Bottom Right Of The Quad (Front)

            gl.Color(1.0f, 1.0f, 0.0f);			// Set The Color To Yellow
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Back)
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Back)
            gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Back)
            gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Back)

            gl.Color(0.0f, 0.0f, 1.0f);			// Set The Color To Blue
            gl.Vertex(-1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Left)
            gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Bottom Right Of The Quad (Left)

            gl.Color(1.0f, 0.0f, 1.0f);			// Set The Color To Violet
            gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Right)
            gl.Vertex(1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Bottom Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Right)
            gl.End();						// Done Drawing The Q

            gl.Flush();

            rtri += 1.0f;// 0.2f;						// Increase The Rotation Variable For The Triangle
            rquad -= 1.0f;// 0.15f;						// Decrease The Rotation Variable For The Quad
        }
示例#38
0
        public void DrawVehicle()
        {
            //translate and rotate at pivot axle
            gl.Translate(mf.pn.fix.easting, mf.pn.fix.northing, 0);
            gl.PushMatrix();

            //most complicated translate ever!
            gl.Translate(Math.Sin(mf.fixHeading) * (hitchLength - antennaPivot),
                         Math.Cos(mf.fixHeading) * (hitchLength - antennaPivot), 0);

            //settings doesn't change trailing hitch length if set to rigid, so do it here
            double trailingTank, trailingTool;

            if (isToolTrailing)
            {
                trailingTank = tankTrailingHitchLength;
                trailingTool = toolTrailingHitchLength;
            }
            else
            {
                trailingTank = 0; trailingTool = 0;
            }

#pragma warning disable CS1690 // Accessing a member on a field of a marshal-by-reference class may cause a runtime exception
            //there is a trailing tow between hitch
            if (tankTrailingHitchLength < -2.0 && isToolTrailing)
            {
                gl.Rotate(glm.toDegrees(-mf.tankPos.heading), 0.0, 0.0, 1.0);

                //draw the tank hitch
                gl.LineWidth(2);
                gl.Color(0.7f, 0.7f, 0.97f);

                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(0, trailingTank, 0);
                gl.Vertex(0, 0, 0);
                gl.End();

                //section markers
                gl.Color(0.95f, 0.950f, 0.0f);
                gl.PointSize(6.0f);
                gl.Begin(OpenGL.GL_POINTS);
                gl.Vertex(0, trailingTank, 0);
                gl.End();

                //move down the tank hitch, unwind, rotate to section heading
                gl.Translate(0, trailingTank, 0);
                gl.Rotate(glm.toDegrees(mf.tankPos.heading), 0.0, 0.0, 1.0);
                gl.Rotate(glm.toDegrees(-mf.toolPos.heading), 0.0, 0.0, 1.0);
            }

            //no tow between hitch
            else
            {
                gl.Rotate(glm.toDegrees(-mf.toolPos.heading), 0.0, 0.0, 1.0);
            }
#pragma warning restore CS1690 // Accessing a member on a field of a marshal-by-reference class may cause a runtime exception

            //draw the hitch if trailing
            if (isToolTrailing)
            {
                gl.LineWidth(2);
                gl.Color(0.7f, 0.7f, 0.97f);

                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(0, trailingTool, 0);
                gl.Vertex(0, 0, 0);
                gl.End();
            }

            //draw the sections
            gl.LineWidth(8);
            gl.Begin(OpenGL.GL_LINES);

            //draw section line
            if (mf.section[numOfSections].isSectionOn)
            {
                if (mf.section[0].manBtnState == FormGPS.manBtn.Auto)
                {
                    gl.Color(0.0f, 0.97f, 0.0f);
                }
                else
                {
                    gl.Color(0.99, 0.99, 0);
                }
                gl.Vertex(mf.section[numOfSections].positionLeft, trailingTool, 0);
                gl.Vertex(mf.section[numOfSections].positionRight, trailingTool, 0);
            }
            else
            {
                for (int j = 0; j < mf.vehicle.numOfSections; j++)
                {
                    //if section is on, green, if off, red color
                    if (mf.section[j].isSectionOn)
                    {
                        if (mf.section[j].manBtnState == FormGPS.manBtn.Auto)
                        {
                            gl.Color(0.0f, 0.97f, 0.0f);
                        }
                        else
                        {
                            gl.Color(0.97, 0.97, 0);
                        }
                    }
                    else
                    {
                        gl.Color(0.97f, 0.2f, 0.2f);
                    }

                    //draw section line
                    gl.Vertex(mf.section[j].positionLeft, trailingTool, 0);
                    gl.Vertex(mf.section[j].positionRight, trailingTool, 0);
                }
            }

            gl.End();

            //draw section markers if close enough
            if (mf.camera.camSetDistance > -1500)
            {
                gl.Color(0.0f, 0.0f, 0.0f);
                //section markers
                gl.PointSize(4.0f);
                gl.Begin(OpenGL.GL_POINTS);
                for (int j = 0; j < mf.vehicle.numOfSections - 1; j++)
                {
                    gl.Vertex(mf.section[j].positionRight, trailingTool, 0);
                }
                gl.End();
            }

            //draw vehicle
            gl.PopMatrix();
            gl.Rotate(glm.toDegrees(-mf.fixHeading), 0.0, 0.0, 1.0);

            //draw the vehicle Body
            gl.Color(0.9, 0.5, 0.30);
            gl.Begin(OpenGL.GL_TRIANGLE_FAN);

            gl.Vertex(0, 0, -0.2);
            gl.Vertex(1.8, -antennaPivot, 0.0);
            gl.Vertex(0, -antennaPivot + wheelbase, 0.0);
            gl.Color(0.20, 0.0, 0.9);
            gl.Vertex(-1.8, -antennaPivot, 0.0);
            gl.Vertex(1.8, -antennaPivot, 0.0);
            gl.End();

            //draw the area side marker
            gl.Color(0.95f, 0.90f, 0.0f);
            gl.PointSize(4.0f);
            gl.Begin(OpenGL.GL_POINTS);

            //antenna
            gl.Color(0.0f, 0.98f, 0.0f);
            gl.Vertex(0, 0, 0);

            //hitch pin
            gl.Color(0.99f, 0.0f, 0.0f);
            gl.Vertex(0, mf.vehicle.hitchLength - antennaPivot, 0);

            ////rear Tires
            //gl.PointSize(12.0f);
            //gl.Color(0, 0, 0);
            //gl.Vertex(-1.8, 0, -antennaPivot);
            //gl.Vertex(1.8, 0, -antennaPivot);
            gl.End();

            gl.LineWidth(1);
            gl.Color(0.9, 0.95, 0.10);
            gl.Begin(OpenGL.GL_LINE_STRIP);
            {
                gl.Vertex(1.2, -antennaPivot + wheelbase + 8, 0.0);
                gl.Vertex(0, -antennaPivot + wheelbase + 10, 0.0);
                gl.Vertex(-1.2, -antennaPivot + wheelbase + 8, 0.0);
            }
            gl.End();

            //draw the rigid hitch
            gl.Color(0.37f, 0.37f, 0.97f);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(0, mf.vehicle.hitchLength - antennaPivot, 0);
            gl.Vertex(0, -antennaPivot, 0);
            gl.End();

            gl.LineWidth(1);
        }
示例#39
0
        public void DrawVehicle()
        {
            //translate and rotate at pivot axle
            gl.Translate(mf.fixPosX, 0, mf.fixPosZ);
            gl.PushMatrix();

            //most complicated translate ever!
            gl.Translate((Math.Sin(mf.fixHeading) * (hitchLength - antennaPivot)), 0, (Math.Cos(mf.fixHeading) * (hitchLength - antennaPivot)));
            gl.Rotate(glm.toDegrees(mf.fixHeadingSection), 0.0, 1.0, 0.0);

            //settings doesn't change trailing hitch length if set to rigid, so do it here
            double trailing;

            if (isToolTrailing)
            {
                trailing = toolTrailingHitchLength;
            }
            else
            {
                trailing = 0;
            }

            //draw the sections
            gl.LineWidth(4);
            gl.Begin(OpenGL.GL_LINES);

            //draw section line
            if (mf.section[numOfSections].isSectionOn)
            {
                gl.Color(0.97f, 0.297f, 0.97f);
                gl.Vertex(mf.section[numOfSections].positionLeft, 0, trailing);
                gl.Vertex(mf.section[numOfSections].positionRight, 0, trailing);
            }

            else
            {
                for (int j = 0; j < mf.vehicle.numOfSections; j++)
                {
                    //if section is on green, if off red color
                    if (mf.section[j].isSectionOn)
                    {
                        if (mf.section[j].manBtnState == AgOpenGPS.FormGPS.manBtn.Auto)
                        {
                            gl.Color(0.0f, 0.97f, 0.0f);
                        }
                        else
                        {
                            gl.Color(0.99, 0.99, 0);
                        }
                    }
                    else
                    {
                        gl.Color(0.97f, 0.2f, 0.2f);
                    }

                    //draw section line
                    gl.Vertex(mf.section[j].positionLeft, 0, trailing);
                    gl.Vertex(mf.section[j].positionRight, 0, trailing);
                }
            }
            gl.End();

            //draw the hitch
            gl.LineWidth(2);
            gl.Color(0.0f, 0.0f, 0.0f);

            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(0, 0, trailing);
            gl.Vertex(0, 0, 0);
            gl.End();

            if (mf.camera.camSetDistance > -2000)
            {
                //section markers
                gl.PointSize(4.0f);
                gl.Begin(OpenGL.GL_POINTS);
                for (int j = 0; j < mf.vehicle.numOfSections - 1; j++)
                {
                    gl.Vertex(mf.section[j].positionRight, 0, trailing);
                }
                gl.End();
            }

            //draw vehicle
            gl.PopMatrix();
            gl.Rotate(glm.toDegrees(mf.fixHeading), 0.0, 1.0, 0.0);

            //draw the vehicle Body
            gl.Color(0.9, 0.5, 0.30);
            gl.Begin(OpenGL.GL_TRIANGLE_FAN);

            gl.Vertex(0, -0.2, 0);
            gl.Vertex(1.8, 0.0, -antennaPivot);
            gl.Vertex(0, 0.0, -antennaPivot + wheelbase);
            gl.Color(0.20, 0.0, 0.9);
            gl.Vertex(-1.8, 0.0, -antennaPivot);
            gl.Vertex(1.8, 0.0, -antennaPivot);
            gl.End();

            //draw the area side marker
            gl.Color(0.95f, 0.90f, 0.0f);
            gl.PointSize(4.0f);
            gl.Begin(OpenGL.GL_POINTS);
            if (mf.isAreaOnRight)
            {
                gl.Vertex(2.0, 0, -antennaPivot);
            }
            else
            {
                gl.Vertex(-2.0, 0, -antennaPivot);
            }


            ////antenna
            //gl.Color(0.0f, 0.98f, 0.0f);
            //gl.Vertex(0, 0, 0);

            //hitch pin
            gl.Color(0.99f, 0.0f, 0.0f);
            gl.Vertex(0, 0, mf.vehicle.hitchLength - antennaPivot);

            ////rear Tires
            //gl.PointSize(12.0f);
            //gl.Color(0, 0, 0);
            //gl.Vertex(-1.8, 0, -antennaPivot);
            //gl.Vertex(1.8, 0, -antennaPivot);



            gl.End();
            gl.LineWidth(1);
        }
示例#40
0
        //draw the red follow me line
        public void DrawContourLine()
        {
            //gl.Color(0.98f, 0.98f, 0.50f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            ////for (int h = 0; h < ptCount; h++) gl.Vertex(guideList[h].x, 0, guideList[h].z);
            //gl.Vertex(boxE.easting, boxE.northing, 0);
            //gl.Vertex(boxA.easting, boxA.northing, 0);
            //gl.Vertex(boxD.easting, boxD.northing, 0);
            //gl.Vertex(boxE.easting, boxE.northing, 0);
            //gl.End();

            //gl.Begin(OpenGL.GL_LINE_STRIP);
            ////for (int h = 0; h < ptCount; h++) gl.Vertex(guideList[h].x, 0, guideList[h].z);
            //gl.Vertex(boxF.easting, boxF.northing, 0);
            //gl.Vertex(boxC.easting, boxC.northing, 0);
            //gl.Vertex(boxB.easting, boxB.northing, 0);
            //gl.Vertex(boxF.easting, boxF.northing, 0);
            //gl.End();

            ////draw the guidance line
            int ptCount = ctList.Count;
            gl.LineWidth(2);
            gl.Color(0.98f, 0.2f, 0.0f);
            gl.Begin(OpenGL.GL_LINE_STRIP);
            for (int h = 0; h < ptCount; h++) gl.Vertex(ctList[h].easting, ctList[h].northing, 0);
            gl.End();

            //gl.PointSize(2.0f);
            //gl.Begin(OpenGL.GL_POINTS);

            //gl.Color(0.7f, 0.7f, 0.25f);
            //for (int h = 0; h < ptCount; h++) gl.Vertex(ctList[h].easting, ctList[h].northing, 0);

            //gl.End();
            //gl.PointSize(1.0f);

            ////draw the reference line
            //gl.PointSize(3.0f);
            ////if (isContourBtnOn)
            //{
            //    ptCount = stripList.Count;
            //    if (ptCount > 0)
            //    {
            //        ptCount = stripList[closestRefPatch].Count;
            //        gl.Begin(OpenGL.GL_POINTS);
            //        for (int i = 0; i < ptCount; i++)
            //        {
            //            gl.Vertex(stripList[closestRefPatch][i].easting, stripList[closestRefPatch][i].northing);
            //        }
            //        gl.End();
            //    }
            //}

            //ptCount = conList.Count;
            //if (ptCount > 0)
            //{
            //    //draw closest point and side of line points
            //    gl.Color(0.5f, 0.900f, 0.90f);
            //    gl.PointSize(4.0f);
            //    gl.Begin(OpenGL.GL_POINTS);
            //    for (int i = 0; i < ptCount; i++) gl.Vertex(conList[i].x, conList[i].z, 0);
            //    gl.End();

            //    //gl.Color(0.35f, 0.30f, 0.90f);
            //    //gl.PointSize(6.0f);
            //    //gl.Begin(OpenGL.GL_POINTS);
            //    //gl.Vertex(conList[closestRefPoint].x, conList[closestRefPoint].z, 0);
            //    //gl.End();
            //}
            if (mf.isPureDisplayOn)
            {
                const int numSegments = 100;
                {
                    gl.Color(0.95f, 0.30f, 0.950f);

                    double theta = glm.twoPI / (numSegments);
                    double c = Math.Cos(theta);//precalculate the sine and cosine
                    double s = Math.Sin(theta);

                    double x = ppRadiusCT;//we start at angle = 0
                    double y = 0;

                    gl.LineWidth(1);
                    gl.Begin(OpenGL.GL_LINE_LOOP);
                    for (int ii = 0; ii < numSegments; ii++)
                    {
                        //glVertex2f(x + cx, y + cy);//output vertex
                        gl.Vertex(x + radiusPointCT.easting, y + radiusPointCT.northing);//output vertex

                        //apply the rotation matrix
                        double t = x;
                        x = (c * x) - (s * y);
                        y = (s * t) + (c * y);
                    }
                    gl.End();

                    //Draw lookahead Point
                    gl.PointSize(4.0f);
                    gl.Begin(OpenGL.GL_POINTS);

                    //gl.Color(1.0f, 1.0f, 0.25f);
                    //gl.Vertex(rEast, rNorth, 0.0);

                    gl.Color(1.0f, 0.5f, 0.95f);
                    gl.Vertex(goalPointCT.easting, goalPointCT.northing, 0.0);

                    gl.End();
                    gl.PointSize(1.0f);
                }
            }
        }
示例#41
0
        /// <summary>
        /// This function creates the internal display lists.
        /// </summary>
        /// <param name="gl">OpenGL object.</param>
        public virtual void Create(OpenGL gl)
        {
            //	Create the arrow.
            arrow.Generate(gl);
            arrow.New(gl, DisplayList.DisplayListMode.Compile);

                //	Draw the 'line' of the arrow.
                gl.Begin(OpenGL.LINES);
                gl.Vertex(0, 0, 0);
                gl.Vertex(0, 0, 1);
                gl.End();

                //	Draw the arrowhead.
                gl.Begin(OpenGL.TRIANGLE_FAN);
                gl.Vertex(0, 0, 1);
                gl.Vertex(0.2f, 0.8f, 0.2f);
                gl.Vertex(0.2f, 0.8f, -0.2f);
                gl.Vertex(-0.2f, 0.8f, -0.2f);
                gl.Vertex(-0.2f, 0.8f, 0.2f);
                gl.End();

            //	End the arrow list.
            arrow.End(gl);

            //	Create the grid.
            grid.Generate(gl);
            grid.New(gl, DisplayList.DisplayListMode.Compile);

                gl.PushAttrib(OpenGL.LIGHTING_BIT);
                gl.Disable(OpenGL.LIGHTING);

                gl.Color(1, 1, 1);

                gl.Begin(OpenGL.LINES);
                for(int i = -10; i <= 10; i++)
                {
                    gl.Vertex(i, 0, -10);
                    gl.Vertex(i, 0, 10);
                    gl.Vertex(-10, 0, i);
                    gl.Vertex(10, 0, i);
                }

                gl.End();

                gl.PopAttrib();

            grid.End(gl);

            //	Create the axies.
            axies.Generate(gl);
            axies.New(gl, DisplayList.DisplayListMode.Compile);

                gl.PushAttrib(OpenGL.ALL_ATTRIB_BITS);
                gl.Disable(OpenGL.LIGHTING);
                gl.Disable(OpenGL.DEPTH_TEST);
                gl.LineWidth(2.0f);

                gl.Begin(OpenGL.LINES);
                    gl.Color(1, 0, 0, 1);
                    gl.Vertex(0, 0, 0);
                    gl.Vertex(3, 0, 0);
                    gl.Color(0, 1, 0, 1);
                    gl.Vertex(0, 0, 0);
                    gl.Vertex(0, 3, 0);
                    gl.Color(0, 0, 1, 1);
                    gl.Vertex(0, 0, 0);
                    gl.Vertex(0, 0, 3);
                gl.End();

                gl.PopAttrib();

            axies.End(gl);

            camera.Generate(gl);
            camera.New(gl, DisplayList.DisplayListMode.Compile);

                Polygon poly = new Polygon();
                poly.CreateCube();
                poly.Scale.Set(.2f ,0.2f, 0.2f);
                poly.Draw(gl);
            //	poly.Dispose();

            camera.End(gl);
        }
        //以下OpenGLの処理内容
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)//描画内容を書く
        {
            if ((bool)Forward_Kinematics_Check.IsChecked)
            {
                this.J0_Slider.IsEnabled = true;
                this.J1_Slider.IsEnabled = true;
                this.J2_Slider.IsEnabled = true;
                this.J3_Slider.IsEnabled = true;
                this.J4_Slider.IsEnabled = true;
                JointAngle[0]            = J0_Slider.Value;
                JointAngle[1]            = J1_Slider.Value;
                JointAngle[2]            = J2_Slider.Value;
                JointAngle[3]            = J3_Slider.Value;
                JointAngle[4]            = J4_Slider.Value;
                J0_TextBox.Text          = JointAngle[0].ToString("F2");
                J1_TextBox.Text          = JointAngle[1].ToString("F2");
                J2_TextBox.Text          = JointAngle[2].ToString("F2");
                J3_TextBox.Text          = JointAngle[3].ToString("F2");
                J4_TextBox.Text          = JointAngle[4].ToString("F2");
            }
            else
            {
                this.J0_Slider.IsEnabled = false;
                this.J1_Slider.IsEnabled = false;
                this.J2_Slider.IsEnabled = false;
                this.J3_Slider.IsEnabled = false;
                this.J4_Slider.IsEnabled = false;
            }
            if ((bool)Inverse_Kinematics_Check.IsChecked)
            {
                X_Pos          = X_Slider.Value;
                Y_Pos          = Y_Slider.Value;
                X_TextBox.Text = X_Pos.ToString("F2");
                Y_TextBox.Text = Y_Pos.ToString("F2");
                int i, j, k, e = 3;
                double[,] Jacob =
                {
                    { -h1 * Math.Sin(theta[1]) - h2 * Math.Sin(theta[1] + theta[2]) - (h3) * Math.Sin(theta[1] + theta[2] + theta[3]),
                      -h2 * Math.Sin(theta[1] + theta[2]) - (h3) * Math.Sin(theta[1] + theta[2] + theta[3]),
                      -(h3) * Math.Sin(theta[1] + theta[2] + theta[3]) },
                    { h1 *Math.Cos(theta[1]) + h2 * Math.Cos(theta[1] + theta[2]) + (h3) * Math.Cos(theta[1] + theta[2] + theta[3]),
                      h2 *Math.Cos(theta[1] + theta[2]) + (h3) * Math.Cos(theta[1] + theta[2] + theta[3]),
                      (h3) * Math.Cos(theta[1] + theta[2] + theta[3]) },
                    {                                                                                                              -1,-1, -1 }
                };              //ヤコビを定義

                double[] Func =
                {
                    h1 *Math.Cos(theta[1]) + h2 * Math.Cos(theta[1] + theta[2]) + (h3) * Math.Cos(theta[1] + theta[2] + theta[3]) - X_Pos,
                    h1 *Math.Sin(theta[1]) + h2 * Math.Sin(theta[1] + theta[2]) + (h3) * Math.Sin(theta[1] + theta[2] + theta[3]) - Y_Pos,
                    -(theta[1] + theta[2] + theta[3]) - T
                };

                for (i = 0; i < e; i++)
                {
                    for (j = 0; j < e; j++)
                    {
                        a[i, j] = Jacob[i, j];
                        b[i, j] = Func[i];
                    }
                }
                for (i = 0; i < e; i++)
                {
                    for (j = 0; j < e; j++)
                    {
                        inv[i, j] = 0.0;
                        if (i == j)
                        {
                            inv[i, j] = 1.0;//対角を1
                        }
                    }
                }
                for (i = 0; i < e; i++)
                {                             //要素数だけループ
                    double buf = a[i, i];     //元の対角成分をバッファをコピー
                    for (j = 0; j < e; j++)
                    {                         //行要素分だけループ
                        a[i, j]   *= 1 / buf; //バッファで行成分をすべて割る
                        inv[i, j] *= 1 / buf; //単位行列の行成分を割る。
                    }
                    for (j = 0; j < e; j++)
                    {
                        if (i != j)
                        {                  //対角成分ではないとき
                            buf = a[j, i]; //i列成分をバッファにコピー
                            for (k = 0; k < e; k++)
                            {
                                a[j, k]   -= a[i, k] * buf;
                                inv[j, k] -= inv[i, k] * buf;
                            }
                        }
                    }
                }
                for (i = 0; i < e; i++)
                {
                    for (j = 0; j < e; j++)
                    {
                        c[i, j] = c_old[i, j];
                        for (k = 0; k < e; k++)
                        {
                            c[i, j] += -(inv[i, k] * b[k, j]);
                        }
                        theta[i + 1] = c[i, 0];
                    }
                }
                for (i = 0; i < e; i++)
                {
                    for (j = 0; j < e; j++)
                    {
                        c_old[i, j] = c[i, j];
                        c[i, j]     = 0;
                    }
                }

                Theta[1] = (theta[1] * 180 / PI) % 360;
                Theta[2] = (theta[2] * 180 / PI) % 360;
                Theta[3] = (theta[3] * 180 / PI) % 360;

                if (Theta[1] > 180)
                {
                    Theta[1] -= 360;
                }
                if (Theta[1] < -180)
                {
                    Theta[1] += 360;
                }

                if (Theta[2] > 180)
                {
                    Theta[2] -= 360;
                }
                else if (Theta[2] < -180)
                {
                    Theta[2] += 360;
                }

                if (Theta[3] > 180)
                {
                    Theta[3] -= 360;
                }
                else if (Theta[3] < -180)
                {
                    Theta[3] += 360;
                }
                /********************************/
                if (Theta[1] > J2_ULMT)
                {
                    Theta[1] = J2_ULMT;
                }
                if (Theta[1] < J2_LLMT)
                {
                    Theta[1] = J2_LLMT;
                }
                if (Theta[2] > J3_ULMT)
                {
                    Theta[2] = J3_ULMT;
                }
                if (Theta[2] < J3_LLMT)
                {
                    Theta[2] = J3_LLMT;
                }
                if (Theta[3] > J4_ULMT)
                {
                    Theta[3] = J4_ULMT;
                }
                if (Theta[3] < J4_LLMT)
                {
                    Theta[3] = J4_LLMT;
                }

                if ((Theta[1] < 0.1 && Theta[1] > -0.1) && (Theta[2] < 0.1 && Theta[2] > -0.1) && (Theta[3] < 0.1 && Theta[3] > -0.1))
                {
                    Theta[1] = 0.1;
                    Theta[2] = 0.1;
                    Theta[3] = 0.1;
                }
                JointAngle[1] = Theta[1];
                JointAngle[2] = Theta[2];
                JointAngle[3] = Theta[3];


                /*double K = Math.Sqrt(Math.Pow(Math.Pow(X_Pos, 2) + Math.Pow(Y_Pos, 2) + Math.Pow(h1, 2) + Math.Pow(h2, 2), 2) - (2 * (Math.Pow(Math.Pow(X_Pos, 2) + Math.Pow(Y_Pos, 2), 2) + Math.Pow(h1, 4) + Math.Pow(h2, 4))));
                 * Theta[0] = Math.Atan2(Y_Pos, X_Pos) - Math.Atan2(K, (X_Pos * X_Pos) + (Y_Pos * Y_Pos) + (h2 * 2) - (h2 * 2));
                 * Theta[1] = Math.Atan2(K, (X_Pos * X_Pos) + (Y_Pos * Y_Pos) - Math.Pow(h1, 2) - Math.Pow(h2, 2));
                 * Theta[2] = 0 - (Theta[0] + Theta[1]);
                 * JointAngle[1] = Theta[0] * 180 / PI;
                 * JointAngle[2] = Theta[1] * 180 / PI;
                 * JointAngle[3] = Theta[2] * 180 / PI;
                 */


                J0_TextBox.Text = JointAngle[0].ToString("F2");
                J1_TextBox.Text = JointAngle[1].ToString("F2");
                J2_TextBox.Text = JointAngle[2].ToString("F2");
                J3_TextBox.Text = JointAngle[3].ToString("F2");
                J4_TextBox.Text = JointAngle[4].ToString("F2");
            }
            else
            {
            }


            OpenGL gl = args.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            gl.Enable(OpenGL.GL_LINE_SMOOTH);
            gl.Hint(OpenGL.GL_LINE_SMOOTH_HINT, OpenGL.GL_NICEST);
            gl.Enable(OpenGL.GL_BLEND);
            gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
            gl.LookAt(900, 900, 900, 0, 200, 0, 0, 1, 0);

            gl.Rotate(-90, 1.0f, 0.0f, 0.0f);//Z軸を上方向にするための回転

            double axis = 100, axis_R = 150;;

            gl.LineWidth(3);
            /**********座標軸**********/
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(axis_R, 0.0f, 0.0f);//X軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(0.0f, axis_R, 0.0f);//Y軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, axis_R);//Z軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.End();
            /**************************/
            gl.Rotate(JointAngle[0], 0.0f, 0.0f, 1.0f);
            gl.Translate(0, 0, h0);//平行移動(diの0)
            /**********アームh0**********/
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1.0f, 1.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Vertex(0.0f, 0.0f, -h0);
            /**********座標軸**********/
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(axis, 0.0f, 0.0f);//X軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(0.0f, axis, 0.0f);//Y軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, axis);//Z軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.End();
            /*************************/
            gl.Rotate(90, 1.0, 0.0, 0.0);//x軸回転(αの2)
            /**********座標軸**********/
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(axis, 0.0f, 0.0f);//X軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(0.0f, axis, 0.0f);//Y軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, axis);//Z軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.End();
            /**************************/
            gl.Rotate(JointAngle[1], 0.0f, 0.0f, 1.0f);
            gl.Translate(h1, 0, 0);//平行移動(Aiの3)
            /**********アームh1**********/
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1.0f, 1.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Vertex(-h1, 0.0f, 0.0f);
            /**********座標軸**********/
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(axis, 0.0f, 0.0f);//X軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(0.0f, axis, 0.0f);//Y軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, axis);//Z軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.End();
            /*************************/
            gl.Rotate(JointAngle[2], 0.0f, 0.0f, 1.0f);
            gl.Translate(h2, 0, 0);//平行移動(Aiの4)
            /**********アームh2**********/
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1.0f, 1.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Vertex(-h2, 0.0f, 0.0f);
            /**********座標軸**********/
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(axis, 0.0f, 0.0f);//X軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(0.0f, axis, 0.0f);//Y軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, axis);//Z軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.End();
            /*************************/
            gl.Rotate(JointAngle[3], 0.0f, 0.0f, 1.0f);
            gl.Rotate(90, 1.0f, 0.0f, 0.0f);
            /**********座標軸**********/
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(axis, 0.0f, 0.0f);//X軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(0.0f, axis, 0.0f);//Y軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, axis);//Z軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.End();
            /*************************/
            gl.Rotate(JointAngle[4], 0.0f, 0.0f, 1.0f);
            gl.Translate(0, 0, h3);//平行移動(diのHand)
            /**********アームh3**********/
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1.0f, 1.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Vertex(0.0f, 0.0f, -h3);
            /**********座標軸**********/
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(axis, 0.0f, 0.0f);//X軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(0.0f, axis, 0.0f);//Y軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(0.0f, 0.0f, axis);//Z軸
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.End();
            /**********手先**********/
            double Hand_Width = h3 / 3;

            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1.0f, 1.0f, 1.0f);
            gl.Vertex(-Hand_Width, 0.0f, -Hand_Width);
            gl.Vertex(Hand_Width, 0.0f, -Hand_Width);
            gl.Vertex(Hand_Width, 0.0f, -Hand_Width);
            gl.Vertex(Hand_Width, 0.0f, Hand_Width);
            gl.Vertex(-Hand_Width, 0.0f, -Hand_Width);
            gl.Vertex(-Hand_Width, 0.0f, Hand_Width);
            gl.End();
        }
示例#43
0
        public virtual void DrawGrid(OpenGL gl)
        {
            gl.PushAttrib(OpenGL.LINE_BIT | OpenGL.ENABLE_BIT | OpenGL.COLOR_BUFFER_BIT);

            //  Turn off lighting, set up some nice anti-aliasing for lines.
            gl.Disable(OpenGL.LIGHTING);
            gl.Hint(OpenGL.LINE_SMOOTH_HINT, OpenGL.NICEST);
            gl.Enable(OpenGL.LINE_SMOOTH);
            gl.Enable(OpenGL.BLEND);
            gl.BlendFunc(OpenGL.SRC_ALPHA, OpenGL.ONE_MINUS_SRC_ALPHA);

            //	Create the grid.
            gl.LineWidth(1.5f);

            gl.Begin(OpenGL.LINES);

                for (int i = -10; i <= 10; i++)
                {
                    gl.Color(0.2f, 0.2f, 0.2f, 1f);
                    gl.Vertex(i, 0, -10);
                    gl.Vertex(i, 0, 10);
                    gl.Vertex(-10, 0, i);
                    gl.Vertex(10, 0, i);
                }

            gl.End();

            //  Turn off the depth test for the axies.
            gl.Disable(OpenGL.DEPTH_TEST);
            gl.LineWidth(2.0f);

            //	Create the axies.
            gl.Begin(OpenGL.LINES);

                gl.Color(1f, 0f, 0f, 1f);
                gl.Vertex(0f, 0f, 0f);
                gl.Vertex(3f, 0f, 0f);
                gl.Color(0f, 1f, 0f, 1f);
                gl.Vertex(0f, 0f, 0f);
                gl.Vertex(0f, 3f, 0f);
                gl.Color(0f, 0f, 1f, 1f);
                gl.Vertex(0f, 0f, 0f);
                gl.Vertex(0f, 0f, 3f);

            gl.End();

            gl.PopAttrib();

               //     gl.Flush();
        }
        public void render()
        {
            if (visible)
            {
                if (fbgaMode)
                {
                    //  Get the OpenGL object.
                    OpenGL gl = openGLControl.OpenGL;

                    float x, y;

                    gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);                          //  Clear the color and depth buffer.
                    gl.DrawText(0, (int)(0.1428 * gl.RenderContextProvider.Height), 0.0f, 0f, 0f, null, 9f, string.Format("{0:#0.##}", (float)2000.0 / scale_factor));
                    gl.DrawText(0, (int)(0.857 * gl.RenderContextProvider.Height), 0.0f, 0f, 0f, null, 9f, string.Format("{0:#0.##}", (float)60000.0 / scale_factor));
                    gl.DrawText(0, (int)(0.5 * gl.RenderContextProvider.Height), 0.0f, 0f, 0f, null, 9f, string.Format("{0:#0.##}", (float)(2000.0 + 60000.0) / (scale_factor * 2.0)));

                    gl.LoadIdentity();
                    gl.Color(r, g, b);
                    gl.LineWidth(1.5f);
                    gl.Begin(OpenGL.GL_LINE_STRIP);
                    // gl.Vertex(0.0f, 0.0f, 0.0f);
                    // gl.Vertex(4.0f, 1.0f, 0.0f);

                    for (int i = 0; i < 512; i++)
                    {
                        y = ((float)array.intArray[i] - (float)2000.0) / ((float)60000.0 - (float)2000.0);
                        x = (float)(dx * i);
                        gl.Vertex((float)x, (float)y, 0.0f);
                    }
                }
                else
                {
                    //  Get the OpenGL object.
                    OpenGL gl = openGLControl.OpenGL;

                    float  x, y;
                    double temp_max = 0.0;
                    double temp_min = 0.0;

                    if (iterator > (array.index + 300))
                    {
                        temp_max      = max_y + (max_y - min_y) * 0.1;
                        max_y_current = (int)temp_max;
                        temp_min      = min_y - (max_y - min_y) * 0.1;
                        min_y_current = (int)temp_min;
                        max_y         = -16777216;
                        min_y         = 16777216;
                    }
                    iterator = array.index;

                    gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);                          //  Clear the color and depth buffer.
                    gl.DrawText(0, (int)(0.1428 * gl.RenderContextProvider.Height), 0.0f, 0f, 0f, null, 9f, string.Format("{0:#0.##}", (float)min_y_current / scale_factor));
                    gl.DrawText(0, (int)(0.857 * gl.RenderContextProvider.Height), 0.0f, 0f, 0f, null, 9f, string.Format("{0:#0.##}", (float)max_y_current / scale_factor));
                    gl.DrawText(0, (int)(0.5 * gl.RenderContextProvider.Height), 0.0f, 0f, 0f, null, 9f, string.Format("{0:#0.##}", (float)(min_y_current + max_y_current) / (scale_factor * 2.0)));



                    gl.LoadIdentity();
                    gl.Color(r, g, b);
                    gl.LineWidth(1.5f);
                    gl.Begin(OpenGL.GL_LINE_STRIP);
                    // gl.Vertex(0.0f, 0.0f, 0.0f);
                    // gl.Vertex(4.0f, 1.0f, 0.0f);

                    for (int i = 0; i < iterator; i++)
                    {
                        if (min_y_current != max_y_current)
                        {
                            //previous_data_float = ((float)previous_y - (float)min_y_current) / ((float)max_y_current - (float)min_y_current); // (float)(16777216.0);
                            //y = array.intArray[iterator]  / (float)(7216.0);
                            y = ((float)array.intArray[i] - (float)min_y_current) / ((float)max_y_current - (float)min_y_current);
                            if (y < 0)
                            {
                                previous_data_float = array.intArray[i];
                                previous_data_float = 0;
                            }
                        }
                        else
                        {
                            previous_data_float = 0.5f;
                            y = 0.5f;
                        }
                        if (array.intArray[i] > max_y)
                        {
                            max_y        = array.intArray[i];
                            iterator_max = iterator;
                        }

                        if (array.intArray[i] < min_y)
                        {
                            min_y        = array.intArray[i];
                            iterator_min = iterator;
                        }

                        x = (float)(dx * i);
                        gl.Vertex((float)x, (float)y, 0.0f);
                    }



                    //  Rotate around the Y axis.

                    /*               gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
                     *
                     *              //  Draw a coloured pyramid.
                     *              gl.Begin(OpenGL.GL_TRIANGLES);
                     *              gl.Color(1.0f, 0.0f, 0.0f);
                     *              gl.Vertex(0.0f, 1.0f, 0.0f);
                     *              gl.Color(0.0f, 1.0f, 0.0f);
                     *              gl.Vertex(-1.0f, -1.0f, 1.0f);
                     *              gl.Color(0.0f, 0.0f, 1.0f);
                     *              gl.Vertex(1.0f, -1.0f, 1.0f);
                     *              gl.Color(1.0f, 0.0f, 0.0f);
                     *              gl.Vertex(0.0f, 1.0f, 0.0f);
                     *              gl.Color(0.0f, 0.0f, 1.0f);
                     *              gl.Vertex(1.0f, -1.0f, 1.0f);
                     *              gl.Color(0.0f, 1.0f, 0.0f);
                     *              gl.Vertex(1.0f, -1.0f, -1.0f);
                     *              gl.Color(1.0f, 0.0f, 0.0f);
                     *              gl.Vertex(0.0f, 1.0f, 0.0f);
                     *              gl.Color(0.0f, 1.0f, 0.0f);
                     *              gl.Vertex(4.0f, -1.0f, -1.0f);
                     *              gl.Color(0.0f, 0.0f, 1.0f);
                     *              gl.Vertex(-1.0f, -1.0f, -1.0f);
                     *              gl.Color(1.0f, 0.0f, 0.0f);
                     *              gl.Vertex(0.0f, 1.0f, 0.0f);
                     *              gl.Color(0.0f, 0.0f, 1.0f);
                     *              gl.Vertex(-1.0f, -1.0f, -1.0f);
                     *              gl.Color(0.0f, 1.0f, 0.0f);
                     *              gl.Vertex(-1.0f, -1.0f, 1.0f);
                     *              gl.End();
                     *
                     *              //  Nudge the rotation.
                     *              rotation += 3.0f;*/


                    gl.End();
                    gl.Flush();
                    openGLControl.InvalidateArrange();
                }
            }
            // }
        }
示例#45
0
文件: Line.cs 项目: nromik/sharpgl
        /// <summary>
        /// This is the function that you must override to draw the line.
        /// The code is commented step by step.
        /// </summary>
        public override void Draw(OpenGL gl)
        {
            //	This is the first function that must be called, DoPreDraw. It basicly
            //	sets up certain settings and organises the stack so that what you draw
            //	now doesn't interfere with what you will draw next.
            DoPreDraw(gl);

            //	This next code saves the current line attributes, then sets the line
            //	attributes for this line.
            lineAttributes.Set(gl);

            //	Begin drawing lines.
            gl.Begin(OpenGL.LINES);

            //	Add the two vertices.
            gl.Vertex(point1);
            gl.Vertex(point2);

            //	End the drawing.
            gl.End();

            //	Restore the previous line settings.
            lineAttributes.Restore(gl);

            //	Finalise the drawing process.
            DoPostDraw(gl);
        }
示例#46
0
        public override void Draw(OpenGL gl)
        {
            if(DoPreDraw(gl))
            {

                //	Set our line settings.
                lineSettings.Set(gl);

                //	Create the evaluator.
                gl.Map1(OpenGL.MAP1_VERTEX_3,//	Use and produce 3D points.
                    0,								//	Low order value of 'u'.
                    1,								//	High order value of 'u'.
                    3,								//	Size (bytes) of a control point.
                    controlPoints.Width,			//	Order (i.e degree plus one).
                    controlPoints.ToFloatArray());	//	The control points.

                //	Enable the type of evaluator we wish to use.
                gl.Enable(OpenGL.MAP1_VERTEX_3);

                //	Beging drawing a line strip.
                gl.Begin(OpenGL.LINE_STRIP);

                //	Now draw it.
                for(int i = 0; i <= segments; i++)
                    gl.EvalCoord1((float) i / segments);

                gl.End();

                //	Draw the control points.
                controlPoints.Draw(gl, drawPoints, drawLines);

                //	Restore the line attributes.
                lineSettings.Restore(gl);

                DoPostDraw(gl);
            }
        }