Not logged in, Join Here! or Log In Below:  
News Articles Search    

Submitted by Jason Zelsnack, posted on April 19, 2005

Image Description, by Jason Zelsnack

This is a simple physics demo showing off the C# wrapper I wrote for Novodex. Once complete I'll release the wrapper. This demo is built upon an editor which I've been making. For simplicity I've stripped the editor down, but there is some editor functionality left. That's what differentiates this phsyics demo from the usual 'knock the box pile over' demo. Of course you can still knock box piles over, but you can also create and manipulate objects well enough to build your own stuff to play with. The renderer is pretty slow. Using a simple renderer with D3D is rather slow, it's not as tolerant to ugly unoptimized data like openGL is.

Wrapping Novodex was much more difficult than I thought. At first I was hoping to just call functions and methods directly from the Novodex DLLs but that wasn't really feasible. I ended up writing a C interface wrapper to talk with Novodex. Even with the extra layer it was difficult passing some of the more complex structures back and forth because it was impossible to get the C# structures to be bitwise identical to the C++ structures, even using LayoutKind.Explicit. In some cases I resorted to manually passing lots of parameters. In the end that is probably better because it will be more compatible with future Novodex DLLs where the structures probably won't be laid out identically.

Go to to download the demo and to get links to DirectX and .NET runtimes. I would like to know if this still runs on .NET 1.1 or it only runs on .NET 2.0. I know it only runs on the April 2005 version of DirectX because every version of managed DirectX seems to be incompatible. It sure is great to require people to download 60MB of stuff to run an 820KB program.

Image of the Day Gallery


Message Center / Reader Comments: ( To Participate in the Discussion, Join the Community )
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

April 19, 2005, 11:48 PM

Yeah the runtime download requirements are a big problem with .net acceptance. A lot of .net developers feel that Microsoft should distribute it automatically with Windows Update.

The main (I think only) developer of managed directx has a blog and two books about the subject. His blog is here: . As you might expect there is plenty of good info there.

Danny Chapman

April 20, 2005, 02:47 AM

Tried to run this but get "An exception 'System.IO.FileNotFoundException' has occurred..."

This is with .net 1.1. It's a shame the error is so obscure.

So I'm downloading the .net runtime now (very slow)


April 20, 2005, 03:54 AM

Same execption here...

Danny Chapman

April 20, 2005, 04:08 AM

Seemed I needed both runtimes, even though I'm sure I had dx9.0c. .net demos often seem to generate these issues.

Anyway - quite fun to play with. A couple of things:

1 Physics time slowed down when I created a fair number of ragdolls (for example) - even though the frame rate was still around 30. Makes it difficult to judge things.

2 It surprised me that if I resized a box to be bigger than the others it wouldn't sit on top of them - it would sink down and then get supported by the penetration/penalty force. Is this normal with Novodex, or is there some flag/feature that you're not setting?

3. Quite interesting how if you move a sphere under the ground plane it simply gets moved up to the ground plane - move any other objects underground and they get accelerated.

Jason Zelsnack

April 20, 2005, 06:17 AM

Yeah, it sucks how poorly .NET is rolled out. Sorry if you have to spend a bunch of time installing .NET and/or DirectX.

I wish that the latest versions of DirectX and .NET were true runtimes with decent installers instead of the icky redistributable installation.

The only reason this uses .NET is because I love C#.
I might drop the managed DirectX and use a wrapper for openGL because I just prefer GL.

The framerate is so slow with lots of ragdolls mostly because of the renderer. I didn't put any effort into a renderer. I just call DrawPrimitive a million times which is really slow.
The problem with a large box crushing a small box is inherently a part of impulse physics. Novodex recommends that the mass difference be no more than 10 times. Oh, actually the size doesn't matter, the mass does. A large light box won't crush a small heavy box.

Danny Chapman

April 20, 2005, 07:13 AM

About the slowing down - what I meant is that the physics should run at "real" speed - whatever the renderer is doing. So if the framerate is 30FPS and you call physics with a fixed timestep of 1/60th of a second, then you'd do (on average) two physics updates per render call. I was seeing physics slowdown with frame rates of 30FPS, which isn't particularly low (I would only start skipping physics updates when it dropped to around 10FPS...)

With the crushing - it surprised me to see that because Novodex supports stacking so well - there in effect you have a massive (collection of) object(s) all being supported by one little object at the bottom. This can be worked around using "shock propogation" in an impulse physics simulator - a compromise between physics and practicality :) So maybe this means Novodex handles stacking without this...

Anyway, as I said - quite entertaining to play with.


April 20, 2005, 08:31 AM

Danny have you done anymore work on JigLib recently?

Danny Chapman

April 20, 2005, 09:31 AM

Yep - it now runs in 5 dimensions on the GPU and makes a cup of tea for you whilst the renderer catches up :)

Jason Zelsnack

April 20, 2005, 09:53 PM

Yeah I'm always passing in 1/60th of a second to the simulate function. Passing in 1/framerate acted a bit erradict. Also, when the framerate drops and you increase the timestep it slows down even more, and then you have to pass in a longer timestep.

I think the solution to physics slow down is not to let it drop below a certain threshold in the first place. Just like you have a polygon budget for a scene you need to have a physics budget and try to never exceed it. (whoa, how obvious)

Turning off the renderer completely and just running the phyiscs Novodex can run a large pile of ragdolls pretty quickly.

Danny, I liked the jiggle physics stuff and some time ago I made a 2d applet using that technique. Too bad your site is down.


April 21, 2005, 04:58 AM

Yes there are certainly some issues at the moment when it comes to distribution and MDX. But hopfully MS will sort these out as MDX matures. I have high hopes, the api is already basically the fastest rendering api you can use, being directx without the *significant* overhead of COM. (some mdx examples in the sdk run 4x faster than their equivalent C++ version). And .net if written well can be very, very fast indeed. Imo the future of game development lies in a managed language, and I'm more than happy to use .net.


I've been looking around for a good .net physics lib. TrueAxis are apparently doing a .net port (or at least interface, but a full port would be much better, and probably a good deal faster). But I heard that a while ago and nothing since.
NovodeX would seem to be a good choice. Seems fairly efficient, but the interface isn't the prettiest and it as stable/reliable as it could be.
There is also the Newton game dynamics engine, which has a .net wrapper. Can't remember the license it used though (it was quite impressive though, fast and efficient)

Anywho, good work. When I get round to the physics side of my current .net projects, I'll have a deeper look.

This thread contains 10 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.