Game Development Community

dev|Pro Game Development Curriculum

PhysX Integration

by Skylar Kelty · 04/11/2006 (2:07 am) · 36 comments

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
Page «Previous 1 2
#1
04/11/2006 (3:20 am)
How about some encouragement. Everyone who wants better physics but were afraid to try are behind you, James. Good Luck!
#2
04/11/2006 (3:31 am)
Sounds really cool, looking forward to see your progress
#3
04/11/2006 (3:57 am)
The sample code in the PhysX SDK is plenty.
#4
04/11/2006 (6:01 am)
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.
#5
04/11/2006 (6:03 am)
Physics is relative.
#6
04/11/2006 (6:45 am)
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?
#7
04/11/2006 (6:59 am)
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
#8
04/11/2006 (9:25 am)
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?
#9
04/11/2006 (10:35 am)
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

#include "NxPhysics.h"


That loads up the physx engine, i believe.

now on to some more advanced stuff :(
#10
04/11/2006 (11:00 am)
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
#include "NxPhysics.h"

#include
#include
#elif LINUX
#include
#include
#include
#elif __APPLE__
#include
#include
#include
#endif
#include

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
#11
04/11/2006 (3:17 pm)
James,

#include
#include
#elif LINUX
#include
#include
#include
#elif __APPLE__
#include
#include
#include
#endif
#include


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.
#12
04/11/2006 (3:22 pm)
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.
#13
04/12/2006 (2:02 am)
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)
#14
04/12/2006 (2:04 am)
and

void ReleaseNx();

in

static void shutdownLibraries()

or in

void shutdownGame()
#15
04/12/2006 (2:07 am)
void ResetNx();

in

void fpsReset()
#16
04/12/2006 (2:09 am)
void GetPhysicsResults();

in

void fpsUpdate()
#17
04/12/2006 (2:27 am)
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
#18
04/12/2006 (5:51 pm)
I have done intergrate physX in tge 1.4 but not yet complete. Here the video.

www.scarvaci.com/small_physx.avi
#19
04/12/2006 (7:13 pm)
@Shannon:

Looking forward to a resource ;)
#20
04/13/2006 (2:08 am)
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.
Page «Previous 1 2