UPDATE: This sample has been updated for Silverlight 2 beta 1. See it in action here - now with heads!
Are you tired of physics demos yet? I hope not because I’ve just made another one
It’s using the Managed Bullet Physics library I ported to WPF, tweaked slightly to run with Silverlight 1.1. This might be the world’s first cross-platform physics demo! (umm, except Flade of course, and probably a million others I’m unaware of).
Points of interest:
- You’ll need the Silverlight 1.1 Alpha runtime (or the SDK) for Windows. Mac users can get it here. Alternatively, if you just click the image above it might give you a direct download link…
It’s using an HtmlTimer to provide a ‘tick’ event for the animation. Curiously HtmlTimer is already marked obsolete; hopefully when Silverlight 1.1 releases it’ll have something like WPF’s CompositionTarget.Rendering event.See below.- Similar to my original 2D physics demo, this is using a full 3D physics library but clamps it to 2D.
- There’s a strange ‘pause’ that occurs every few seconds in the animation. I can’t see anything in my code that’s causing it (it’s almost identical to the 3D XBAP demo I published earlier). On IE it’s about 250ms, but on Firefox it’s more like a couple of seconds. I’m assuming this is just related to Silverlight 1.1’s alpha status and will soon be fixed (don’t let me down guys!
).
- It listens to the BrowserHost.Resize event to adjust the scale and translation to fit the window. I’ve not added a full-screen toggle, but you can hit F11 to maximize the browser for full effect.
- This has been sitting on my PC a few weeks already; I came up against some really dumb bugs (of mine, related to my ‘XnaToWpf’ bridge) and wussed out a few times. It’s amazing how much easier it gets when the initial hurdles are gone…
Click the image above or this link to try it out. Source code will be coming soon!
UPDATE: No longer using the HtmlTimer; source code now available! (see later post).

