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

Mouse Picking

Aug 5, 2011 at 8:02 PM

How would I implement mouse picking into farseer? I am using farseer to handle 100% of collisions and images in my application, and I need to use mouse picking for interaction.

Aug 5, 2011 at 10:15 PM


this is my implementation for Mouse Joint


       private FixedMouseJoint fixedMouseJoint;

       public void MouseJointHandler()
            Vector2 position = new Vector2(Mouse.GetState().X / MeterInPixel, Mouse.GetState().Y / MeterInPixel);
            if (Mouse.GetState().LeftButton == ButtonState.Pressed && fixedMouseJoint == null)
                fixture = world.TestPoint(position);
                if (fixture != null)
                    Body body = fixture.Body;
                    fixedMouseJoint = new FixedMouseJoint(body, position);
                    fixedMouseJoint.MaxForce = 1000.0f * body.Mass;
                    body.Awake = true;


            if (Mouse.GetState().LeftButton == ButtonState.Released && fixedMouseJoint != null)
                fixedMouseJoint = null;

            if (fixedMouseJoint != null)
                fixedMouseJoint.WorldAnchorB = position;
Aug 5, 2011 at 10:39 PM


Curious, if I try to draw something out of the viewport, does XNA automatically cull it away or do I have to do a manual viewport test??

Aug 6, 2011 at 4:07 PM

I recommend reading "Learning XNA 4.0" its good for understanding all the XNA things :)

Aug 7, 2011 at 8:04 PM
Edited Aug 7, 2011 at 8:05 PM

This does not work for me somehow. It might be because of my positioning.

I use ConvertUnits and world.TestPointAll:


List<Fixture> fixtures = world.TestPointAll(ConvertUnits.ToSimUnits(mouseXY));
            foreach (Fixture element in fixtures)

I do a to test my object's position, and it looks fine.
Aug 8, 2011 at 2:11 AM

ok good,

but I didn't tell you that the variable MeterInPixel for me 64 int but int the XNA samples they use 100 int

and just put this function in Update method