Particle System Demo – Collision Detection Demo (2D)

Hi All

This is my first project looking at collision detection. I used a basic system of particles to represent my physics world objects just to simplify the project to focus on the CD (Collision Detection).

Here is what I used to build the project :

–          Visual Studio 2010 Express ( C# )

–          XNA Game Studio 4.0

–          The Internet

The core physics theory for the collision detection in this example revolves around the co-efficient of restitution. I’m not going to go into depth on this topic as there are enough tutorials online for the physics details but I will give mention to the Wikipedia article :

http://en.wikipedia.org/wiki/Coefficient_of_restitution

This article covers the basics and includes a 2-Body collision model which I use for the basis of the CD Engine. ( See Speeds after impact )

I’ve used this 2-Body model for simplicity’s sake but you will notice when running the demo the problems the engine encounters. Such as a 3-body collision, which causes the particles to stick together or in the case of a boundary collision it will stick to the boundary. Two major performance problems in the implementation :

–          The application is purely single threaded and therefore only runs on a single core.

–          The algorithm used to check for collisions is essentially a O(n^2) algorithm is which incredibly expensive.

Depending on the hardware being used, enhancing the app in these two areas could radically improve the performance of the particle system.

Something worth mentioning specific to the implementation is the embedding of the XNA graphics device in a WinForms application. This is hardly revolutionary though. There are a number of examples on how to do this and I would recommend looking at :

http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1

The above sample will give you the framework to embed the entire graphics device. It operates slightly differently as there is no Game object but the update events now get added by the WinForm application which pushes the XNA Component along.

Here is a quick screen shot with a few particles running in the system :

 

 

 

 

 

 

 

 

 

 

 

Anyway, enough rambling on my part, here is the demo project :

ParticleSystemDemo2D

Just as a disclaimer..

Coming from a business systems background I’ve been having an internal debate as to how to lay out the classes with regards to their interactivity. Such as the Physics kernel and how the WinForm must set attributes that exist all the way back in the engine. I’ve decided to draw the line though, feel free to experiment with the “framework” layout.

I would appreciate any feedback on this project in terms of things I might have left our or have not considered. If I have mentioned them then they are on my research to-do list, but I would welcome the feedback or resources anyway.

Ciao  🙂