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

Bounding World for Sleeping

Topics: Developer Forum, User Forum
Jul 3, 2010 at 5:06 PM

 genbox wrote at

In 3.0 we have a concept of bounds or world. It is simply a AABB that you define in size and when things get out of bounds, they will get disabled. No need to update stuff that falls out of the world. We also have a very good inactivity controller in 3.0 - In our early tests we can have several 1000 geomtries in the world that is sleeping while we have 1000 active geometries at 40 FPS. Just letting you know that good things will come in Farseer Physics 3.0 that helps you to get more of out the physics engine without actually doing anything.

So how exactly do you implement this? I have been looking through everything that I have access to and can't seem to find it. I want to create an AABB that only does active things on the screen (and a couple meters further out). How do I do this?

Jul 3, 2010 at 9:55 PM

Farseer 3.0 is based off of Box2D. When Box2D got a new Dynamic Tree broad phase so did Farseer!. This removed the world's AABB limitation. What you would need to do is create a controller that simply disables everything once it leaves an AABB of your choosing and re-enables it when it reenters.

Jul 5, 2010 at 4:51 PM

So I would just loop through the entire list of bodies and check if they're inside the bounding box I've set up? Also, I don't understand why this would have to have been removed. It seems like a pretty nice feature to have. You said it removed the world's limitations to this but I know AABB's are still a part of the engine.

Jul 6, 2010 at 4:15 AM
Well in the previous version bodies that left the World AABB where destroyed. With the new Dynamic Tree everything remains active no matter how far from the origin it gets. Bodies will automatically sleep when they stop moving. AABB's are used in the broadphase to find out which bodies are intersecting. Your best bet would be to disable all the bodies, then write a query for the broadphase that finds all bodies inside a given AABB and enable them. I would do this every 10 frames or so, but it depends on how fast your camera moves. Use World.QueryAABB() to perform broadphase queries on the bodies in the engine. If you need an example I can get you one, but for now check out the MouseDown method in Test.cs in the Framework folder of the source code. It uses a lambda based delegate to perform a boardphase test then then tests a single point to see if the mouse intersects with a body. For performance reasons try not the iterate over the entire list of bodies and try to have your algorithm run only every 10 frames or something like that.
Jul 6, 2010 at 5:33 PM

Sorry but could I get an example of this? I get what the MouseDown code is doing and everything but I don't know how to handle deactivating bodies that aren't colliding with the AABB. 

Jul 6, 2010 at 11:33 PM

Sonic - I will work on an example for you, but just so you can get an idea of how I envision it working -

  1. Disable all bodies in the whole World.
  2. Perform World.Query using an AABB of your liking.
  3. For each body it finds colliding with the AABB enable it.
Jul 10, 2010 at 5:10 AM

Ok cool thank you :)


I have something small that I wrote to use currently. I'll post it when I get home.