Ejemplo n.º 1
0
        public override void Draw(SpriteBatch spriteBatch, SpriteFont font, float dt)
        {
            spriteBatch.Begin();

            spriteBatch.DrawString(font, "No of bodies: " + physicsWorld.bodies.Count,
                                   new Vector2(10, 85), Color.White);

            spriteBatch.End();

            foreach (Body body in physicsWorld.bodies)
            {
                DrawBody(body, Color.White);
            }

            if (isIntersect)
            {
                Primitives2D.DrawLine(((ray.origin).ToVector2()), ((result.point).ToVector2()), Color.Green);
                Primitives2D.DrawLine(((result.point).ToVector2()),
                                      ((result.point + result.normal).ToVector2()), Color.Yellow);
            }
            else
            {
                Primitives2D.DrawLine(((ray.origin).ToVector2()),
                                      ((ray.origin + ray.direction * distance).ToVector2()), Color.Blue);
            }
        }
Ejemplo n.º 2
0
        protected static void DrawBody(Body body, Color color)
        {
            DrawShape(body.shape, body.position, color);

            if (body.shape is Circle)
            {
                Vec2 r = body.transform.LocalToWorldDirection(-Vec2.UnitY * (body.shape as Circle).radius);
                Primitives2D.DrawLine(body.position.ToVector2(), (body.position + r).ToVector2(), color);
            }
        }
Ejemplo n.º 3
0
        // / <summary>
        // / Allows the game to perform any initialization it needs to before starting to run.
        // / This is where it can query for any required services and load any non-graphic
        // / related content.  Calling base.Initialize will enumerate through any components
        // / and initialize them as well.
        // / </summary>
        protected override void Initialize()
        {
            height = width / GraphicsDevice.Viewport.AspectRatio;
            Primitives2D.Initialize(GraphicsDevice, height);

            SelectedDemo.Initialize(width, height);

            lastMouseState = Mouse.GetState();
            lastKeyState   = Keyboard.GetState();

            base.Initialize();

            init = true;
        }
Ejemplo n.º 4
0
        protected static void DrawShape(Shape shape, Vec2 position, Color color)
        {
            if (shape is Polygon)
            {
                Polygon polygon = shape as Polygon;
                Vec2[]  verts   = new Vec2[polygon.VertexCount];

                for (int i = 0; i < polygon.VertexCount; i++)
                {
                    verts[i] = polygon.transform.localToWorldRotation * polygon.vertices[i];
                }

                Primitives2D.DrawPolygon(position.ToVector2(), Array.ConvertAll(verts, v => v.ToVector2()), color);
            }
            else if (shape is Circle)
            {
                Circle circle = shape as Circle;
                Primitives2D.DrawCircle(position.ToVector2(), circle.radius, color);
            }
        }
Ejemplo n.º 5
0
 void IDebugDrawer.Draw(Vec2 center, float radius, params object[] data)
 {
     Primitives2D.DrawCircle(Vec2.Zero.ToVector2(), radius, colors[(int)data[0] % colors.Length]);
 }
Ejemplo n.º 6
0
 void IDebugDrawer.Draw(Vec2[] vertices, params object[] data)
 {
     Primitives2D.DrawPolygon(Vec2.Zero.ToVector2(), Array.ConvertAll(vertices, v => v.ToVector2()), colors[(int)data[0] % colors.Length]);
 }