Google

OgrePhysX - a simple Ogre-PhysX binding

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.

Moderators: Moderators, OGRE Team

OgrePhysX - a simple Ogre-PhysX binding

Postby Caphalor » Sun Jan 10, 2010 12:10 am

I wrote a small PhysX wrapper and decided to share it, maybe somebody will find it useful. :)

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:
Image
Attachments
OgrePhysX_0.1.zip
(31.87 KiB) Downloaded 158 times
Last edited by Caphalor on Mon Jul 05, 2010 5:05 pm, edited 2 times in total.
Caphalor
Regular
 
Posts: 89
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany

Re: OgrePhysX - a simple Ogre-PhysX binding

Postby talklittle » Wed Jan 13, 2010 3:23 am

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.
talklittle
Newcomer
 
Posts: 1
Joined: Wed Jan 13, 2010 3:11 am

Re: OgrePhysX - a simple Ogre-PhysX binding

Postby neoranga974 » Thu Jul 01, 2010 6:29 am

Hi,

Interesting, nxOgre is definitely too complicated and incomplete.
neoranga974
Newcomer
 
Posts: 24
Joined: Tue Apr 28, 2009 3:17 pm

Re: OgrePhysX - a simple Ogre-PhysX binding

Postby avengre » Sun Jul 04, 2010 4:03 pm

Any chance this still exists? I get a bad url.
avengre
Regular
 
Posts: 54
Joined: Fri Nov 11, 2005 6:27 am
Location: Stillwater, Oklahoma

Re: OgrePhysX - a simple Ogre-PhysX binding

Postby buckED » Sun Jul 04, 2010 8:30 pm

The downlaod works just fine for me.

Thanks by the way, Caphalor.
"And they shall say: Never owed so many so much to so few."
User avatar
buckED
Regular
 
Posts: 125
Joined: Fri Feb 15, 2008 9:51 pm

Re: OgrePhysX - a simple Ogre-PhysX binding

Postby jacmoe » Sun Jul 04, 2010 8:32 pm

It's odd that the google code project gives a bad url - I guess he deleted it.
/* when invited to a free lunch, you should not complain about the quality of the caviar */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, Fueled by Passion.
Ogre AppWizards - project wizards for Visual Studio and Code::Blocks.
User avatar
jacmoe
OGRE Moderator
OGRE Moderator
 
Posts: 17492
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark

Re: OgrePhysX - a simple Ogre-PhysX binding

Postby Caphalor » Mon Jul 05, 2010 5:05 pm

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.
Caphalor
Regular
 
Posts: 89
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany


Return to Using OGRE in practice

Who is online

Users browsing this forum: NQ and 1 guest