Featured Posts

8. Bump Mapping in GLSL8. Bump Mapping in GLSL Introduction Bump mapping is essential in todays computer games, and computer graphics in general. Would you like to know the best thing about it? It is extremely simple to implement. Bump mapping works...

Read more

Swiftless GLSL Shader DeveloperSwiftless GLSL Shader Developer Swiftless GLSL Shader Developer   Version 0.1a Currently Swiftless GLSL Shader Developer is in it's first public release, and is currently in alpha status, meaning it is not complete and may contain...

Read more

Wordpress Optimization Wordpress Website Optimizations Introduction Wordpress itself is a fairly wonderful tool. Since switching to it, I find it is a lot quicker to make changes to my website and it is also quicker to get...

Read more

36. OpenGL Framebuffers36. OpenGL Framebuffers Introduction Frame buffers are one of those mythical things that we have all heard of, but many beginner OpenGL developers avoid because there is not much information about them, and they can be confusing...

Read more

1. Terrain Class1. Terrain Class Terrain is one of those things that so far, hasn't been perfectly recreated in computer graphics. But it is almost there! Looking over a beautiful landscape can be one of the most amazing feelings in the...

Read more

  • Prev
  • Next

5. PhysX Materials

Posted on : 25-03-2010 | By : Swiftless | In : Physx

0

Jump To:
main.cpp Source
Download

Main.CPP File:

For our fourth PhysX tutorial, we are just going to set a couple of paramters for our SDK and our scene. These are all going to take place in our initNX function.

First off we are going to set a default skin width for objects in our scene. But first I will explain what this does. Each object has it’s own skin that goes around the object at the width of the skin depth we are going to set. This skin is used for interpenetration between objects to account for inaccuracy when stacking objects on top of each other. The skin allows the objects to penetrate each other, at the width of the skin. The width of the skin that should be needed depends on the size of the objects as it can lead to visible penetration. The default skin width is set to 0.025. To set the skin width we just use the following line after we set the Physics SDK:

NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0);

defaultMaterial->setRestitution(0.5);
defaultMaterial->setStaticFriction(0.5);
defaultMaterial->setDynamicFriction(0.5);

There are a couple of parameters covered (there are LOTS more). Check out the next tutorial for setting materials here.

If you have any questions, just email me at swiftless@gmail.com

#include <stdio.h>

#include <GL\glut.h>
#include <GL\gl.h>

#include <Physics\include\NxPhysics.h>

#define NOMINMAX

#include <windows.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;

NxScene* gScene = NULL;

void initNX(void){
gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);

gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

NxSceneDesc sceneDesc;
sceneDesc.gravity.set(0.0f, -9.8f, 0.0f);
sceneDesc.simType = NX_SIMULATION_SW;

gScene = gPhysicsSDK->createScene(sceneDesc);

NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0);
defaultMaterial->setRestitution(0.5);
defaultMaterial->setStaticFriction(0.5);
defaultMaterial->setDynamicFriction(0.5);

}

void deinitNX(void){
gPhysicsSDK->releaseScene(*gScene);
gScene = 0;

gPhysicsSDK->release();

}

void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity();

glutSwapBuffers();
}

void reshape(int w, int h){
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);

}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);

glutCreateWindow("Physics");

initNX();

glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);

glutMainLoop();

deinitNX();

return 0;
}

Download:

Download main.cpp Source Code for this Tutorial

VN:F [1.9.3_1094]
Please rate so I know where to improve the site. 1 means needs a lot of improvement, 10 means perfect. If you leave a low rating, please state why. I don't want people just coming to bash the site.
Rating: 6.0/10 (4 votes cast)
VN:F [1.9.3_1094]
Rating: +1 (from 1 vote)

4. PhysX Parameters

Posted on : 25-03-2010 | By : Swiftless | In : Physx

1

Jump To:
main.cpp Source
Download

Main.CPP File:

For our fourth PhysX tutorial, we are just going to set a couple of parameters for our SDK and our scene. These are all going to take place in our initNX function.

First off we are going to set a default skin width for objects in our scene. But first I will explain what this does. Each object has it’s own skin that goes around the object at the width of the skin depth we are going to set. This skin is used for interpenetration between objects to account for inaccuracy when stacking objects on top of each other. The skin allows the objects to penetrate each other, at the width of the skin. The width of the skin that should be needed depends on the size of the objects as it can lead to visible penetration. The default skin width is set to 0.025. To set the skin width we just use the following line after we set the Physics SDK:

// gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

Next up, we are going to set the simulate mode for our program. If you are like me and don’t have a PhysX card (simply due to the cost), then you will be running the SDK in software mode. You can setup your program to detect a PhysX card and set this accordingly, but I am just going to set it to software mode straight out:

// sceneDesc.simType = NX_SIMULATION_SW;

To set it to hardware mode, the code is just:

// sceneDesc.simType = NX_SIMULATION_HW;

There are a couple of parameters covered (there are LOTS more). Check out the next tutorial for setting materials here.

If you have any questions, just email me at swiftless@gmail.com

#include <stdio.h>

#include <GL\glut.h>
#include <GL\gl.h>

#include <Physics\include\NxPhysics.h>

#define NOMINMAX

#include <windows.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;

NxScene* gScene = NULL;

void initNX(void){
gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);

gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

NxSceneDesc sceneDesc;
sceneDesc.gravity.set(0.0f, -9.8f, 0.0f);
sceneDesc.simType = NX_SIMULATION_SW;

gScene = gPhysicsSDK->createScene(sceneDesc);

}

void deinitNX(void){
gPhysicsSDK->releaseScene(*gScene);
gScene = 0;

gPhysicsSDK->release();

}

void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity();

glutSwapBuffers();

}

void reshape(int w, int h){
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);

glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL);
glutInitWindowSize(500, 500);

glutInitWindowPosition(100, 100);
glutCreateWindow("Physics");

initNX();

glutDisplayFunc(display);
glutIdleFunc(display);

glutReshapeFunc(reshape);

glutMainLoop();

deinitNX();

return 0;
}

Download:

Download main.cpp Source Code for this Tutorial

VN:F [1.9.3_1094]
Please rate so I know where to improve the site. 1 means needs a lot of improvement, 10 means perfect. If you leave a low rating, please state why. I don't want people just coming to bash the site.
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

3. PhysX Scenes

Posted on : 25-03-2010 | By : Swiftless | In : Physx

1

Jump To:
main.cpp Source
Download

Main.CPP File:

Here’s our third PhysX tutorial, and it doesn’t look like we are getting anywhere, but this tutorial is going to start getting into the PhysX SDK. We are going to create a scene which will calculate all our physics interactions. Just like OpenGL needs a window to draw to, PhysX needs a scene to simulate a world with. But don’t interperet this wrong, the PhysX SDK DOES NOT do any rendering for you.

So, continuing on from the previous tutorial, we need to create a new global variable that will be the scene for our PhysX world. This is going to be called gScene, and takes the type NxScene. We will set it like so:

// NxScene* gScene = NULL;

So we have a scene, what do we do with it? First off we are going to set the most basic of properties, gravity. So we need to create a scene descriptor which will hold the properties for our scene. We are going to start off with creating a variable for our scene descriptor called sceneDesc like so:

NxSceneDesc sceneDesc;

Now that we have a scene descriptor, we need to set our gravity:

// sceneDesc.gravity.set(0.0f, -9.8f, 0.0f);

And now we are going to create our scene:

// gScene = gPhysicsSDK->createScene(sceneDesc);

So we now have a scene that we can add objects to, and adjust its properties as needed. Eg: In the game Prey, we change the gravity direction throughout to allow for a new type of gameplay.

To close up our program, we need to go to our deinitNX function and release our scene:

// gPhysicsSDK->releaseScene(*gScene);
// gScene = 0;

So we now have a scene, in our next tutorial we are going to start playing with some different parameters. You can check it out here.

If you have any questions, just email me at swiftless@gmail.com

#include <stdio.h>

#include <GL\glut.h>
#include <GL\gl.h>

#include <Physics\include\NxPhysics.h>

#define NOMINMAX

#include <windows.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;

NxScene* gScene = NULL;

void initNX(void){
gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);

NxSceneDesc sceneDesc;
sceneDesc.gravity.set(0.0f, -9.8f, 0.0f);
gScene = gPhysicsSDK->createScene(sceneDesc);
}

void deinitNX(void){

gPhysicsSDK->releaseScene(*gScene);
gScene = 0;

gPhysicsSDK->release();
}

void display(void){

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity();

glutSwapBuffers();
}

void reshape(int w, int h){
glViewport(0,0, (GLsizei)w, (GLsizei)h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv) {

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("Physics");

initNX();

glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);

glutMainLoop();

deinitNX();

return 0;
}

Download:

Download main.cpp Source Code for this Tutorial

