Previous Blog Next Blog
Prev/Next Blog
by date

PhysX Integration

PhysX Integration
Name:James Thompson 
Date Posted:Apr 11, 2006
Rating:3.5 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for James Thompson

Blog post
Hi,

This seems like an impossible task, im going to try to integrate the PhysX SDK into Torque for DawnOfMen.
I know this has already been done so I know that the code is out there somewhere but Ageia wont reply to my e-mails, and GG did not write the code, at least I don't think they did?

So there you have it im going to go for it. It should be worth it, in my castle siege game. Lets hope it is :)

Ill update you on the progress every time I hit a new landmark.

Any tips, including code, would be great ;)


EDIT: Already been done :) see below

Recent Blog Posts
List:11/04/06 - DOM, SG and future resources
10/01/06 - Progress on various things
09/02/06 - DawnOfMen & me
07/01/06 - DawnOfMen Alpha Progress
06/25/06 - DawnOfMen Alpha Release
06/18/06 - RSS
06/05/06 - DawnOfMen 0.8
05/29/06 - X-Fire Integration continued

Submit ResourceSubmit your own resources!

N R Bharathae   (Apr 11, 2006 at 10:20 GMT)
How about some encouragement. Everyone who wants better physics but were afraid to try are behind you, James. Good Luck!

Martin de Richelieu   (Apr 11, 2006 at 10:31 GMT)   Resource Rating: 4
Sounds really cool, looking forward to see your progress

X-Tatic   (Apr 11, 2006 at 10:57 GMT)   Resource Rating: 1
The sample code in the PhysX SDK is plenty.

Scott Burns   (Apr 11, 2006 at 13:01 GMT)
James, I'm going to be getting started on this as well in the next day or two. I'll let you know how things go on my end.

When I downloaded the sdk I was playing the reinforced wall demos and thought it would be perfect for a castle seige game.

Alan H   (Apr 11, 2006 at 13:03 GMT)
Physics is relative.

Matt Vitelli   (Apr 11, 2006 at 13:45 GMT)
Why take the time to integrate PhysX? Doesnt that mean that if people want to see the physics effect they'll need one of those cards from Ageia?

Jeremiah Fulbright   (Apr 11, 2006 at 13:59 GMT)
PhysX is the Library, not a card requirement!

As for integration, Good luck.. I had done some preliminary stuff got everything init'ing and even actor creation, but all non-visible (ala not in the game world). I talked to my Account Rep at AGEIA and they told me to talk to GG, as an implementation was supposedly being done by GG, but I have recieved no answer either way.

I have access to another engine which already had PhysX integrated and wrapped into C#, so I know alot of stuff needed to wrap functions and variables into TorqueScript, but not sure how much help it'll give me, If I decide to give it a go again

Feel free to contact me if I can of any service though
Edited on Apr 11, 2006 15:44 GMT

James Thompson   (Apr 11, 2006 at 16:25 GMT)
Thanks for the replys!

Jeremiah: yeah ive got no response from GG when i've asked about PhysX, did you need to make any changes to the PhysX files to get them to init?
Edited on Apr 11, 2006 16:27 GMT

James Thompson   (Apr 11, 2006 at 17:35 GMT)
Okay ive had a look at this, got the include files done and the lib files, all added to the compile list.
I've created a file in 'game' called physx.h and put this in it:

//-----------------------------------------------------------------------------
// Torque Game Engine PhysX Core
//-----------------------------------------------------------------------------
#ifndef PhysX
#define PhysX

#define NOMINMAX
#ifdef WIN32
#include <windows.h>

#include "NxPhysics.h"


That loads up the physx engine, i believe.

now on to some more advanced stuff :(
Edited on Apr 11, 2006 17:39 GMT

James Thompson   (Apr 11, 2006 at 18:00 GMT)
PhysX.h now looks like lesson_01.h :)
but with a major change that enables you to actually compile it :)

#ifndef PhysX_H
#define PhysX_H

#define NOMINMAX
#ifdef WIN32
#include <windows.h>
#include "NxPhysics.h"

