Chris Cavanagh’s Blog

3D Physics XBAP

April 8, 2007 · 35 Comments

I’ve created a small XBAP 3D physics demo for pure geeky delight.  It’s got a long way to go, but it’s got a nice button that lets you drop beachballs on to each other, so I think that makes it morally OK smile_wink

It’s built on a managed version of the Bullet Physics Library, tweaked slightly for WPF (so it’ll run locally as an XBAP).  Give it a try and see what you think.  Some general notes:

  • Performance is fair; it could struggle on slow machines.  There are loads of optimizations we can do with WPF 3D (merging models into one GeometryModel3D can give huge improvements) but I’ll save that for another post smile_shades
  • Dropping too many objects will bring any system to its knees pretty quickly.  It’s not culling anything to a view frustum yet and the sphere models probably have too many vertices, so even if objects roll off screen they’ll still suck your CPU dry.  Just don’t do it smile_regular
  • You’ll get better performance with spheres than boxes.  They generally come to a rest more decisively (the physics engine marks objects as inactive when they’re at rest, at least until something hits them).  Boxes can currently ‘jitter’ a while before they settle down.

I’ve published the source on CodePlex.  Let me know if you’d be interested in contributing!

UPDATE: Did a couple of rendering tweaks and enabled camera movements (drag mouse to move, right-drag to zoom).  Also, thanks for the great feedback!

UPDATE 2: Fixed earlier ‘rolling’ issue (my bad) and added a ‘drop box’ button.  Boxes don’t behave quite as nicely as the beachballs yet (they act like jello cubes) but they’re still a lot of fun smile_party

Categories: .NET

