Page 1 of 4
OgrePhysX - added destruction + Demo
Posted: Sun Jan 10, 2010 12:10 am
by Caphalor
0.4 Update:
- - included w0rm's MeshSplitter Tool (with his permission
)
- added experimental destruction support (see this thread)
- added destruction demo
- fixed project file settings, see README
OgrePhysX 0.4 is only compatible with PhysX 3.1. I removed the old OgrePhysX versions.
I also added a binary Destruction Demo (Windows).
Download source archieve, including w0rms Mesh Splitter Tool.
Download binary destruction demo (Windows) and binary MeshSplitter Tool.
===============================================================================
I wrote a small PhysX wrapper and decided to share it, maybe somebody will find it useful.
Features:
- PhysX initialisation
- bind scene nodes or other "PointRenderable" implementations to actors
- mesh cooking
- raycasting
- destructible objects
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
3.1 to use OgrePhysX.
Some example code:
Initialisation
Code: Select all
#include "OgrePhysX.h"
class MyGame
{
...
Ogre::SceneManager *mOgreSceneMgr;
OgrePhysX::Scene *mPhysXScene;
}
//...
OgrePhysX::World::getSingleton().init();
OgrePhysX::World::getSingleton().setupOgreFramelistener();
mPhysXScene = OgrePhysX::World::getSingleton().addScene("Main", mOgreSceneMgr);
//...
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);
//create physical actor
OgrePhysX::Actor<PxRigidDynamic> actor = mPhysXScene->createRigidDynamic(ent, 50);
//setup binding
mPhysXScene->createRenderedActorBinding(actor, new OgrePhysX::NodeRenderable(node));
actor.setGlobalPosition(Ogre::Vector3(0, 20, 10));
Static actors / cooking PhysX meshes
Code: Select all
Ogre::Entity *ent = mSceneMgr->createEntity("Cube", "cube.mesh");
Actor<PxRigidStatic> actor = mPhysXScene->createRigidStatic(ent);
And finally, a screenshot:

Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Wed Jan 13, 2010 3:23 am
by talklittle
Wow- thanks very much for this. Your sample code makes it look extremely easy to use! I'd been wanting something like this for my next project, something in between a full physics library and the Minimal Ogre Collision lib (
http://www.ogre3d.org/forums/viewtopic.php?t=45267). So I will probably be incorporating this wrapper. Kudos.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Thu Jul 01, 2010 6:29 am
by neoranga974
Hi,
Interesting, nxOgre is definitely too complicated and incomplete.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Sun Jul 04, 2010 4:03 pm
by avengre
Any chance this still exists? I get a bad url.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Sun Jul 04, 2010 8:30 pm
by buckED
The downlaod works just fine for me.
Thanks by the way, Caphalor.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Sun Jul 04, 2010 8:32 pm
by jacmoe
It's odd that the google code project gives a bad url - I guess he deleted it.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Mon Jul 05, 2010 5:05 pm
by Caphalor
I merged the code into my
main project (but it's still a seperate dll), because there was little interest here. I don't know how up-to-date the code in the zip archive is, if you experience problems using it I can upload a new zip package. I didn't change much though.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Thu Nov 11, 2010 2:38 pm
by fruki
Any demos regarding ragdoll?

Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Tue Mar 01, 2011 12:09 am
by Caphalor
I received two PMs concerning OgrePhysX and I decided to post a small update.
OgrePhysX 0.2
- mesh cooker now merges redundant vertices (credit goes to Benedikt, who is not registered in this forum)
- convex mesh cooking
- some minor fixes
- Ogre 1.8 support
- Visual Studio 2010 project files
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Mon Mar 14, 2011 8:05 pm
by psx
What I actually found is PhysX does not need any wrapper.
PhysX interface is straightforward and easy to use.
Its like .. creating wrapper around OGRE.
You just dont need that.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Mon Mar 14, 2011 8:22 pm
by betajaen
I beg to differ.
PhysX is a harsh beast sometimes. There are plenty of things that need wrapping; cloth, soft bodies, cooking interface, debug visualization, etc.. I suppose they could be left out, but every time a person wants cloth; they'll have to write cloth binding code. I think it's best for everyone to use a standardised and well tested code than everyone rolling their own.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Tue Mar 22, 2011 12:01 am
by Nodrev
Very useful for lot of people I guess, nice and simple design, just a little remark, your source code really lacks of documentation, which could be really useful to PhysX beginners (which it's not my case

) to understand how it works internally.
Its like .. creating wrapper around OGRE.
You just dont need that.
Ha ha, so fun, it makes me laugh a lot... before I start to cry! If only beginners do not fall in this trap all the times... It would save me lot of time in my actual work.
Trust me, a Ogre centered framework (I mean, a framework with Ogre's plugins for physics, sound, etc inside Ogre) is not the best way to do, when your project increase, you lost lot of time to make everything work together... but I'm a bit off-subject...
Anyway, this kind of little lib is perfect for a small project!
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Sun Mar 27, 2011 3:19 pm
by psx
There are plenty of things that need wrapping; cloth, soft bodies, cooking interface, debug visualization, etc..
Hmm.. You're right.
I'm in the middle of a project now, which includes PhysX.
I think, I can get away with some
utility functions.
But we'll see. Maybe I will end with wrapping.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Mon Mar 28, 2011 7:16 pm
by Caphalor
Very useful for lot of people I guess, nice and simple design, just a little remark, your source code really lacks of documentation, which could be really useful to PhysX beginners
I am sorry, but I wrote OgrePhysX mainly for myself and I don't have time to write a documentation. If you want support and documentation use NxOgre.
What I actually found is PhysX does not need any wrapper.
I think this is true to some degree. For example joints and the character controller are not wrapped in OgrePhysX, because I use them directly in my engine. But as betajaen said there are things that everybody needs who uses Ogre together with PhysX.
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Fri Apr 22, 2011 9:48 am
by Roman
Excellent work! I will try it out. Does it also run or can it be used/compiled on Linux with the old available PhysX version (v2.8.1 AFAIK) and the new PhysX release for Mac OS X?
Re: OgrePhysX - a simple Ogre-PhysX binding
Posted: Tue Aug 30, 2011 6:09 pm
by Campi
Hello
I have the same question that Roman. Is possible to use this wrapper in linux? and which version of PhysiX need to be used?
Anyone ??
PhysX 3
Posted: Wed Sep 21, 2011 9:47 pm
by Caphalor
Sorry that I did not answer, I haven't read the forums for a while.
I use Windows and Visual Studio, so all I can say is: Download the PhysX Linux SDK and try it out.
I recently ported OgrePhysX to PhysX 3 and rewrote a lot of code. It is even less code now, because I removed some things like the contact listener.
Some guidelines/Notes:
- You create Ogre and PhysX objects (nodes, entities, actors...), and you destroy them. OgrePhysX only synchronises Ogre with PhysX.
- OgrePhysX has factory methods for some PhysX objects and an Actor class, but this is only syntactic sugar. You can also create the PhysX actors manually if you want.
- There is a class "Ragdoll", but it only synchronises bone actors with bones and does not create actors or joints. There is no out-of-the-box ragdoll support yet.
- The zip package only contains a project file for Visual Studio 2010 (it works for VS 11 developer preview too) and in addition to that OgrePhysX uses C++0x keywords (auto for iterators and nullptr).
- In order to compile you probably have to change the include directories, I recommend editing PhysXIncludes.props using a text editor or the Visual Studio Property manager.
Now some code!
Initialisation
Code: Select all
OgrePhysX::World::getSingleton().init();
mPhysXScene = OgrePhysX::World::getSingleton().addScene("Main"); //you can also pass a PxSceneDesc here
Mainloop
Using a frame listener:
Code: Select all
OgrePhysX::World::getSingleton().setupOgreFramelistener();
Using a custom main loop:
Code: Select all
OgrePhysX::World::getSingleton().simulate(time);
OgrePhysX::World::getSingleton().syncRenderables();
Ogre::Root::getSingleton().renderOneFrame();
Inside simulate, OgrePhysX uses a fixed timestep to advance the simulation, so when time is higher than the timestep multiple steps are performed. Using a SimulationListener (see Scene::setSimulationListener) you can get notifications when OgrePhysX invokes PhysX each timestep (onSimulate is called between PxScene::simulate and PxScene::fetchResults, so you can do stuff while PhysX is working).
I use seperate threads for physics and rendering. Inside the physics loop I call simulate and inside the rendering loop I call syncRenderables.
Dynamic Actors
Code: Select all
OgrePhysX::Actor<PxRigidDynamic> actor =
mPhysXScene->createRigidDynamic((OgrePhysX::Geometry::convexMeshGeometry(entity->getMesh())), myDensity);
OgrePhysX::PointRenderable *renderable =
new OgrePhysX::NodeRenderable(myOgreNode); //any class implementing PointRenderable is suitable
OgrePhysX::RenderedActorBinding *renderBinding =
Main::Instance().GetPhysXScene()->createRenderedActorBinding(actor, renderable);
//Later: Destruction. Make sure to delete the renderable binding first.
mPhysXScene->destroyRenderedActorBinding(renderBinding);
delete renderable;
mPhysXScene->removeActor(actor);
Static Actors
Code: Select all
OgrePhysX::Actor<PxRigidStatic> actor =
mPhysXScene->createRigidStatic(entity->getMesh());
//Later
mPhysXScene->removeActor(actor);
Of course this is only a quick overview and not a documentation.
Please tell me if you find any bugs, I didn't test everything (for example I don't use NodeRenderables or the FrameListener).
Feel free to extract parts of the code if you don't want to use the full library. I hope it will be useful!
Edit: This only works for PhysX 3.0. For the current PhysX 3.1 see the first post.
Re: OgrePhysX - now for PhysX 3
Posted: Wed Sep 21, 2011 9:57 pm
by betajaen
Awesome!
I'm glad there is a PhysX 3 wrapper for Ogre now.
Re: OgrePhysX - now for PhysX 3
Posted: Wed Sep 21, 2011 11:45 pm
by Mind Calamity
<un-quote-ified>
Someone may upgrade NxOgre eventually
That someone may or may not be you
Converting/Updating code is not as hard as writing code from the ground up, so it wouldn't be a tough task for most people here on the forums.
Re: OgrePhysX - now for PhysX 3
Posted: Fri Oct 14, 2011 8:14 pm
by Sapd
Is this also compatible for PhysX 3.1?
Re: OgrePhysX - now for PhysX 3
Posted: Fri Oct 14, 2011 10:43 pm
by Mind Calamity
@Sapd:
Well I read in the release notes of PhysX 3.1 that some API changes have been made, and files have been renamed, so I think you might need to do a bit of re-factoring to get it working.
Personally I haven't used OgrePhysX, as I use NxOgre myself, but it shouldn't be that hard to update it to work with the new version of PhysX, as the code of OgrePhysX is not that big it should be a piece of cake if you have minimal programming knowledge (or maybe experience counts more in this case).
<Slightly off-topic>On the NxOgre side, a mountain of re-factoring would need to be done and probably some code changes in order to get it working with PhysX 3.x, it shouldn't be much of a problem, but would require a good amount of time to get it done. </SO-T>
Re: OgrePhysX - now for PhysX 3
Posted: Sat Oct 15, 2011 3:21 pm
by Caphalor
I ported OgrePhysX to PhysX 3.1 (this does not work with 3.0).
If you want to use it you probably have to build the physx extensions in debug mode because of this problem:
http://forum-archive.developer.nvidia.c ... topic=6835
Edit: The latest version is 0.4, see first post.
Re: OgrePhysX - now for PhysX 3
Posted: Fri Oct 21, 2011 11:03 pm
by shadoslayer
When i tried to compile the project, I got so many ambiguities that the compiler exited early. they were all between physx classes and ogrephysx classes by the same names. relatively new to C++, so how do I keep this from happening?
Re: OgrePhysX - now for PhysX 3
Posted: Sat Oct 22, 2011 3:25 am
by shadoslayer
I gave up trying to use the 3.1 wrapper. how would i go about 'installing' the 3.0 wrapper sdk? i tried adding it to my solution. when I try to compile, i get a bunch of confusing errors:
Code: Select all
3>Scene.obj : error LNK2019: unresolved external symbol "public: void __thiscall OgrePhysX::World::syncRenderables(void)" (?syncRenderables@World@OgrePhysX@@QAEXXZ) referenced in function "public: virtual bool __thiscall OgrePhysX::World::OgreFrameListener::frameStarted(struct Ogre::FrameEvent const &)" (?frameStarted@OgreFrameListener@World@OgrePhysX@@UAE_NABUFrameEvent@Ogre@@@Z)
3>Scene.obj : error LNK2019: unresolved external symbol "public: void __thiscall OgrePhysX::World::simulate(float)" (?simulate@World@OgrePhysX@@QAEXM@Z) referenced in function "public: virtual bool __thiscall OgrePhysX::World::OgreFrameListener::frameStarted(struct Ogre::FrameEvent const &)" (?frameStarted@OgreFrameListener@World@OgrePhysX@@UAE_NABUFrameEvent@Ogre@@@Z)
3>Scene.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall OgrePhysX::NodeRenderable::setTransform(class Ogre::Vector3 &,class Ogre::Quaternion &)" (?setTransform@NodeRenderable@OgrePhysX@@UAEXAAVVector3@Ogre@@AAVQuaternion@4@@Z)
3>Scene.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall OgrePhysX::NodeRenderable::~NodeRenderable(void)" (??1NodeRenderable@OgrePhysX@@UAE@XZ) referenced in function "public: virtual void * __thiscall OgrePhysX::NodeRenderable::`scalar deleting destructor'(unsigned int)" (??_GNodeRenderable@OgrePhysX@@UAEPAXI@Z)
3>Scene.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall OgrePhysX::Ragdoll::sync(void)" (?sync@Ragdoll@OgrePhysX@@UAEXXZ)
3>Scene.obj : error LNK2019: unresolved external symbol "private: virtual __thiscall OgrePhysX::Ragdoll::~Ragdoll(void)" (??1Ragdoll@OgrePhysX@@EAE@XZ) referenced in function "private: virtual void * __thiscall OgrePhysX::Ragdoll::`scalar deleting destructor'(unsigned int)" (??_GRagdoll@OgrePhysX@@EAEPAXI@Z)
on top of this, when I tried compiling the wrapper on it's own, it seems to get to the end, and it generates .dll's and .lib's, but it gives me the following errors:
Code: Select all
1> OgrePhysX.vcxproj -> (Path to OgrePhysx)\..\..\lib\OgrePhysX_d.dll
1> The system cannot find the path specified.
1> 0 file(s) copied.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: The command "copy ..\..\lib\OgrePhysX_d.dll ..\..\bin\
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: :VCEnd" exited with code 1.
Re: OgrePhysX - now for PhysX 3
Posted: Sat Oct 22, 2011 2:13 pm
by Caphalor
I am sorry that you experience so many problems!
You can fix the second problem easily: Just remove the post build event.
Project Properties -> Build Events -> Post-Build Step
When linking OgrePhysX to your project, did you add OgrePhysX.lib (Release) and OgrePhysX_d.lib (Debug) as input librarys in your project settings? You can also add the OgrePhysX code directly to your project (it isn't very much) if you want.
Are you sure that you compiled the 3.1 wrapper against PhysX 3.1? It does not work with 3.0.