24 responses so far ↓
2D physics in Silverlight 1.1 « Josh Smith on WPF // May 23, 2007 at 6:37 am
[...] 2D physics in Silverlight 1.1 Chris Cavanagh, the man who came in second place in The WPF Challenge for his WPF Physics demo, is at it again. This time he has built a Silverlight 1.1 app on top of a physics engine. I’m amazed that Silverlight can handle this type of scenario! As Chris points out in his blog post about the demo app, there seems to be some performance issues in Silverlight which cause the animations to “freeze” for a short time. Other than that, the demo is very cool! Check it out here: http://chriscavanagh.wordpress.com/2007/05/22/silverlight-11-2d-physics/ [...]
bubu // May 23, 2007 at 9:43 am
Here on Intel MacOSX 10.4.9. I am getting following error message:
Silverlight error message
ErrorCode: 2251
ErrorType: ParserError
Message: AG_E_RUNTIME_MANAGED_ACTIVATION
XamlFile: Page.xaml
Line: 12
Position: 9
Chris Cavanagh // May 23, 2007 at 9:52 am
bubu - Aaaw damn
Unfortunately I don’t have a Mac handy so couldn’t test that myself. I’ll forward this to the Silverlight team; maybe it’s something I overlooked or a Silverlight bug…
Can you open other Silverlight things ok?
Chris Cavanagh // May 23, 2007 at 10:03 am
bubu - A bit of Googling suggests this error’s showing up quite a lot (in Safari; apparently Firefox just crashes?). Seems likely to be a Silverlight bug (but I’d never claim my code is perfect). I’ll stamp my feet until they fix it
bubu // May 23, 2007 at 11:05 am
I got this error in both browsers - Safari (2.0.4) and Firefox (2.0.0.3).
Samples from this site: http://silverlight.net/community/gallerydetail.aspx?cat=1&sort=2#vid45 works in Firefox.
Silverlight Cream for May 24, 2007 // May 24, 2007 at 10:04 am
[...] but this is my list for today as I view my Morning Paper, and will add on as I come across others Silverlight 1.1 2D Physics Chris Cavanagh has posted a cool Silverlight Alpha Physics demo using a ‘tweaked’ port of his [...]
http://ngadutrafik2007.smandung.com // May 25, 2007 at 2:39 am
Smile_teeth? it’s a nice … I will try uset it…. Hope make an supporting to creativity…
http://ngadutrafik2007.smandung.com
KoSh // May 25, 2007 at 6:36 am
Протсо обосраться
Justin // May 27, 2007 at 11:43 am
Bubu,
I’m using OS X 10.4.9 also, but it’s working great on my machine. I guess make sure you’ve got the Silverlight 1.1 alpha and not 1.0 beta. I don’t even get the pauses mentioned either
Awesome demo Chris!
Post Bank Holiday Web Reading « Tales from a Trading Desk // May 29, 2007 at 1:44 am
[...] 2D Physics [...]
Schuyler // May 29, 2007 at 6:27 pm
Is there any way to do pixel-level collision detection with Images or Polygons using 1.1? I was surprised to find that the Polygon.Points collection is write-only, and that apparently there isn’t a way to read the pixels in an Image.
Chris Cavanagh // May 29, 2007 at 10:41 pm
Schuyler - Well, I guess you could keep your own frame buffer and do all the detection in there. Could you give an example of what you’d use it for?
I consider WPF and Silverlight the last step in a rendering pipeline; all the ‘real work’ happens behind the scenes in a device-independent manner, leaving WPF/Silverlight to do the gruntwork of displaying it.
So in the case of your example, you’d have your own representation of the polygons/images and do your own transformations, detections etc based on that… Let me know if I’ve misunderstood your question
Chris Cavanagh // May 29, 2007 at 10:43 pm
Justin - Nice to know it works! (and better than Windows ;)). I’ll keep my fingers crossed the problems are just related to not having the 1.1 plugin installed…
Alexey Gavrilov // May 30, 2007 at 4:18 am
Great demo, Chris! Keep it up.
Rajesh Lal // June 15, 2007 at 3:36 pm
Very nice !
Development in a Blink » Blog Archive » More Silverlight // June 24, 2007 at 7:33 am
[...] Harsh blogs about Chris Cavanagh’s Silverlight based physics modeler (sub, [...]
look or feel or blog » Silverlight Link Roundup // July 1, 2007 at 10:19 pm
[...] Cavanagh has a port of the Managed Bullet physics engine for Silverlight 1.1, complete with source code [...]
nate // July 5, 2007 at 4:29 am
I couldn’t install Silverlight 1.0 beta on Mac OS 10.4.10. It keeps giving me a notification saying that I need Mac OS 10.4.8 or higher. Alpha doesn’t install either
Chris Cavanagh // July 5, 2007 at 9:40 am
Nate - Apparently this is a known issue with the beta Silverlight installers and it’ll be fixed in the final version which is “coming soon.”
Dan on eScience & Technical Computing @ Microsoft : Silverlight 1.1 2D Physics // July 7, 2007 at 1:14 am
[...] May 22nd, 2007 · 19 Comments [...]
Silverlight 1.1 2D Physics - Noticias externas // July 7, 2007 at 1:36 am
[...] May 22nd, 2007 · 19 Comments [...]
remy // July 30, 2007 at 9:22 am
Chris, your link to the Alpha Refresh is pointing to the SDK download. Here’s the Alpha one: http://msdn.microsoft.com/vstudio/eula.aspx?id=e2c1a44f-0b5c-face-28c8-08a26f2e0b3c
Erik // August 1, 2007 at 1:14 pm
Not working in the apha refresh for me. But Chris, if you can get all of the kinks ironed out and wrap it all up into a usable library, I would definitely start making some cool silverlight games with it.
Chris Cavanagh // August 1, 2007 at 1:56 pm
Erik - I’m hoping to have the samples updated in the next couple of days
I hit some snags getting Beta 2 installed (mainly related to Beta 1) but think I’m through the worst of them now. Fingers crossed… 
Leave a Comment