1. PhysX Includes

Jump To:
main.cpp Source
Download
|
Main.CPP File: Welcome to the first of MANY PhysX tutorials helping you to start off with Ageia’s PhysX SDK. If you haven’t got the SDK already, head to Ageia’s website and download it. You will need it for these tutorials. The original setup for this tutorial copied the PhysX 2.7 headers and libraries into Visual Studio’s global #include <Physics\include\NxPhysics.h> #define NOMINMAX Note: you must Next up we are going to attach our library files. These are: #pragma comment(lib,"PhysXLoader.lib") #pragma comment(lib,"NxCharacter.lib") #pragma comment(lib,"NxCooking.lib") #pragma comment(lib,"NxExtensions.lib") Now you can test this out, by just having a simple int main() { return 0; } function to see if it will compile if you want, but I am going to go just one step further and create our SDK for use. We first need a NxPhysicsSDK type variable which is going to be called gPhysicsSDK (If you have played with the PhysX SDK before, you will notice that alot of my variables are named the same as theirs, simply because I learnt it that way 😛 So here’s our gPhysicsSDK variable: static NxPhysicsSDK* gPhysicsSDK = NULL; Now that we have something to create our PhysicsSDK with, we go to our int main() function which will start off like so: int main(int argc, char** argv) {
return 1;
}
Now that we have a main function, we are going to set out gPhysicsSDK. we do this with the following line: gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION); This will create the Physics SDK using the current PhysX version you have installed on your computer. In my case, version 2.7.0 as of this tutorial. If this creates properly, check that the pointer is not gPhysicsSDK->release(); So our main function will look like: int main(int argc, char** argv) {
gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
if (gPhysicsSDK == NULL) {
return 1;
}
gPhysicsSDK->release();
gPhysicsSDK = NULL;
return 0;
}
Now just compile and run this program. If it works, we are ready to start some serious coding. If it doesn’t compile, double-check the PhysX 2.7 include/library paths and make sure the SDK architecture matches the project you are building. It may not seem like much, but once you get all this done, IMO you have just completed the hardest part in beginning with the SDK. The next tutorial here is about creating a GLUT window to draw to for when we get to rendering our Physics #include <cstdlib>
#include <stdio.h>
#include <GL/glut.h>
#include <GL/gl.h>
#define NOMINMAX
#include <windows.h>
#include <Physics/include/NxPhysics.h>
#pragma comment(lib, "PhysXLoader.lib")
#pragma comment(lib, "NxCharacter.lib")
#pragma comment(lib, "NxCooking.lib")
#pragma comment(lib, "NxExtensions.lib")
static NxPhysicsSDK *gPhysicsSDK = NULL;
int main(int argc, char **argv) {
gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
if (gPhysicsSDK == NULL) {
return 1;
}
gPhysicsSDK->release();
gPhysicsSDK = NULL;
return 0;
}
|
Source & downloads
Questions or corrections? If something doesn’t work or you spot something I’ve got wrong, leave a comment below. These tutorials have been around a long time, so useful corrections are always welcome!
I can’t see your site on my iphone. All the text is clipped on the right.
I know, sorry. These tutorials are very much out of date and are meant for Ageia PhysX which was bought by nVidia a few years ago.
Because the tutorials are so out of date, I don’t plan on re-writing them for the latest nVidia PhysX.
Thanks,
Swiftless
Amazing tutorials keep em comming 🙂
hello swl,
may I add that
SDKs/PhysxLoader/include
and
SDKs/Foundation/include
were required to be added to compile the above code
Hi Paras,
I’m surprised the code still compiles, it is several SDK’s old, back when AGEIA owned PhysX. It’s good to hear though 🙂
Cheers,
Swiftless
Hi Swiftless,
Thanks for your tutorial it is really helpful.
I have a problem and perhaps you can help me : the function NxCreatePhysicsSDK always returns NULL.
Do you have any idea why ?
Hi Alex,
It might have something to do with the changes in the PhysX SDK since I wrote these tutorials. I wouldn’t recommend my PhysX tutorials anymore because they are too old, although I have personally updated some for my own reference offline and it was fairly simple. Just use the SDK guide as a reference.
Cheers,
Swiftless