I have managed to get the "PhysX integration" tutorial to work with the latest version of both engines (see title for version reference).
The link to the tutorial on the site:
http://irrlicht.sourceforge.net/tut_physx.html
I recommend you to read that tutorial first and download the project.
I have made a few modifications to the code.
There are still things that could be improved, but i don't have the time for it right now.
Feel free to contribute on the project for the community
Now that is said, lets move on to the tutorial.
You'll need to copy the "CAnimatedMeshSceneNode.h" and "CAnimatedMeshSceneNode.cpp" to your project directory.
After that, rename the file names from:
"CAnimatedMeshSceneNode.h" and "CAnimatedMeshSceneNode.cpp".
To:
"CPhysXAnimatedMeshSceneNode.h" and "CPhysXAnimatedMeshSceneNode.cpp".
And the class name "CAnimatedMeshSceneNode", constructor "CAnimatedMeshSceneNode" and destructor "~CAnimatedMeshSceneNode".
To:
"CPhysXAnimatedMeshSceneNode".
And all the namespaces in the "CAnimatedMeshSceneNode.cpp" file.
Instead of naming them "CPhysXAnimatedMeshSceneNode", you can choose whatever you like. But keep in mind that they have to match.
For example this is my class:
Code: Select all
class CPhysXAnimatedMeshSceneNode : public IAnimatedMeshSceneNode
And this is my constructor:
Code: Select all
//! constructor
CPhysXAnimatedMeshSceneNode(IAnimatedMesh* mesh, NxActor* actor, ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
And a few examples for the namespaces (open CAnimatedMeshSceneNode.cpp to change them):
Change:
Code: Select all
void CAnimatedMeshSceneNode::setCurrentFrame(f32 frame)
To:
Code: Select all
void CPhysXAnimatedMeshSceneNode::setCurrentFrame(f32 frame)
Another example about the namespace:
Change:
Code: Select all
f32 CAnimatedMeshSceneNode::getFrameNr() const
To:
Code: Select all
f32 CPhysXAnimatedMeshSceneNode::getFrameNr() const
Ok, back to the constructor:
Code: Select all
CPhysXAnimatedMeshSceneNode(IAnimatedMesh* mesh, NxActor* actor, ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
The "NxActor*" will keep a pointer to the AnimatedMesh object to do the physics simulation for it.
Add this function:
Code: Select all
IAnimatedMeshSceneNode* addPhysXAnimatedMeshSceneNode(IAnimatedMesh* mesh, NxActor* actor, ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0), const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))
{
if (!mesh)
return 0;
if (!parent)
parent = smgr->getRootSceneNode();
IAnimatedMeshSceneNode* node = new
CPhysXAnimatedMeshSceneNode(mesh, actor, parent, smgr, id, position, rotation, scale);
node->drop();
return node;
}
To your main class.
If you want to create a mesh with physics simulation capabilities, all you have to do is, call this function:
Code: Select all
addPhysXAnimatedMeshSceneNode(SomeMesh, SomeActor);
For example, to create a sphere:
Code: Select all
void CreateASphere()
{
f32 dim = 20.0f; // the typical dimension/radius is 20
NxActor *newActor; // pointer to newly created object
ISceneNode *newNode; // pointer to its scene node
vector3df position = camera->getPosition();
vector3df target = camera->getTarget();
core::vector3df irrDir = (target - position).normalize(); // get and normalize the direction
// create the physics model of the sphere
newActor = CreateSphere(position, dim);
newNode = addPhysXAnimatedMeshSceneNode(sphereMesh, newActor);
newNode->setMaterialFlag(video::EMF_LIGHTING, false);
newNode->setMaterialTexture(0, driver->getTexture("data/earth.bmp"));
newNode->setScale(core::vector3df(dim,dim,dim));
ApplyForceToActor(newActor, NxVec3(irrDir.X, irrDir.Y, irrDir.Z), gForceStrength);
}
The "void CreateASphere" function will call the function:
Code: Select all
NxActor* CreateSphere(const core::vector3df &pos, const f32 &radius)
Which will create the actual physics model of the sphere mesh.
This is how the complete function for the physics model looks like for the sphere object:
Code: Select all
NxActor* CreateSphere(const core::vector3df &pos, const f32 &radius)
{
// Add a single-shape actor to the scene
NxActorDesc actorDesc;
NxBodyDesc bodyDesc;
bodyDesc.angularDamping = 0.2f;
// The actor has one shape, a box, 1m on a side
NxSphereShapeDesc sphereDesc;
sphereDesc.radius = radius; // should be 0.5
actorDesc.shapes.pushBack(&sphereDesc);
actorDesc.body = &bodyDesc;
actorDesc.density = 1.0f;
actorDesc.globalPose.t = NxVec3(pos.X,pos.Y,pos.Z);
return gScene->createActor(actorDesc);
}
The project also covers on how to create a box mesh object and the physics model for it.
If you want to be able to load quake 3 maps, then this is how it's done:
Code: Select all
// load a quake 3 map
device->getFileSystem()->addZipFileArchive("data/nemesis.pk3");
IAnimatedMesh* q3levelmesh = smgr->getMesh("data/nemesis.bsp");
The nemesis map is from afecelis which i have included in the zip file (hope he doesn't mind).
The PhysX integration project contains another quake 3 map which you could use to play around with, also included in the zip file.
Change the name nemesis.pk3 to "physicstest.pk3" and "nemesis.bsp" to "physicstest.bsp" in order to use that map instead.
To create your own quake 3 map, you should follow this tutorial from afecelis:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=12100
I did not include every texture, lib and dll's in the zip file which I have used in the project.
You'll need to get the SDK from Ageia your self and the textures can be obtained from the "irrlicht\media" folder.
I have included 2 quake 3 maps and a sphere and cube mesh in the zip file.
None of this is mine, so you should check the license before using it for commercial purposes.
Ok, that's it. Feel free to ask your questions about the project.
The project link:
http://www.g0dsoft.com/yustme/Projects/Irrlicht&PhysX/