Esempio n. 1
0
        public void DrawDebug(SpriteBatch sb)
        {
            var view       = Camera.GetFarseerViewMatrix();
            var projection = Matrix.CreateOrthographicOffCenter(0,
                                                                ConvertUnits.ToSimUnits(GraphicsDevice.Viewport.Width),
                                                                ConvertUnits.ToSimUnits(GraphicsDevice.Viewport.Height),
                                                                0, 0, 1);

            DebugView.BeginCustomDraw(ref projection, ref view);
            foreach (var b in World.BodyList)
            {
                Transform f;
                b.GetTransform(out f);
                for (var i = 0; i <= b.FixtureList.Count() - 1; i++)
                {
                    var color = Color.Blue;
                    if (b.Awake)
                    {
                        color = Color.Red;
                    }
                    if (b.FixtureList[i].Shape == null)
                    {
                        continue;
                    }
                    if (b.UserData != null)
                    {
                        if (((GameObject)b.UserData).IgnoreDebug)
                        {
                            continue;
                        }
                    }
                    DebugView.DrawShape(b.FixtureList[i], f, color);
                }
            }
            DebugView.EndCustomDraw();
            sb.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null,
                     Camera.GetViewMatrix());
            foreach (var obj in GameObjects.Objects)
            {
                sb.Draw(Vector, new Rectangle((int)obj.Value.Position.X - 32, (int)obj.Value.Position.Y - 32, 64, 64),
                        Color.White);
                var obj1 = obj;
                foreach (var pos in from i in obj.Value.Body.FixtureList
                         where i.UserData != null
                         where !((GameObject)i.UserData).IgnoreDebug
                         select Utils.PositionOfFixture(obj1.Value.Body, i))
                {
                    sb.Draw(Vector, new Rectangle((int)pos.X - 16, (int)pos.Y - 16, 32, 32), Color.White);
                }
            }
            if (Raycast.Casts != null)
            {
                foreach (var cast in Raycast.Casts)
                {
                    if (cast.HitPoint != Vector2.Zero)
                    {
                        DrawLine(SpriteBatch, cast.StartPoint, cast.HitPoint, Color.Red);
                        DrawLine(SpriteBatch, cast.HitPoint, cast.EndPoint, Color.Blue);
                    }
                    else
                    {
                        DrawLine(SpriteBatch, cast.StartPoint, cast.EndPoint, Color.Blue);
                    }
                }
                Raycast.Casts.Clear();
            }
            sb.End();
        }