This project has moved and is read-only. For the latest updates, please go here.

DebugView issues

Topics: Developer Forum, User Forum
Sep 14, 2011 at 6:06 PM
Edited Sep 14, 2011 at 7:01 PM

I am trying to mess with the farseer debugview and I'm seriously struggling with this. Text, sprites, and that kind of stuff shows up fine, but when I try to get it to draw bodies I have issues and it shows nothing.

I've used systems similar to the way the testbed does it, and I've copied the Camera2D code pretty much verbatim from your simple samples after the former did not work and still no luck. I went into debug to try to get some hints, and it looks like it thinks my objects are at something like (5400, 5000) in the camera coords. I feel like the view matrix is totally messed up, but I'm using the Camera2D code you guys have included, so I have no idea where it's getting messed up.

Do you guys have any documentation at all on DebugView? I've been struggling with this for close to 2 days now, and the closest I can find is one guy plugging in arbitrary, by his own admission, numbers, and someone telling the other person their view matrix is wrong and to look at the simple samples.


My code is a mess right now from trying everything, but I'll post it after I clean it up a bit. Any documentation though would be very helpful.

edit: So once I switched to the camera, I hadn't set the ConvertUnits ratio, so first my objects were very small, then I used an absurd number that made them so big I just didn't notice as my screen still looked like a flat color.


Sep 14, 2011 at 6:26 PM
Edited Sep 14, 2011 at 6:27 PM

Alright here's some code. My "Camera" class is copied and pasted from the Farseer Camera2D class in the simple samples as well as the ConvertUnits class.



class GameplayTestScreen : GameScreen
        internal DebugViewXNA DebugView;
        ContentManager content;

        private Camera _camera;

        World World;
        Body Player;
        Body Enemy;

        public GameplayTestScreen()
            World = null;
            _camera = null;

public override void Activate(bool instancePreserved)
            if (!instancePreserved)
                if (content == null)
                    content = new ContentManager(ScreenManager.Game.Services, "Content");
                GameInstance = (BoredGame)ScreenManager.Game;

                if (World == null)
                    World = new World(Vector2.Zero);

                if (_camera == null)
                    _camera = new Camera(GameInstance.GraphicsDevice);

                FarseerPhysics.Settings.EnableDiagnostics = true;
                DebugView = new DebugViewXNA(World);
                DebugView.LoadContent(GameInstance.GraphicsDevice, GameInstance.Content);

                Player = BodyFactory.CreateCircle(World, 200f, 55, new Vector2(50, 50));
            Player.BodyType = BodyType.Kinematic;
            Enemy = BodyFactory.CreateCircle(World, 200f, 55, new Vector2(500, 500));
            Enemy.BodyType = BodyType.Dynamic;
            Enemy.LinearVelocity = new Vector2(50, 0);

            //Add gravity so stuff moves around.
            GravityController gravity = new GravityController(20);

            Vector2 center = new Vector2(150, 150);

                // A real game would probably have more content than this sample, so
                // it would take longer to load. We simulate that by delaying for a
                // while, giving you a chance to admire the beautiful loading screen.

                // once the load has finished, we use ResetElapsedTime to tell the game's
                // timing mechanism that we have just finished a very long frame, and that
                // it should not try to catch up.

 public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)

            base.Update(gameTime, otherScreenHasFocus, false); 

            if (IsActive)
                World.Step((float)(gameTime.ElapsedGameTime.TotalMilliseconds * 0.001));

public override void Draw(GameTime gameTime)
            // Our player and enemy are both actually just text strings.
            Matrix projection = _camera.SimProjection;
            Matrix view = _camera.SimView;

            //This outputs something around (5400, 5000)
            Vector2 blah = _camera.ConvertWorldToScreen(Player.Position);
            DebugView.RenderDebugData(ref projection, ref view);

            // If the game is transitioning on or off, fade it out to black.
            if (TransitionPosition > 0 || pauseAlpha > 0)
                float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, pauseAlpha / 2);





That's kind of a mess, but for some reason c/p didn't format quite so nicely from VS :-/

edit: In debug I can track this all the way down into the PrimitiveBatch and the points are getting in there and flushed to the device with the correct colors, so I'm fairly sure it's just the view matrix going insane.

Sep 14, 2011 at 7:01 PM

Fixed, See op for details.