35 responses so far ↓

  • NakedCleaner.com » Blog Archive » XBAP and 3D // April 8, 2007 at 4:03 am | Reply

    [...] of my mates has been playing about with XBAP, Pop Along and have a play. Technorati Tags: 3D, Computing, Gaming, PC, XBAP Possibly Related : No related [...]

  • Josh Smith // April 9, 2007 at 10:38 am | Reply

    Nice! This is very cool. In case you’re interested in some feedback from the community, here’s my 2 cents. I think it would be awesome if:
    1) Larger planets had stronger gravitational attraction.

    2) Planets could have one or more moon which orbits it.

    3) The moons could collide with other objects in the scene and shatter. (That would be sooo cool!)

    Anyways, thanks for the cool app. :)

    Josh

  • Ruurd Boeke // April 14, 2007 at 5:03 am | Reply

    I don’t know what Josh is talking about (moons?), but this is absurdly cool.

  • Chris Cavanagh // April 14, 2007 at 11:13 am | Reply

    Ruurd – Thanks! But sorry for the confusion. My original demo had planets rolling around (Jupiter actually; was the only bitmap I had to hand!). The problem was gas giants don’t usually bounce and roll so well, so when I updated it (for some performance improvements and fix to how the physics engine was used) I threw in some beachballs instead :) I was going to leave the post unedited (with just updates at the bottom) but didn’t want it to be too confusing for newer readers. I really like Josh’s suggestion of a planetary demo though, so I might just make one :D

  • Ruurd Boeke // April 21, 2007 at 9:22 am | Reply

    ;-)
    You’re really on to something here. There is probably going to be great demand for 2d and 3d engines for wpf.
    I was looking in to some of the examples of Kevin Moore where he is doing funky 2d physics, and I definitely see opportunities for animations even in business applications.

  • Tonko // April 21, 2007 at 11:57 am | Reply

    It would be great if Codeplex site actually contained something downloadable . Not your fault though, I know.

  • Chris Cavanagh // April 21, 2007 at 5:02 pm | Reply

    Tonko – Yeah CodePlex has been down a while (sabout 10 days I think). I’ll probably upload the source to my server too, in case it’s lost for good ;o)

  • Suite et fin du WPF Challenge , alex# // April 24, 2007 at 3:23 am | Reply

    [...] :Quixotry par Johnny TurpinMoteur physique WPF (2 D) vraiment impressionnant, à noter la version 3D. WPF Physics par Chris Cavanagh Un srabble-like en WPF avec du glisser-déposéRSS Reader par [...]

  • theWPFblog » WPF 3D Physics Poopr Application // May 15, 2007 at 8:06 pm | Reply

    [...] Cavanagh has created some excellent 3D physics examples which utilizes the XNA game framework. I decided to take his code and build a truly innovative WPF [...]

  • Jose // May 15, 2007 at 11:25 pm | Reply

    how did you created the 3d scenes? the sames objects that are used in wpf? how do you manage to create the 3d objects for the browser?

  • Chris Cavanagh // May 16, 2007 at 6:54 am | Reply

    Jose – The objects are just regular WPF 3D meshes. I cheated a little on the spheres and used some code by Daniel Lehenbauer (there’s also some code for cones and cylinders I think). It calculated all the texture co-ordinates and vertex normals. The boxes (including the ground) are made from 24 vertices to prevent the [Gouraud] shading blending the corners away (none of the faces share vertices). Hope this helps!

  • Fábio Pedrosa » 3D Physics XBAP // May 16, 2007 at 7:39 am | Reply

    [...] Cavanagh some weeks ago created a very nice 3D Physics XBAP (Windows WPF) example just to show the WPF/XNA [...]

  • Joku // May 16, 2007 at 9:35 am | Reply

    Try piling up 3 boxes (possible but takes a bit of trying), the ones already on ground tend to stay wobbling really long as if the surfaces had no friction to stop the wobble sooner.

  • Chris Cavanagh // May 16, 2007 at 10:21 am | Reply

    Joku – Yeah I’ve noticed that; it’s something I’ve been meaning to fix! I don’t think it’s a problem with the physics engine though (unless I did a sloppy port to WPF). Right now the cubes bounce like jello, which is still kinda fun :)

  • John Davis // July 25, 2007 at 3:39 am | Reply

    If your’re interested, I’ve got a 3D terrain XBAP at http://www.lunchgamer.com Make sure you’re running a tier 2 graphics card, otherwise it may appear slow. Enjoy!

  • Chris Cavanagh // July 29, 2007 at 5:02 pm | Reply

    John – I’d love to take a look at the terrain XBAP but I’m getting an error :( Here are the details (edited for length):

    ERROR SUMMARY
    Below is a summary of the errors, details of these errors are listed later in the log.
    * An exception occurred while downloading the manifest. Following failure messages were detected:
    + Downloading http://www.lunchgamer.com/ did not succeed.
    + The remote server returned an error: (500) Internal Server Error.

    COMPONENT STORE TRANSACTION FAILURE SUMMARY
    No transaction error was detected.

    ERROR DETAILS
    Following errors were detected during this operation.
    * [7/29/2007 5:58:44 PM] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
    - Downloading http://www.lunchgamer.com/ did not succeed.
    - Source: System.Deployment
    - Stack trace:
    at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
    at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
    at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
    at System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri& sourceUri, String targetPath, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
    at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirect(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
    at System.Deployment.Application.DownloadManager.DownloadDeploymentManifest(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, IDownloadNotification notification, DownloadOptions options)
    at System.Deployment.Application.DeploymentManager.BindCore(Boolean blocking, TempFile& tempDeploy, TempDirectory& tempAppDir, FileStream& refTransaction, String& productName)
    at System.Deployment.Application.DeploymentManager.BindAsyncWorker()
    — Inner Exception —
    System.Net.WebException
    - The remote server returned an error: (500) Internal Server Error.
    - Source: System
    - Stack trace:
    at System.Net.HttpWebRequest.GetResponse()
    at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)

  • John Davis // August 3, 2007 at 1:42 am | Reply

    Try this one and let me know if it works. It’s deployed on IIS7
    http://208.106.245.119/xbap/publish.htm

  • Chris Cavanagh // August 3, 2007 at 1:50 am | Reply

    Hey John – That works great now! Very cool and runs nice & smooth :)

    Would it be tricky to make it hit Virtual Earth or Google maps? (Virtual Earth has height data too I think; just a thought!).

  • John Davis // August 3, 2007 at 4:58 am | Reply

    I have http://www.lunchgamer.com redirecting to the IIS7 server now as well. Strange, lots of people were accessing to old one fine. But Lutz Roeder was having the same problem as you. Hopefully this will work for everyone. If anyone has an issue please let me know.

  • John Davis // August 3, 2007 at 5:01 am | Reply

    Tell me where to get the height map data and I’ll see what I can do. Do they have something that can be used as surface texture?

  • Chris Cavanagh // August 3, 2007 at 7:05 am | Reply

    I’d have to dig into their API a bit. Certainly the map images themselves would be the surface texture. I’m assuming the height map data is accessible as Virtual Earth 3D uses it (but I don’t know if it’s public). They also now do “hill shading” (there’s probably a better name, but I think that’s what they called it) where it applies some shading as an overlay on 2D maps (that’s probably done on the server through).

    Maybe this could help: http://blogs.msdn.com/publicsector/archive/2007/05/08/update-virtual-earth-with-silverlight-sample.aspx.

  • John Davis // August 4, 2007 at 3:42 am | Reply

    That link doesn’t seem to work anymore.

  • Chris Cavanagh // August 4, 2007 at 5:15 pm | Reply

    John – What error/message do you get? For some errors (related to old cached versions) clearing any cached XBAPs may help… Copy the following into a batch file and just run it if things get weird (replace with your Windows account name).:

    @echo off
    rundll32 %windir%\system32\dfshim.dll CleanOnlineAppCache
    del /S /Q /F “C:\Documents and Settings\\Local Settings\Apps\2.0\*.*”

    (I can’t remember where I dug this up from, but maybe it’ll help) :)

  • John Davis // August 5, 2007 at 2:54 am | Reply

    “The page cannot be found” error is what I’m getting. I don’t think this is related to the OnlineAppCache?

  • Chris Cavanagh // August 5, 2007 at 8:28 am | Reply

    John – Can you send me the full URL you’re trying? (just paste it in a comment). Could you let me know if you can reach the other links on my blog? (source code etc, particularly things on the chriscavanagh.com domain; also, give http://65.166.200.182/Chris/CJC.Bullet/BulletDemo1.xbap a try).

  • Martin Cook // August 7, 2007 at 5:06 am | Reply

    sorry, i broke this one to….

    PLATFORM VERSION INFO
    Windows : 6.0.6000.0 (Win32NT)
    Common Language Runtime : 2.0.50727.1318
    System.Deployment.dll : 2.0.50727.1318 (redbitsb1.050727-1300)
    mscorwks.dll : 2.0.50727.1318 (redbitsb1.050727-1300)
    dfshim.dll : 2.0.50727.1318 (redbitsb1.050727-1300)

    SOURCES
    Deployment url : http://www.chriscavanagh.com/Chris/CJC.Bullet/BulletDemo1.xbap

    ERROR SUMMARY
    Below is a summary of the errors, details of these errors are listed later in the log.
    * An exception occurred while downloading the manifest. Following failure messages were detected:
    + Downloading http://www.chriscavanagh.com/Chris/CJC.Bullet/BulletDemo1.xbap did not succeed.
    + The remote server returned an error: (407) Proxy Authentication Required.

    COMPONENT STORE TRANSACTION FAILURE SUMMARY
    No transaction error was detected.

    WARNINGS
    There were no warnings during this operation.

    OPERATION PROGRESS STATUS
    No phase information is available.

    ERROR DETAILS
    Following errors were detected during this operation.
    * [07/08/2007 12:05:08] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
    - Downloading http://www.chriscavanagh.com/Chris/CJC.Bullet/BulletDemo1.xbap did not succeed.
    - Source: System.Deployment
    - Stack trace:
    at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
    at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
    at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
    at System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri& sourceUri, String targetPath, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
    at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirect(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
    at System.Deployment.Application.DownloadManager.DownloadDeploymentManifest(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, IDownloadNotification notification, DownloadOptions options)
    at System.Deployment.Application.DeploymentManager.BindCore(Boolean blocking, TempFile& tempDeploy, TempDirectory& tempAppDir, FileStream& refTransaction, String& productName)
    at System.Deployment.Application.DeploymentManager.BindAsyncWorker()
    — Inner Exception —
    System.Net.WebException
    - The remote server returned an error: (407) Proxy Authentication Required.
    - Source: System
    - Stack trace:
    at System.Net.HttpWebRequest.GetResponse()
    at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)

    COMPONENT STORE TRANSACTION DETAILS
    No transaction information is available.

    Martin

  • Chris Cavanagh // August 7, 2007 at 7:10 am | Reply

    Martin – Can you browse other XBAPs (on other servers) ok?

  • John Davis // August 10, 2007 at 8:58 pm | Reply

    That last one worked.

  • Chris Cavanagh // August 11, 2007 at 10:53 am | Reply

    John – Interesting; maybe some kind of DNS issue. Glad it’s working :)

  • Scott Hanselman's Computer Zen - Firefox, WPF and XBAP // February 1, 2008 at 11:52 pm | Reply

    [...] 3D Physics XBAP by Chris Cavanagh and Source [...]

  • ahndunk // February 19, 2008 at 4:47 am | Reply

    Cool application, but I think you can give a lot of ball to make it more interesting.

  • Ryan // July 7, 2008 at 7:55 pm | Reply

    Wow. Too cool. I never cease to be amazed at what’s possible with the framework. I’ve really got to stop making boring business apps and play with some of this stuff.

  • Flashbot » Blog Archive » Xbap, Silverlight’s Forgotten Big Brother - Developing interactive advertising, entertainment and applications // March 19, 2009 at 8:52 am | Reply

    [...] haven’t heard a thing about XBAP since then. There are a few nice examples around the blogosphere (if you look hard enough), but Silverlight has since stolen the show and the [...]

  • Takuan Daikon // August 17, 2009 at 8:17 am | Reply

    This looks very cool from the description, and is something I’ve been interested in some time. Unfortunately, like most year-old Web content, it doesn’t actually work. I get exceptions when trying to run the online demo.

    I’ll have to check out the code, I guess :)

  • Chris Cavanagh // August 17, 2009 at 9:47 am | Reply

    Takuan – Are you using .NET 3.5 SP1? Which browser are you using? The XBAP runs ok for me… (should be fine in FF or Safari on Windows).

Leave a Comment