Jun 13, 2012 at 7:53 PM
Edited Jun 13, 2012 at 8:08 PM
I think what you want is something like the MotionState in Bullet Physics which is the main way to deal with physics updates in that engine. It looks like a good idea given its wide usage. http://www.bulletphysics.org/mediawiki-1.5.8/index.php/MotionStates
This doesn't exist in Box2D and consequently in Farseer. It will however be extremenly easy to implement:
Have a class called MotionState attached to each fixture upon creation in the UserData field. The class keeps velocities (angular and linear and the body transform). After calling World.Step() in something like a PhysicsManager singleton that knows about
the simulation, iterate over all bodies (World.BodyList), grab the MotionState of each fixture and call it's Update() method with the new data. The MotionState will be responsible for firing an OnUpdate() Event to which other entities can subscribe. Other
useful events could be OnPre/PostStep() (cancelling updates?), OnFixtureChanged, OnMotionStateChanged() and whatever else. Also the MotionState can be extended through inheritance like in Bullet for more specific needs. I haven't actually looked at Bullet's
implementation but should be in that spirit.
Note that this changes the chain of responsibility. I prefer a setup where the user code *pulls* data from the physics whenever needed. The above approach will mean that the PhysicsManager will *push* the physics onto the user code. Does this really play
well with the way graphics engines work? In XNA Update() and Draw() are not synchronous for example (one can be faster than the other)...