protected override void OnRenderFrame(FrameEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit); shapeRenderer.Begin(); //Create matrix transforms based on the body's rotation and position Vector2 ballPosition = ball.Position * unitToPixel; shapeRenderer.SetTransform( Matrix4.CreateRotationZ(ball.Rotation) * Matrix4.CreateTranslation(ballPosition.X, ballPosition.Y, 0f)); shapeRenderer.DrawShape(rocketShape, Color4.Black); shapeRenderer.ClearTransform(); shapeRenderer.DrawRect(new Vector2(0f, 425f), new Vector2(800f, 25f), Color4.Red); foreach (Body box in boxes) { Vector2 boxPos = (box.Position * unitToPixel) - new Vector2(25f); shapeRenderer.SetTransform( Matrix4.CreateTranslation(-boxPos.X - 25f, -boxPos.Y - 25f, 0f) * Matrix4.CreateRotationZ(box.Rotation) * Matrix4.CreateTranslation(boxPos.X + 25f, boxPos.Y + 25f, 0f)); shapeRenderer.DrawRect(boxPos, new Vector2(50f), Color4.Brown); } shapeRenderer.End(); SwapBuffers(); }
public override void Draw(ShapeRenderer renderer) { Vector2 position = ConvertUnits.ToDisplayUnits(physicsBody.Position); renderer.SetTransform( Matrix4.CreateRotationZ(PhysicsBody.Rotation) * Matrix4.CreateTranslation(position.X, position.Y, 0f)); renderer.DrawShape(shape.VertexData, ColorUtils.Blend(Color4.Red, Color4.Green, currentHealth / 100f)); renderer.ClearTransform(); }