VN:F [1.9.3_1094]
Please rate so I know where to improve the site. 1 means needs a lot of improvement, 10 means perfect. If you leave a low rating, please state why. I don't want people just coming to bash the site.
Rating: 10.0/10 (2 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

2. PhysX Windows

Posted on : 25-03-2010 | By : Swiftless | In : Physx

0

Jump To:
main.cpp Source
Download

Main.CPP File:

Now that we have our workspace setup for coding with the PhysX SDK, lets get a basic program up and running that incorporates OpenGL. I am going to start off with a base OpenGL program with a display function and reshape function, and the base GLUT code in our main function. The base of this program looks simply like this:

// #include <GL\glut.h>
// #include <GL\gl.h>

// void display(void){
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// glLoadIdentity();

// glutSwapBuffers();
// }

// void reshape(int w, int h){

// glViewport(0,0, (GLsizei)w, (GLsizei)h);
// glMatrixMode(GL_PROJECTION);
// glLoadIdentity();
// gluPerspective(60, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);
// glMatrixMode(GL_MODELVIEW);
// }

// int main(int argc, char** argv) {
// glutInit(&argc, argv);
// glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL);
// glutInitWindowSize(500, 500);
// glutInitWindowPosition(100, 100);
// glutCreateWindow("Physics");

// glutDisplayFunc(display);
// glutIdleFunc(display);
// glutReshapeFunc(reshape);

// glutMainLoop();

// return 0;

// }

So lets go ahead and create a function to initialize our PhysX SDK with. I am going to call this initNX. This is going to contain the code from the previous tutorial for Physics SDK:

// void initNX(void){
// gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
// }

Now that we have initialized the PhysX SDK, lets go ahead and create a cleanup function which I am going to call deinitNX:

// void deinitNX(void){
// gPhysicsSDK->release();
// }

These functions are going to be called from inside our main function:

// int main(int argc, char** argv) {
// glutInit(&argc, argv);

// glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL);
// glutInitWindowSize(500, 500);
// glutInitWindowPosition(100, 100);
// glutCreateWindow("Physics");

// initNX();

// glutDisplayFunc(display);
// glutIdleFunc(display);
// glutReshapeFunc(reshape);

// glutMainLoop();

// deinitNX();

// return 0;
// }

In my opinion, this is looking much neater and much more like a program than the last tutorial. So next up we are going to create a virtual scene for our physics calculations to take place. Check it out here.

If you have any questions, just email me at swiftless@gmail.com

#include <stdio.h>

#include <GL\glut.h>
#include <GL\gl.h>

#include <Physics\include\NxPhysics.h>

#define NOMINMAX

#include <windows.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;

void initNX(void){
gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
}

void deinitNX(void){
gPhysicsSDK->release();

}

void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity();

glutSwapBuffers();
}

void reshape(int w, int h){
glViewport(0,0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);

}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);

glutCreateWindow("Physics");

initNX();

glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);

glutMainLoop();

deinitNX();

return 0;
}

Download:

Download main.cpp Source Code for this Tutorial

VN:F [1.9.3_1094]
Please rate so I know where to improve the site. 1 means needs a lot of improvement, 10 means perfect. If you leave a low rating, please state why. I don't want people just coming to bash the site.
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

1. PhysX Includes

Posted on : 25-03-2010 | By : Swiftless | In : Physx

0

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.

Anyway, once you have the SDK, navigate to the:
\Program Files\AGEIA Technologies\AGEIA PhysX SDK\v2.7.0\SDKs\

folder and copy the Physics folder to:
\Program Files\Microsoft Visual Studio\VC98\Include\

Next up we are going to navigate to:
\Program Files\AGEIA Technologies\AGEIA PhysX SDK\v2.7.0\SDKs\lib\win32
and we are going to copy every file from this folder to:
\Program Files\Microsoft Visual Studio\VC98\Lib

Theoretically, we should now be able to start coding using the PhysX SDK. So lets test it out. The first lines of code we are going to use are:

// #include <Physics\include\NxPhysics.h>

// #define NOMINMAX

*note, you must #define NOMINAX before using the windows.h file*

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(){return0;} 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 :-P 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 we are then going to need to release our Physics SDK so we can clean up and close our program, this is done with the following line:

// gPhysicsSDK->release();

So our main function will look like:

// int main(int argc, char** argv) {

// gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
// gPhysicsSDK->release();
// return 1;
// }

Now just compile and run this program. If it works, we are ready to start some serious coding. If it doesn’t please email me and I will try to help you sort it out.

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

If you have any questions, just email me at swiftless@gmail.com

#include <stdio.h>

#include <GL\glut.h>
#include <GL\gl.h>

#include <Physics\include\NxPhysics.h>

#define NOMINMAX

#include <windows.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);
gPhysicsSDK->release();
return 1;
}

Download:

Download main.cpp Source Code for this Tutorial

 

VN:F [1.9.3_1094]
Please rate so I know where to improve the site. 1 means needs a lot of improvement, 10 means perfect. If you leave a low rating, please state why. I don't want people just coming to bash the site.
Rating: 9.3/10 (3 votes cast)
VN:F [1.9.3_1094]
Rating: +2 (from 2 votes)
Improve the web with Nofollow Reciprocity.