Esempio n. 1
0
        public void drawSceneGrid(OpenGL gl)
        {
            gl.Color(0.3f, 0.3f, 0.3f);
            gl.LineWidth(0.1f);
            gl.Begin(OpenGL.GL_LINES);

            for (int i = 0; i <= n; i++)
            {
                gl.Vertex(-n / 2 + i, -n / 2, 0.0f);
                gl.Vertex(-n / 2 + i, n / 2, 0.0f);
                gl.Vertex(-n / 2, -n / 2 + i, 0.0f);
                gl.Vertex(n / 2, -n / 2 + i, 0.0f);
            }
            gl.End();

            gl.Color(0.0f, 0.0f, 1.0f); //
            drawCoordinateAxisZ(gl);
            gl.Color(0.0f, 1.0f, 0.0f);
            drawCoordinateAxisY(gl);
            gl.Color(1.0f, 0.0f, 0.0f);
            drawCoordinateAxisX(gl);
        }
Esempio n. 2
0
        public override int Draw(OpenGL gl, Texture tex)
        {
            float h    = this.Height / 2;
            float e_dx = this.Length * (float)Math.Sqrt(3.0) / 3;
            float d_dx = this.Length / (2 * (float)Math.Sqrt(3.0));
            float dy   = this.Length / 2;

            gl.PushMatrix();

            //Thực hiện các hàm biến đổi Affine
            gl.Translate(this.Translate[0], this.Translate[1], this.Translate[2]);
            gl.Scale(this.Scale[0], this.Scale[1], this.Scale[2]);
            gl.Rotate(this.Rotate[0], this.Rotate[1], this.Rotate[2]);

            for (int i = 0; i < 2; i++)
            {
                if (i == 0)
                {
                    gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_LINE);
                    if (isSelected)
                    {
                        gl.LineWidth(5.0f);
                        gl.Color(Color.Orange.R, Color.Orange.G, Color.Orange.B);
                    }
                    else
                    {
                        gl.LineWidth(1.0f);
                        gl.Color(Color.Black.R, Color.Black.G, Color.Black.B);
                    }
                }
                else
                {
                    //Set the polygon mode to be filled triangles
                    gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL);
                    gl.Color(Color.R, Color.G, Color.B);
                }

                gl.Begin(OpenGL.GL_TRIANGLES);

                //TOP
                gl.Vertex(-d_dx, -dy, h);
                gl.Vertex(-d_dx, dy, h);
                gl.Vertex(e_dx, 0, h);

                //BOT
                gl.Vertex(-d_dx, -dy, -h);
                gl.Vertex(-d_dx, dy, -h);
                gl.Vertex(e_dx, 0, -h);
                gl.End();

                gl.Begin(OpenGL.GL_QUADS);

                ////BACK
                gl.Vertex(-d_dx, dy, h);
                gl.Vertex(-d_dx, -dy, h);
                gl.Vertex(-d_dx, -dy, -h);
                gl.Vertex(-d_dx, dy, -h);

                //////LEFT
                gl.Vertex(-d_dx, -dy, h);
                gl.Vertex(e_dx, 0, h);
                gl.Vertex(e_dx, 0, -h);
                gl.Vertex(-d_dx, -dy, -h);

                //////RIGHT
                gl.Vertex(-d_dx, dy, h);
                gl.Vertex(e_dx, 0, h);
                gl.Vertex(e_dx, 0, -h);
                gl.Vertex(-d_dx, dy, -h);

                gl.End();
            }
            gl.PopMatrix();
            return(1);
        }
Esempio n. 3
0
        public override int Draw(OpenGL gl, Texture tex)
        {
            float a = this.Length / 2;
            float h = this.Height / 2;

            gl.PushMatrix();

            //Thực hiện các hàm biến đổi Affine
            gl.Translate(this.Translate[0], this.Translate[1], this.Translate[2]);
            gl.Scale(this.Scale[0], this.Scale[1], this.Scale[2]);
            gl.Rotate(this.Rotate[0], this.Rotate[1], this.Rotate[2]);

            //Hàm vẽ các mặt của ảnh

            for (int i = 0; i < 2; i++)
            {
                if (i == 0)
                {
                    gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_LINE);
                    if (isSelected)
                    {
                        gl.LineWidth(5.0f);
                        gl.Color(Color.Orange.R, Color.Orange.G, Color.Orange.B);
                    }
                    else
                    {
                        gl.LineWidth(1.0f);
                        gl.Color(Color.Black.R, Color.Black.G, Color.Black.B);
                    }
                }
                else
                {
                    //Set the polygon mode to be filled triangles
                    gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL);
                    gl.Color(Color.R, Color.G, Color.B);
                }

                gl.Begin(OpenGL.GL_QUADS);

                //BOT
                gl.TexCoord(0.0f, 0.0f); gl.Vertex(a, a, -h);    // Top Right Of The Quad (Bottom)
                gl.TexCoord(1.0f, 0.0f); gl.Vertex(a, -a, -h);   // Top Left Of The Quad (Bottom)
                gl.TexCoord(1.0f, 1.0f); gl.Vertex(-a, -a, -h);  // Bottom Left Of The Quad (Bottom)
                gl.TexCoord(0.0f, 1.0f); gl.Vertex(-a, a, -h);   // Bottom Right Of The Quad (Bottom)
                gl.End();

                gl.Begin(OpenGL.GL_TRIANGLES);

                //FRONT
                gl.TexCoord(0.0f, 0.0f); gl.Vertex(a, -a, -h);  // Top Right Of The Quad (Front)
                gl.TexCoord(1.0f, 0.0f); gl.Vertex(a, a, -h);   // Top Left Of The Quad (Front)
                gl.TexCoord(1.0f, 1.0f); gl.Vertex(0, 0, h);    // Bottom Left Of The Quad (Front)

                //BACK
                gl.TexCoord(0.0f, 0.0f); gl.Vertex(-a, a, -h);  // Top Right Of The Quad (Back)
                gl.TexCoord(1.0f, 0.0f); gl.Vertex(-a, -a, -h); // Top Left Of The Quad (Back)
                gl.TexCoord(1.0f, 1.0f); gl.Vertex(0, 0, h);    // Bottom Left Of The Quad (Back)

                ////LEFT
                gl.TexCoord(0.0f, 0.0f); gl.Vertex(a, -a, -h);  // Top Right Of The Quad (Left)
                gl.TexCoord(1.0f, 0.0f); gl.Vertex(-a, -a, -h); // Top Left Of The Quad (Left)
                gl.TexCoord(1.0f, 1.0f); gl.Vertex(0, 0, h);    // Bottom Left Of The Quad (Left)

                ////RIGHT
                gl.TexCoord(0.0f, 0.0f); gl.Vertex(-a, a, -h);  // Top Right Of The Quad (Right)
                gl.TexCoord(1.0f, 0.0f); gl.Vertex(a, a, -h);   // Top Left Of The Quad (Right)
                gl.TexCoord(1.0f, 1.0f); gl.Vertex(0, 0, h);    // Bottom Left Of The Quad (Right)
                gl.End();
            }


            gl.PopMatrix();
            return(1);
        }