![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/irrPhysxIcon.png)
Website
Forum
Having used Physx on PS3 and got rather cosy with it I decided that it would be my physics engine of choice on PC too. I noticed that there weren't really any 'easy' to use wrappers/integrations with Irrlicht (there were tutorials and other ones which seemed to require rather large changes and code duplication) so I thought I'd have a go at writing a simple to use wrapper.
So the idea of this wrapper is to completely abstract away the Physx SDK from the user so they needn't get down and dirty with it. Instead they just have to use my simple interface. This should prove pretty useful for people not used to physics engines and external libraries but may not be so useful for people wanting to get really ambitious with their physics, at least not in its current state.
So what do you need to develop with IrrPhysx? First off you need IrrPhysx itself (dur!), which is compiled with Irrlicht 1.4.2 and Nvidia Physx 2.8.1, so you'll need those two as well. When developing Physx applications you also need to install the Physx system software. It turns out that the latest system software doesn't actually work with 2.8.1, it just complains about CUDA DLL errors when you try and run a Physx application. FMX informed me that system software 8.06.12 is the best one to go for, seems to do the trick!
It might also be a good idea to read the Physx EULA to be sure of any restrictions/requirements of using Physx.
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/nvidia_physx_official_logo.png)
Anyway, here's the download!
IrrPhysx 0.2 SDK for Irrlicht 1.4.2 ( 12mb )
IrrPhysx 0.2 SDK for Irrlicht 1.5 ( 12mb )
IrrPhysx 0.2 Game Example for Irrlicht 1.4.2 ( 3mb )
IrrPhysx 0.2 Game Example for Irrlicht 1.5 ( 3mb )
I've used MSVC 2008 to compile the code but I reckon i've set it up properly to not require the MSVC redistibutables so it should work fine on 'any' PC. If you're just running Physx applications you don't actually need the Physx system software, that's just for developing, but you will require a small installation. For this I reckon the supplied Physx game installer should do the trick, be a guinea pig for me and let me know if there's any problems!
The following example is provided above, seperate from the SDK
[New]Game Example:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/game.jpg)
This example shows you how to use IrrPhysx in a hopefully sensible way, read through the source and comments to understand the advice and feel free to post questions if you don't understand something.
This example will be updated along with each new version of IrrPhysx. At the moment the 'character controller' is just a sphere which isn't the best way of controlling characters in Physx but i've not got round to wrapping up the character controller stuff yet, that will come soon, when it does i'll update this example to show how to use it.
In the example you can move around, knock objects over, shoot objects, jump, throw spheres and then shoot them to cause explosions.
The SDK contains the source for both the library and the examples, documentation in .CHM form and the following examples....
[New]Mesh Example:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/mesh.jpg)
This example shows you how to create convex mesh objects (an object which encloses a shape in a convex manner) and triangle mesh objects (a static object made from the triangles of a mesh).
[New]Explosion Example:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/explosion.jpg)
This example shows you how to create explosions with IrrPhysx. The explosion is like an expanding sphere and anything within the sphere has the force of the explosion applied to it.
[New]Raycast Example:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/raycast.jpg)
This example shows you how to do raycasting, similarly to the Irrlicht collision tutorial.
The intersection point of the raycast is shown with the billboard and a blue line also shows the normal of the surface which was hit.
[Updated]Boxes Example:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/boxes.jpg)
This example shows you how to simple create some boxes and then knock them around... kinda like the 'Hello World' of physics engines I guess!
The large box which is present on start-up is a static box which has been created by passing a density of 0 (a density that is bigger than 0 will result in a box being moveable).
[Update] The box created by pressing W is now created with random dimensions between 1 and 10.... ground breaking....
![Laughing :lol:](./images/smilies/icon_lol.gif)
[Updated]Heightfield Example:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/heightfield2.jpg)
This example shows how to make some terrain, it reproduces the terrain produced by ITerrainSceneNode. I apologise for the horrific lighting on the terrain... it doesn't seem to be behaving properly but I can't really be bothered to keep picking away at it!
![Laughing :lol:](./images/smilies/icon_lol.gif)
[Update] There's now a second way of creating heightfields. This new version just takes an s16 array of height values which means you can now create heightfields from sources which aren't ITerrainSceneNodes. The example now shows how to use this function to create a heightfield from a Milkshape3D-created heightfield mesh.
[Updated]Multi-Shape Example:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/multishape.jpg)
This example shows how you can make more complex shapes than a simple box, by using the boxes as building blocks. It takes the individual mesh buffers of a model and makes a bounding box and keeps them all joined together. As you may be able to see from the picture, each of the table's individual sections has a different texture, this is to force each section to be put into a different mesh buffer so that it's easy to form bounding boxes around the pieces.
At this point I shall point out that when creating physics objects for your game you should rarely use the mesh data of the models that you use for rendering. When rendering you want uber-next-gen kewl looking models so they're much higher poly than is needed for physics calculations. So for this reason you should create a hugely lower poly version of your model to use for physics calculations and this is what the multi-coloured table can be thought of as. You wouldn't want to render it as 5 different mesh buffers or have 5 textures for it when 1 would suffice so once you'd created the table physics object with this model it could be removed and you could load a much nicer looking table for the actual rendering.
A slight problem in this example is if you create two multi-shape objects on top of each other they can become joined together and start jiggling around frantically. This shouldn't really happen in a game as you'd ensure you weren't creating objects on top of each other but it can happen in the example as you have free reign over quickly creating objects in the same place.
[Update] The example now shows you how to create capsule objects,. Pressing K creates a randomly sized capsule for you. The previous example had a 'double box' object you could create by pressing W, this has now been changed to an object constructed from a box, a sphere and a capsule.
[Updated]Cloth Example:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/cloth.jpg)
This example shows how to create cloth objects. Unfortunately a bug appeared at some point during development which means that if you create a flag in the example and then exit it will crash on device->drop(). I haven't been able to track down the reason for the crash but will obviously continue to do so! You can also create a cloth version of good ol' Sydney and knock her about a bit. She will have internal pressure so be kinda like a bag of air, it's not actually that easy to see in the example.. she's not the best mesh to use to show off this, but there you go!
I'll point out that the flag cloth is actually created from a hill plane mesh and as such it is one-sided. So this means it's only lit from one side and with backface culling off it looks the same from both sides so if it gets knocked around so that it's facing away from the light then both sides are black. This is just a limitation of single-sided meshes!
I shall also point out that currently in Physx, cloth collision is done on a per-vertex basis rather than per-triangle. So this means that the cloth can sometimes penetrate surfaces and cloths will often be able to occupy the same space as each other (try creating two sydneys in quick succession and you'll see they don't actually collide with each other in any way as their vertices sort of end up missing each other). It does seem, though, that triangle collision detection will be available in a future release of Physx.
Another thing to note about cloth is that if you want to use internal pressure on them then the mesh must be completely enclosed so have to holes in it that the air could leak out of. Also when creating cloth from a mesh the entire mesh should be joined otherwise it will fall apart when the simulation is run. You may notice that i've removed Sydney's fringe as this was modelled seperately to her body and so would fall off her head. And another thing is that currently only the first mesh buffer is used when creating the cloth object, I suppose this won't actually change because otherwise the seperate mesh buffers would fall apart from each other anyway.
[Update] You can now create tearable cloth in this example. Pressing T will create a tearable cloth attached to the green static box and the cloth will have a small box attached to it which will then fall down and cause the cloth to tear.
The tearing does look a bit ugly, this is because of the low poly count in the cloth mesh. Tearing just rips the vertices apart so if you have a higher poly count you're more likely to get nicer looking tearing!
Contact Report Example:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/contact.jpg)
This example shows you how you can use a callback function to be informed about object collisions. Within the little 'arena' you can create a load of random spheres and when they hit each other they will magically fizzle out of existence. Magic!
Thanks go to Dark_Kilauea for his useful little grid scene node.