Tuesday, April 26, 2011

PhysX Basics Tutorial: Getting started with NVIDIA PhysX

I went to see the power of the NVIDIA PhysX sdk. So I downloaded the sdk from the PhysX developer site. While the sdk contains a lot of demos, for a beginner like me it was quite tedious to get started. I initially started with the documentation and I must say it is pretty good at explaining the API. So my next step was to look at the internet to find out if there are any basic tutorials. Fortunately, I came across Swiftless Tutorials (http://www.swiftless.com/misctuts/physxtuts.html) on AGEIA PhysX (before acquired by NVIDIA, AGEIA owned this sdk). These were very helpful for me in understanding how to get up and running with NVIDIA PhysX sdk. So I will try to fill the gap by doing basic PhysX tutorials.

These tutorials are based on the latest NVIDIA PhysX sdk version 2.8.4. This sdk does not ask u for installing the system software. Thus its your responsibilty to handle the dlls required. Which dlls u need I will explain in a minute. I will use freeglut in this tutorial series.

Getting started with NVIDIA PhysX
We need to include the headers first.

#include <iostream >
#include <nxphysics.h >
using namespace std;
#pragma comment(lib, "PhysXLoader.lib")

The last header NxPhysics.h is the header needed for PhysX. The rest are for c++ output/input stuff. I like to programmatically add the linker libraries. For this basic startup demo, we only need the PhysxLoader.lib/dll so we link to it.
void main() {

NxSDKCreateError whatError;
NxPhysicsSDK* pPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION,0,0, NxPhysicsSDKDesc(), &whatError);
if(pPhysicsSDK) {
} else {
cerr << "Cannot create PhysX device." << endl;
cerr << "Reason: " << whatError;

Thats it. If u try to compile and run the code, the pPhysicsSDK pointer will be NULL and the error code will be NXCE_PHYSX_NOT_FOUND. The reason for this is because the required dlls are needed to be copied to the current solution folder. These dlls are PhysXLoader.dll and PhsyXCore.dll. That's it you have the helloworld PhysX program.

Next, we will look at how to hook glut with PhysX in the next tutorial.
Hope you will enjoy the rest of the tutorials. Source codes are here


Sur Aliad said...

Hello. I am currently trying to get started with PhysX SDK and I have followed and tried every single one of your tutorials, but I can't seem to be able to get anything working. I am using VisualStudio 2010, and I intend to use PhysX 2.8.4. I try this tutorial, copy/paste the code into my project, and get a ton of errors about missing files. I am quite desperate now, since I've also tried to use PhysX 3.1 and 3.2, and after trying to copy/paste your code into my project, error appear. I mention that I have inserted the right files in the lib and include folders of visual studio. Could you please help me? I am quite in a desperate situation and don't know what to do.

Muhammad Mobeen Movania said...

Hi Sur Aliad,
What errors do you get? Could you copy/paste the errors here or an image so that I might know what might be wrong. Worst case, you can email me your project and I will revert with the answer.


Popular Posts

Copyright (C) 2011 - Movania Muhammad Mobeen. Awesome Inc. theme. Powered by Blogger.