Exemple #1
0
        void RenderableAllFeatures_WriteNextFrameEvent(Vector3 camerapos)
        {
            //Console.WriteLine("raf writenextframe");
            GraphicsHelperGl g       = new GraphicsHelperGl();
            FrustrumCulling  culling = FrustrumCulling.GetInstance();

            foreach (FeatureInfo featureinfo in features)
            {
                Vector3 displaypos = new Vector3(featureinfo.x * Terrain.SquareSize, featureinfo.y * Terrain.SquareSize,
                                                 parent.Map[featureinfo.x, featureinfo.y]);
                //  Console.WriteLine("displaypos: " + displaypos );
                if (culling.IsInsideFrustum(displaypos, featureinfo.unit.Radius))
                {
                    //    Console.WriteLine("culling ok");
                    g.PushMatrix();
                    g.Translate(displaypos);
                    featureinfo.unit.Render();
                    g.PopMatrix();
                }
            }
        }
Exemple #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();
        }