#include <GL/gl.h>
#include <GL/glut.h>
#elif LINUX
#include <windows_replacement.h>
#include <GL/gl.h>
#include <GL/glut.h>
#elif __APPLE__
#include <windows_replacement.h>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#endif
#include <stdio.h>

void PrintControls();
void ProcessCameraKeys();
void SetupCamera();
void RenderActors(bool shadows);

void ProcessForceKeys();
void ProcessInputs();

void RenderCallback();
void ReshapeCallback(int width, int height);
void IdleCallback();
void KeyboardCallback(unsigned char key, int x, int y);
void KeyboardUpCallback(unsigned char key, int x, int y);
void SpecialCallback(int key, int x, int y);
void MouseCallback(int button, int state, int x, int y);
void MotionCallback(int x, int y);
void ExitCallback();
void InitGlut(int argc, char** argv);

void InitNx();
void ReleaseNx();
void ResetNx();

void StartPhysics();
void GetPhysicsResults();

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


#endif // PhysX

Luke *V8motorhead* Jones   (Apr 11, 2006 at 22:17 GMT)
James,

#include <GL/gl.h>
#include <GL/glut.h>
#elif LINUX
#include <windows_replacement.h>
#include <GL/gl.h>
#include <GL/glut.h>
#elif __APPLE__
#include <windows_replacement.h>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#endif
#include <stdio.h>


that stuff isn't needed, unless you plan to write cubes in the code and render them with your own GL calls.

All you really need are :

void InitNx();
void ReleaseNx();
void ResetNx();

void StartPhysics();
void GetPhysicsResults();

You want to call InitNx from main.cc somewhere (this is all very much the same as Newton Dynamics) ReleaaseNx needs to be called when the game ends, ResetNx, guess thats for when you start a new game and need to clear the physics world. StartPhysics, call that when you start your game.
Most important GetPhysicsResults, call that every tick to update with the simulation.

Now, a couple of the callbacks will be needed, most notably rendercallback, so you can update the torque screen. And, your going to have to write your own callback functions for it.

You got some hard work ahead of you bud.

If you want, I can do a quick conversion from my Newton code so that you can see how PhysX will be initialised.

Luke *V8motorhead* Jones   (Apr 11, 2006 at 22:22 GMT)
I'll have a crack at it soon, let you see what I come up with.
The one problem I had, was getting the terrain collision, getting shapes seems to be easy enough, but thats it.

James Thompson   (Apr 12, 2006 at 09:02 GMT)
Luke: Id love the newton code :)


I could put

void InitNx();

in

static bool initLibraries()

or should it be in

bool initGame(int argc, const char **argv)
Edited on Apr 12, 2006 09:10 GMT

James Thompson   (Apr 12, 2006 at 09:04 GMT)
and

void ReleaseNx();

in

static void shutdownLibraries()

or in

void shutdownGame()
Edited on Apr 12, 2006 09:06 GMT

James Thompson   (Apr 12, 2006 at 09:07 GMT)
void ResetNx();

in

void fpsReset()

James Thompson   (Apr 12, 2006 at 09:09 GMT)
void GetPhysicsResults();

in

void fpsUpdate()

James Thompson   (Apr 12, 2006 at 09:27 GMT)
Okay done the above changes and a few major changes to the physX sdk (mainly in nxallocatable) and got it too compile.
The mission load up too :)
So I believe I have got the physx sdk to load and release, got to put in some echos to the console to make sure

Shannon "ScarWars" Scarvaci   (Apr 13, 2006 at 00:51 GMT)
I have done intergrate physX in tge 1.4 but not yet complete. Here the video.

www.scarvaci.com/small_physx.avi
Edited on Apr 13, 2006 00:52 GMT

Chris \"C2\" Byars   (Apr 13, 2006 at 02:13 GMT)   Resource Rating: 5
@Shannon:

Looking forward to a resource ;)

Shannon "ScarWars" Scarvaci   (Apr 13, 2006 at 09:08 GMT)
Here the other video www.scarvaci.com/small_physx2.avi

There is a bit of improvement but the terrain is still the problem.

