Exemple #1
0
        public void Draw(ShapeRenderer renderer)
        {
            renderer.SetTransform(Matrix4.Identity);

            //Draw water
            for (int i = 0; i < WaterBodies.Count; i++)
            {
                renderer.FillShape(WaterBodies[i].VertexData, new Color4(0, 174, 239, 60));
                renderer.DrawShape(WaterBodies[i].VertexData, new Color4(0, 174, 239, 255));
            }

            //Draw map entities
            for (int i = 0; i < entities.Count; i++)
            {
                entities[i].Draw(renderer);
            }

            //TODO: Consider rendering static geometry to a texture for performant rendering
            //Or put all of the static geometry into one VBO and render it in one shot, rather than
            //depend on the shape renderer

            //Draw static geometry
            for (int i = 0; i < StaticGeometry.Count; i++)
            {
                renderer.FillShape(StaticGeometry[i].VertexData, Color4.Black);
                renderer.DrawShape(StaticGeometry[i].VertexData, Color4.LimeGreen);
            }

            //Simulate world
            World.Step(0.01f);
        }
Exemple #2
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            shapeRenderer.Begin();

            //Create matrix transforms based on the body's rotation and position
            Vector2 body01Position = (body01.Position * unitToPixel) - new Vector2(25f, 25f);

            shapeRenderer.SetTransform(
                Matrix4.CreateRotationZ(body01.Rotation) *
                Matrix4.CreateTranslation(body01Position.X + 25f, body01Position.Y + 25f, 0f));
            shapeRenderer.FillShape(body01Shape, Color4.Red);
            shapeRenderer.DrawShape(body01Shape, Color4.Black);

            Vector2 body02Position = (body02.Position * unitToPixel) - new Vector2(400f, 25f);

            shapeRenderer.SetTransform(
                Matrix4.CreateRotationZ(body02.Rotation) *
                Matrix4.CreateTranslation(body02Position.X + 400f, body02Position.Y + 25f, 0f));
            shapeRenderer.FillShape(body02Shape, Color4.Blue);
            shapeRenderer.DrawShape(body02Shape, Color4.Black);
            shapeRenderer.End();

            SwapBuffers();
        }