Esempio n. 1
0
        void RenderableWater_WriteNextFrameEvent(Vector3 camerapos)
        {
            double           xmultiplier = scale.x / numsectors;
            double           ymultiplier = scale.y / numsectors;
            GraphicsHelperGl g           = new GraphicsHelperGl();

            g.SetMaterialColor(new double[] { 0, 0.2, 0.8, 0.6 });
            g.EnableBlendSrcAlpha();
            g.EnableModulate();
            g.DisableTexture2d(); // note to self: could add texture??? (or vertex fragment)
            g.Normal(new Vector3(0, 0, 1));
            for (int x = 0; x < numsectors; x++)
            {
                Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
                for (int y = numsectors; y >= 0; y--)
                {
                    Vector3 posoffset = new Vector3(x * xmultiplier, y * ymultiplier, 0);
                    Vector3 vertexpos = pos + posoffset;
                    //Console.WriteLine(vertexpos);
                    g.Vertex(vertexpos);
                    vertexpos.x += xmultiplier;
                    //Console.WriteLine(vertexpos);
                    g.Vertex(vertexpos);
                }
                Gl.glEnd();
            }
            Gl.glDisable(Gl.GL_BLEND);
            g.SetMaterialColor(new double[] { 1, 1, 1, 1 });
        }
Esempio n. 2
0
        void RenderUnitPart(UnitPart unitpart)
        {
            Gl.glPushMatrix();
            g.Translate(unitpart.Offset);
            switch (unitpart.PrimitiveType)
            {
            case UnitPart.PrimitiveTypeEnum.Triangles:
            {
                Gl.glBegin(Gl.GL_TRIANGLES);
                foreach (Primitive primitive in unitpart.Primitives)
                {
                    Triangle triangle = primitive as Triangle;
                    g.Normal(triangle.Vertices[0].Normal);
                    g.TexCoord(triangle.Vertices[0].TextureCoords);
                    g.Vertex(triangle.Vertices[0].Pos);

                    g.Normal(triangle.Vertices[1].Normal);
                    g.TexCoord(triangle.Vertices[1].TextureCoords);
                    g.Vertex(triangle.Vertices[1].Pos);

                    g.Normal(triangle.Vertices[2].Normal);
                    g.TexCoord(triangle.Vertices[2].TextureCoords);
                    g.Vertex(triangle.Vertices[2].Pos);
                }
                Gl.glEnd();
                break;
            }

            case UnitPart.PrimitiveTypeEnum.Quads:
            {
                Gl.glBegin(Gl.GL_QUADS);
                foreach (Primitive primitive in unitpart.Primitives)
                {
                    Quad quad = primitive as Quad;
                    g.Normal(quad.Vertices[0].Normal);
                    g.TexCoord(quad.Vertices[0].TextureCoords);
                    g.Vertex(quad.Vertices[0].Pos);

                    g.Normal(quad.Vertices[1].Normal);
                    g.TexCoord(quad.Vertices[1].TextureCoords);
                    g.Vertex(quad.Vertices[1].Pos);

                    g.Normal(quad.Vertices[2].Normal);
                    g.TexCoord(quad.Vertices[2].TextureCoords);
                    g.Vertex(quad.Vertices[2].Pos);

                    g.Normal(quad.Vertices[3].Normal);
                    g.TexCoord(quad.Vertices[3].TextureCoords);
                    g.Vertex(quad.Vertices[3].Pos);
                }
                Gl.glEnd();
                break;
            }

            case UnitPart.PrimitiveTypeEnum.TriangleStrips:
            {
                foreach (Primitive primitive in unitpart.Primitives)
                {
                    TriangleStrip trianglestrip = primitive as TriangleStrip;
                    Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
                    foreach (Vertex vertex in trianglestrip.Vertices)
                    {
                        g.Normal(vertex.Normal);
                        g.TexCoord(vertex.TextureCoords);
                        g.Vertex(vertex.Pos);
                    }
                    Gl.glEnd();
                }
                break;
            }
            }

            foreach (UnitPart childunitpart in unitpart.Children)
            {
                RenderUnitPart(childunitpart);
            }
            Gl.glPopMatrix();
        }