4. PhysX Parameters

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

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>