The physX limit for terrain is 256x256 so if your mission have terrain with squareSize = 2 and you may notice the gap between it coz terrain is 512x512 but for collision in physX would be 256x256. So I'll working it out for this terrain later but now I try use player to push it around.

And for networking seem work well with minor lag.

James Thompson   (Apr 13, 2006 at 09:32 GMT)
Wow nice!
Could you send me those files? Or upload them as a resource?

Shannon "ScarWars" Scarvaci   (Apr 13, 2006 at 09:41 GMT)
@James

Yes I'll put them as a resource...but I need to fix things up before put in the resource.

Please wait for a week or two.

James Thompson   (Apr 13, 2006 at 10:46 GMT)
Thanks you so much, will be looking forward to it :)

James Thompson   (Apr 13, 2006 at 10:48 GMT)
Does the integration support the PhysX hardware?

Shannon "ScarWars" Scarvaci   (Apr 13, 2006 at 12:01 GMT)
This PPU support is a must! but that the last things on "to do" list because there no PPU yet.

James Thompson   (Apr 13, 2006 at 14:24 GMT)
Well you can pre-order one or buy a new system but the new system is probably a bit too expensive (
Edited on Apr 13, 2006 14:38 GMT

Christian Weber   (Apr 13, 2006 at 15:48 GMT)   Resource Rating: 5
this physx library is like ode right? with ragdoll, cloth, foliage swaying around aso.? doesn't the library also cost something? is it free for integration? awesome work so far. :)

James Thompson   (Apr 13, 2006 at 18:24 GMT)
Yes, like ode, but PhysX is faster, can have more objects, etc.

The library is free as long as you include support for the PhysX H/W

James Thompson   (Apr 13, 2006 at 18:27 GMT)
Shannon - sorry might have told a load of people about your inetgration, didnt mean to put any pressure on you, sorry :(

Christian Weber   (Apr 13, 2006 at 20:23 GMT)   Resource Rating: 5
Thanks James, that really sounds awesome. :) Can't wait to have this in tge/tse. :) That's exactly what I need for our game project using tse. :)

Luke *V8motorhead* Jones   (Apr 14, 2006 at 01:30 GMT)
Don't forget, PPU support means, enable a bunch more stuff if the card is present.
I'm seriosly hoping that shannons code will provide the missing bits for my newton integration....

Jeremiah Fulbright   (Apr 14, 2006 at 02:33 GMT)
Its nice to see something finally working, although its just Rigid Shape dynamics.. The fun stuff is Rigid Shape + Joints for Ragdoll stuff and Cloth physics (which requires rendering support) and Fluid physics (which also requires rendering support).

HW Physics means alot more items, but it also means more optimization for collisions and meshes themselves, and there are limits for HW Physics currently.. Software can actually do more overall, than HW right now..

And for PPU support, its a matter of enabling it in the SDK and you need 2.4.0 SDK or better which isn't publically available (that I have seen), but an Aegia rep should be able to supply you with it (as they did for me)

Scott Burns   (Apr 14, 2006 at 18:15 GMT)
James, did you get these two errors? How did you get rid of them?

c:\torque 1.4\lib\physx\foundation\include\nx.h(34) : fatal error C1189: #error : custom definition of NX_CALL_CONV for your OS needed!

BSCMAKE: error BK1506 : cannot open file '..\engine\out.VC6.DEBUG\game.sbr': No such file or directory

Shannon "ScarWars" Scarvaci   (Apr 15, 2006 at 01:24 GMT)
@Scott

At the configuration properties of this game, put WIN32 in c/c++ -> preproccessor definitions. Or put #define WIN32 before calling #include <NxPhysics.h>

Scott Burns   (Apr 17, 2006 at 18:08 GMT)
@Shannon

Thanks, I thought I had that in there but I guess I missed it. I've started over now and am up to NxAllocatable now.

Shannon "ScarWars" Scarvaci   (Apr 18, 2006 at 00:09 GMT)
@Scott

You can find the resource in here to save your time :D
Edited on Apr 18, 2006 00:18 GMT

You must be a member and be logged in to either append comments or rate this resource.