Why another PhysX wrapper?
I have used NxOgre for more than a year and I think that it's a great library and that is has a great community.
But when I upgraded to the latest NxOgre version "Detritus", I noticed that NxOgre has become a bit too big for my purposes, mainly because of two reasons:
1. It is render independent (the core library doesn't require Ogre as dependency).
2. It tries to hide all PhysX classes from the user.
So I decided to write my own PhysX wrapper: "OgrePhysX" (very innovative isn't it?
It is a really small library and supports the following features:
- PhysX initialisation
- bind scene nodes or other "PointRenderable" implementations to actors
- mesh cooking
- shape parameter system
- raycasting
- contact report
I will probably implement more features in the future, but the main idea is to keep the wrapper small and simple.
The attached zip file contains the library and a small demo. You need PhysX 2.83 to use OgrePhysX.
Some example code:
Initialisation
- Code: Select all
#include "OgrePhysX.h"
class MyGame
{
...
OgrePhysX::Scene *mPhysXScene;
}
//...
OgrePhysX::World::getSingleton().init();
mRoot->addFrameListener(OgrePhysX::World::getSingleton().createFramelistener());
mPhysXScene = OgrePhysX::World::getSingleton().addScene("Main");
mPhysXScene->createActor(OgrePhysX::PlaneShape(Ogre::Vector3(0, 1, 0), -500)); //Ground
//...
Binding a node to an actor
- Code: Select all
Ogre::SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
Ogre::Entity *ent = mSceneMgr->createEntity("Cube", "cube.mesh");
node->attachObject(ent);
OgrePhysX::RenderedActor *actor = mPhysXScene->createRenderedActor(
new OgrePhysX::NodeRenderable(node), //Visual (derived from OgrePhysX::PointRenderable)
OgrePhysX::BoxShape(ent)); //PhysX collision modell
actor->setGlobalPosition(Ogre::Vector3(0, 20, 10));
Cooking physx meshes
- Code: Select all
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("cooked", "FileSystem"); //This is just an example which demonstrates that OgrePhysX uses the Ogre resource system to load the nxs mesh files.
//...
//We check whether we need to cook the mesh. If yes, we cook it to a file before loading.
Ogre::Entity *cook = mSceneMgr->createEntity("cook", "Levelmesh.mesh");
if (!OgrePhysX::Cooker::getSingleton().hasNxMesh("Levelmesh.mesh.nxs"))
OgrePhysX::Cooker::getSingleton().cookNxMeshToFile(cook->getMesh(), "cooked\\Levelmesh.mesh.nxs");
mPhysXScene->createActor(
OgrePhysX::CookedMeshShape("Levelmesh.mesh.nxs")); //This actor is implicit static, because only static actors can use mesh shapes
//Also possible: Runtime cooking without any files
mPhysXScene->createActor(
OgrePhysX::RTMeshShape(cook->getMesh()).scale(Ogre::Vector3(2,2,2)));
And finally, a screenshot:





