Feb 25, 2011 at 9:09 PM
Edited Feb 25, 2011 at 10:32 PM
The Farseer Physics Engine uses the Meters-Kilograms-Second (MKS) system of units. More information about this can be found in section 1.7 of the
Box2D Manual and in its
FAQ page. This means that you SHOULD NOT use pixels as units to build your fixtures. You need to convert the pixels to meters.
As per your example:
rectangle = FixtureFactory.CreateRectangle(world, 80, 69, 1, posRect);
In the above line, you are creating a fixture which is 80 meters wide and 69 meters high and that will probably overflow the engine, which is why everything slows down.
One way to get around this is by using the
ConvertUnits class (found under "Samples\Samples XNA\Samples XNA\ScreenSystem") to switch between display units (pixels) and simulation units (MKS).
For your example, first we need to convert the pixels to simulation units:
float width = ConvertUnits.ToSimUnits(80),
height = ConvertUnits.ToSimUnits(69);
posRect = ConvertUnits.ToSimUnits(100, 100);
rectangle = FixtureFactory.CreateRectangle(world, width, height, 1, posRect);
Then in the Draw method, you need to convert the position of the rectangle back to display units:
spriteBatch.Draw(texture, ConvertUnits.ToDisplayUnits(rectangle.Body.Position), Color.White);
Try that out and see how it works for you.