コード例 #1
0
ファイル: Cube.cs プロジェクト: PlumpMath/CG_4_OpenGLScene
        public override void Draw(SharpGL.OpenGL gl)
        {
            gl.PushMatrix();
            float halfSize = size / 2;

            gl.Translate(position.x, position.y + halfSize, position.z);
            gl.Color(color.GetInArrWithAlpha());
            Point3D[] vertex = new Point3D[]
            {
                new Point3D(halfSize, halfSize, halfSize),
                new Point3D(-halfSize, halfSize, halfSize),
                new Point3D(-halfSize, -halfSize, halfSize),
                new Point3D(halfSize, -halfSize, halfSize),
                new Point3D(halfSize, halfSize, -halfSize),
                new Point3D(-halfSize, halfSize, -halfSize),
                new Point3D(-halfSize, -halfSize, -halfSize),
                new Point3D(halfSize, -halfSize, -halfSize)
            };
            DrawPrimitive.Quard(gl, vertex[0], vertex[1], vertex[2], vertex[3], false);
            DrawPrimitive.Quard(gl, vertex[0], vertex[4], vertex[5], vertex[1], false);
            DrawPrimitive.Quard(gl, vertex[7], vertex[6], vertex[5], vertex[4], false);
            DrawPrimitive.Quard(gl, vertex[3], vertex[2], vertex[6], vertex[7], false);
            DrawPrimitive.Quard(gl, vertex[1], vertex[5], vertex[6], vertex[2], false);
            DrawPrimitive.Quard(gl, vertex[0], vertex[3], vertex[7], vertex[4], false);
            gl.PopMatrix();
        }
コード例 #2
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            gl.PushMatrix();
            gl.Translate(position.x, position.y, position.z);
            gl.Rotate(-90, 1, 0, 0);
            int   iPivot = 1;
            float x, y;

            //gl.Begin(BeginMode.TriangleFan);
            {
                //gl.Vertex(0f, 0f, size);
                Point3D top       = new Point3D(0f, 0f, size);
                Point3D prevPoint = null;
                for (float angle = 0; angle <= (2f * Math.PI) + (((float)Math.PI / doubledFaceNumber) / 2); angle += ((float)Math.PI / doubledFaceNumber))
                {
                    y = size * (float)Math.Sin(angle);
                    x = size * (float)Math.Cos(angle);
                    if ((iPivot++ % 2) == 0)
                    {
                        gl.Color(0f, 1f, 0f);
                    }
                    else
                    {
                        gl.Color(1f, 0f, 0f);
                    }
                    //gl.Vertex(x, y);
                    if (prevPoint != null)
                    {
                        DrawPrimitive.Triangle(gl, top, prevPoint, new Point3D(x, y), false);
                    }
                    prevPoint = new Point3D(x, y);
                }
            }
            //gl.End();
            //основание
            gl.Begin(BeginMode.TriangleFan);
            {
                gl.Normal(0, 0, -1f);
                gl.Vertex(0f, 0f, 0f);
                for (float angle = 0; angle <= (2f * Math.PI) + (((float)Math.PI / doubledFaceNumber) / 2); angle += ((float)Math.PI / doubledFaceNumber))
                {
                    x = size * (float)Math.Sin(angle);
                    y = size * (float)Math.Cos(angle);
                    if ((iPivot++ % 2) == 0)
                    {
                        gl.Color(0f, 1f, 0f);
                    }
                    else
                    {
                        gl.Color(1f, 0f, 0f);
                    }
                    gl.Vertex(x, y);
                }
            }
            gl.End();

            gl.PopMatrix();
        }
コード例 #3
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            gl.PushMatrix();
            gl.Translate(position.x, position.y + Z * scaleKoef, position.z);
            gl.Scale(scaleKoef, scaleKoef, scaleKoef);
            int i;

            gl.Color(color.GetInArrWithAlpha());

            //float[] specular1 = { 1, 1, 1, 1 };
            //gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_SPECULAR, specular1);
            //gl.Material(OpenGL.GL_FRONT, OpenGL.GL_SHININESS, 128);

            for (i = 0; i < 20; i++)
            {
                DrawPrimitive.Triangle(gl, new Point3D(vdata[tindices[i][0]]),
                                       new Point3D(vdata[tindices[i][1]]),
                                       new Point3D(vdata[tindices[i][2]]), false);
            }
            gl.PopMatrix();
        }