Middleware and 3rd Party Libraries in Auxnet - Part 2 - PhysX

Published November 14, 2013
Advertisement

Middleware and 3rd Party Libraries in Auxnet - Part 2 - Phys X


PhysXbyNV_220x125.png

It's been a couple of weeks since I've updated, but I want to continue writing about the different middleware and 3rd party libraries that I've been using. Now I'll give some information on how I use the popular physics library PhysX by Nvidia.

What is it?


PhysX is the physics library from Nvidia. It was made by Nvidia, but it works on non-Nvidia graphics cards. I use version 3 which doesn't require any additional drivers to be installed.

PhysX can be used for rigid body physics and collision detection. It has built in shapes that can be used such as boxes, spheres, and capsules. It also supports heightfields, convex hulls, and triangle meshes.

Why did I choose it?


I was in need of a nice collision detection system and this suited my needs nicely. At the time that I found out about this, I was just a hobbyist and was looking for a free solution (or at least something that would be free until I started to make money). I tried two other physics engines and felt the most comfortable with this one.

I also liked the Phys X 2 documentation. The documentation for version 2 is much more complete than PhysX 3, but after becoming familiar with 2.8, version 3 was not too difficult. If you don't have much experience, working with the Phys X 3 documentation may be a little difficult. Even I often have to study the example code to try to figure out what's going on sometimes.

How do I use it in the game / engine?


I currently only use PhysX for collision detection. My game engine has one major division in its objects based on class lifetimes. The first division is application level and the other is state level. Application level objects are classes that need to be alive from application start until the application dies, and state level objects live and die with a state. I also use a plugin system to add functionality that's similar to adding components in a component-based entity system. Because of this, I have two basic classes that I feel fit nicely with the way PhysX is organized, CPhysX3AppAddon and CPhysX3StateAddon.

CPhysX3AppAddon
This class is responsible for physics objects whose lifetimes are the same as the app and things that shouldn't be created and recreated. It includes the following:[code=js:0]physx::PxFoundation *m_Foundation;// This should be created first to instance the higher level SDKs. As stated in the// docs "Every PhysX module requires a PxFoundation instance to be available"physx::PxPhysics *m_Physics;// This is a factory class used for instancing objects in the Physics SDK.physx::PxCooking *m_Cooking; // Only if needed// This is used to preprocesses or cook raw data and turn it into a form that can be used by PhysX
CPhysX3StateAddon
The main job of this class is to take care of the scene. So it keeps an instance to a physx::PxScene *m_Scene object. All physics bodies should be associated with a scene. As stated in the docs, "a scene is a collection of bodies, particle systems and constraints which can interact. The scene simulates the behavior of these objects over time. Several scenes may exist at the same time, but each body, particle system or constraint is specific to a scene -- they may not be shared."

The engine uses component based entities. Physics components are registered with this class.

What are my future plans?


I hope to be able to do more things with PhysX in the future like being able to throw things and have them bounce in a realistic way. I also want to see what interesting effects I can achieve by adding things like forces and adjusting gravity. Code-wise, when it comes to the ever evolving design of this engine, I want to see if CPhysX3AppAddon is even necessary. Maybe it would be better to keep things together and create and destroy all Phys X objects with the state.

Squared'D on social media


These days, I've been trying to increase my internet presence. I'm on Google+ now, and I have a YouTube channel. If you'd also like to gain more exposure, let's subscribe and follow one another so we can pick up more followers. I think this could help some of us grow our brands. You can leave a comment below if you think this sounds like a good idea. I'll follow most games; however, I'm not into over the top violent and horror games.

Google+: Squared'D Game Google+ Page


YouTube: Squared'D Youtube Channel


dtalogo.png

auxnet+wall+paper-medium.png
0 likes 2 comments

Comments

cgrant

Just a little clarification so as not to confuse readers. Physx only support GPU simulation only on Nvidia GPU, all other platforms will run the simulation on the CPU.

November 19, 2013 05:09 AM
Squared'D

Thanks for pointing that out.

November 22, 2013 01:20 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement