Nov 15, 2010 at 8:34 PM
Edited Nov 16, 2010 at 2:41 AM
I was able to get the new engine working on WPF 4. I'll try to clean up a sample app and post. This isn't a complete explanation, but maybe it will help someone until I get a chance to post some samples.
The trick is Scale and Translate transforms. I created a decent working sample by doing to following:
Create a drawing canvas on the main .XAML page of your WPF app, create a TransformGroup for the canvas and add two transforms: a Scale and Translate transform. Set the scale transform's ScaleY to -1; this will "invert" the Y axis which puts the
WPF canvas's coordinate system in the same "direction" as the Farseer/Box2D world. There are a few other things you probably want to do with the scale transform like set the CenterX and CenterY properties to one-half the width/height of the canvas's
width/height. The scale of that transform will also control the relative movement between the world and your app. The world is moving in units like meters/second. I scaled my app up (set ScaleX/ScaleY to 10 and -10, respectively) which translates to 10 pixels
of movement on the canvas for every 1 meter of movement in the physics world.
Next, set the translate transform's OffsetX and OffsetY properties to width/2 and height/2, respectively. This will realign your canvas's coordinate system from 0,0 in the upper-left to 0,0 in the center of the canvas.
There's one more trick around drawing visual objects on the screen. Because you're "upping" the scale transform of the canvas, you need to scale down anything you draw on the screen. You can either create a scale transform for every visual object
you add to the screen or create the object at 1/n its normal size where n is the scale factor you used in the canvas's scale transform.