From: <me...@us...> - 2009-05-18 17:21:17
|
Revision: 2691 http://ogreaddons.svn.sourceforge.net/ogreaddons/?rev=2691&view=rev Author: melven2 Date: 2009-05-18 17:21:05 +0000 (Mon, 18 May 2009) Log Message: ----------- interface breaking changes! -use sharedptrs for collisions -use Ogre::Any for userdata values -set position and orientation of a node attached to a body correctly, when the the node derives position/orientation from its parent -make OgreNewt export the (internally used) MovableText-class -updated the demos -create the correct OgreNewt collisionprimitive type when importing collisions and some other minor changes Modified Paths: -------------- branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonApplication.cpp branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonFrameListener.cpp branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonApplication.cpp branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonFrameListener.cpp branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorBelt.cpp branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorMatCallback.cpp branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonApplication.cpp branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonFrameListener.cpp branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonApplication.cpp branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonFrameListener.cpp branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/SimpleVehicle.cpp branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonApplication.cpp branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonFrameListener.cpp branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonApplication.cpp branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonFrameListener.cpp branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonApplication.cpp branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonFrameListener.cpp branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.cpp branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.h branches/ogrenewt/newton20/inc/OgreNewt.h branches/ogrenewt/newton20/inc/OgreNewt_BasicFrameListener.h branches/ogrenewt/newton20/inc/OgreNewt_Body.h branches/ogrenewt/newton20/inc/OgreNewt_BodyInAABBIterator.h branches/ogrenewt/newton20/inc/OgreNewt_Collision.h branches/ogrenewt/newton20/inc/OgreNewt_CollisionPrimitives.h branches/ogrenewt/newton20/inc/OgreNewt_CollisionSerializer.h branches/ogrenewt/newton20/inc/OgreNewt_ContactCallback.h branches/ogrenewt/newton20/inc/OgreNewt_ContactJoint.h branches/ogrenewt/newton20/inc/OgreNewt_Debugger.h branches/ogrenewt/newton20/inc/OgreNewt_Joint.h branches/ogrenewt/newton20/inc/OgreNewt_MaterialID.h branches/ogrenewt/newton20/inc/OgreNewt_PlayerController.h branches/ogrenewt/newton20/inc/OgreNewt_Prerequisites.h branches/ogrenewt/newton20/inc/OgreNewt_RayCast.h branches/ogrenewt/newton20/inc/OgreNewt_Tools.h branches/ogrenewt/newton20/inc/OgreNewt_Vehicle.h branches/ogrenewt/newton20/inc/OgreNewt_World.h branches/ogrenewt/newton20/src/OgreNewt_Body.cpp branches/ogrenewt/newton20/src/OgreNewt_Collision.cpp branches/ogrenewt/newton20/src/OgreNewt_CollisionPrimitives.cpp branches/ogrenewt/newton20/src/OgreNewt_CollisionSerializer.cpp branches/ogrenewt/newton20/src/OgreNewt_Debugger.cpp branches/ogrenewt/newton20/src/OgreNewt_PlayerController.cpp branches/ogrenewt/newton20/src/OgreNewt_RayCast.cpp branches/ogrenewt/newton20/src/OgreNewt_Tools.cpp Modified: branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonApplication.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonApplication.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -55,13 +55,15 @@ // here's where we make a collision shape for the physics. note that we use the same size as // above. - OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Cylinder(m_World, 2.5, 5); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder(m_World, 2.5, 5)); // now we make a new rigid body based on this collision shape. OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR // we`re done with the collision shape, we can delete it now. delete col; +#endif // now we "attach" the rigid body to the scene node that holds the visual object, and set it's // original position and orientation. all rigid bodies default to mass=0 (static, immobile), so Modified: branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonFrameListener.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonFrameListener.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -80,17 +80,20 @@ //ent->setNormaliseNormals(true); // again, make the collision shape. - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Cylinder(m_World, 1, 1); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder(m_World, 1, 1)); // then make the rigid body. OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR //no longer need the collision shape object delete col; +#endif body->setMassMatrix( 10.0, 10.0*inertia ); + body->setCenterOfMass(offset); // attach to the scene node. body->attachNode( node ); Modified: branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonApplication.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonApplication.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -74,8 +74,10 @@ // SceneNodes (parsing all children), and add collision for all meshes in the tree. OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* stat_col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser( m_World ); stat_col->parseScene( floornode, true ); - OgreNewt::Body* bod = new OgreNewt::Body( m_World, stat_col ); + OgreNewt::Body* bod = new OgreNewt::Body( m_World, OgreNewt::CollisionPtr(stat_col) ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete stat_col; +#endif bod->attachNode( floornode ); bod->setPositionOrientation( Ogre::Vector3(0.0,-20.0,0.0), Ogre::Quaternion::IDENTITY ); @@ -160,7 +162,7 @@ box1node->setScale( size ); // box1->setNormaliseNormals(true); - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Box( m_World, size ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); @@ -171,10 +173,13 @@ Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif bod->attachNode( box1node ); bod->setMassMatrix( mass, mass*inertia ); + bod->setCenterOfMass(offset); bod->setStandardForceCallback(); box1->setMaterialName( "Simple/BumpyMetal" ); Modified: branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonFrameListener.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonFrameListener.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -74,12 +74,17 @@ ent->setMaterialName( "Simple/dirt01" ); // ent->setNormaliseNormals(true); - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) )); OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR + delete col; +#endif + Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); body->setMassMatrix( 10.0, 10.0*inertia ); + body->setCenterOfMass(offset); body->attachNode( node ); body->setStandardForceCallback(); body->setPositionOrientation( pos, camorient ); Modified: branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorBelt.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorBelt.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorBelt.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -16,7 +16,7 @@ { // build a conveyor belt object. first create the basic visual object. mSceneMgr = mgr; - mDir = dir; + mDir = dir.normalisedCopy(); mSpeed = speed; mNode = mgr->getRootSceneNode()->createChildSceneNode(); @@ -27,15 +27,21 @@ mNode->setScale( size ); // create the collision object for the conveyor belt. - OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box( world, size ); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size )); mBody = new OgreNewt::Body( world, col, conveyorType ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif mBody->setMassMatrix( 0.0, Ogre::Vector3(0,0,0) ); mBody->attachNode( mNode ); mBody->setMaterialGroupID( conveyorMat ); +#ifndef OGRENEWT_NO_OGRE_ANY + mBody->setUserData( Ogre::Any(this) ); +#else mBody->setUserData( this ); +#endif mBody->setPositionOrientation( pos, orient ); mNode->setPosition( pos ); Modified: branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorMatCallback.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorMatCallback.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorMatCallback.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -29,13 +29,21 @@ if (body0->getType() == mConveyorID) { +#ifndef OGRENEWT_NO_OGRE_ANY + belt = Ogre::any_cast<ConveyorBelt*>(body0->getUserData()); +#else belt = (ConveyorBelt*)body0->getUserData(); +#endif object = body1; } if (body1->getType() == mConveyorID) { +#ifndef OGRENEWT_NO_OGRE_ANY + belt = Ogre::any_cast<ConveyorBelt*>(body1->getUserData()); +#else belt = (ConveyorBelt*)body1->getUserData(); +#endif object = body0; } @@ -47,8 +55,15 @@ for( OgreNewt::Contact contact = contactJoint.getFirstContact(); contact; contact = contact.getNext() ) { contact.rotateTangentDirections( thedir ); - Ogre::Vector3 result_accel = (thedir * belt->getSpeed()) - object->getVelocity(); - contact.setTangentAcceleration( result_accel.length(), 0 ); + Ogre::Vector3 contactPos, contactNorm; + contact.getPositionAndNormal(contactPos, contactNorm); + Ogre::Vector3 objectPos; + Ogre::Quaternion objectOri; + object->getPositionOrientation(objectPos, objectOri); + Ogre::Vector3 objectContactPointVel = object->getVelocity() + (contactPos - objectPos)*object->getOmega(); + Ogre::Real result_accel = belt->getSpeed() - thedir.dotProduct(objectContactPointVel); + result_accel *= 10; // looks nicer + contact.setTangentAcceleration( result_accel, 0 ); } } } Modified: branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonApplication.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonApplication.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -79,9 +79,13 @@ floor->setCastShadows( false ); //Ogre::Vector3 siz(100.0, 10.0, 100.0); - OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true ); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR + delete col; +#endif + //floornode->setScale( siz ); bod->attachNode( floornode ); bod->setPositionOrientation( Ogre::Vector3(0.0,-10.0,0.0), Ogre::Quaternion::IDENTITY ); @@ -109,7 +113,9 @@ mMatPairDefaultConveyor = new OgreNewt::MaterialPair( m_World, mMatDefault, mMatConveyor ); mConveyorCallback = new ConveyorMatCallback( BT_CONVEYOR ); mMatPairDefaultConveyor->setContactCallback( mConveyorCallback ); - mMatPairDefaultConveyor->setDefaultFriction( 1.5, 1.4 ); + mMatPairDefaultConveyor->setDefaultSoftness( 0.8 ); + mMatPairDefaultConveyor->setDefaultElasticity( 0.05 ); + mMatPairDefaultConveyor->setDefaultFriction( 0.9, 0.8 ); } Modified: branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonFrameListener.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonFrameListener.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -68,14 +68,18 @@ ent->setMaterialName( "Simple/BumpyMetal" ); - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Box( m_World, size ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); + +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif body->setMassMatrix( mass, mass*inertia ); + body->setCenterOfMass(offset); body->attachNode( node ); body->setStandardForceCallback(); body->setPositionOrientation( Ogre::Vector3(-5,8,0), Ogre::Quaternion::IDENTITY ); Modified: branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonApplication.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonApplication.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -75,9 +75,11 @@ //Ogre::Vector3 siz(100.0, 10.0, 100.0); - OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true ); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif //floornode->setScale( siz ); bod->attachNode( floornode ); @@ -174,7 +176,7 @@ box1node->attachObject( box1 ); box1node->setScale( size ); - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Box( m_World, size ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); @@ -184,10 +186,13 @@ Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif bod->attachNode( box1node ); bod->setMassMatrix( mass, mass*inertia ); + bod->setCenterOfMass(offset); bod->setStandardForceCallback(); box1->setMaterialName( "Simple/BumpyMetal" ); Modified: branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonFrameListener.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonFrameListener.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -114,7 +114,12 @@ Ogre::Vector3 localpt = bodorient.Inverse() * (globalpt - bodpos); // now we need to save this point to apply the spring force, I'm using the userData of the bodies in this example. + // (where is it used? probably not needed here...) +#ifndef OGRENEWT_NO_OGRE_ANY + info.mBody->setUserData( Ogre::Any(this) ); +#else info.mBody->setUserData( this ); +#endif // now change the force callback from the standard one to the one that applies the spring (drag) force. // this is an example of binding a callback to a member of a specific class. in previous versions of OgreNewt you were Modified: branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/SimpleVehicle.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/SimpleVehicle.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/SimpleVehicle.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -172,6 +172,7 @@ bod->attachNode( box1node ); bod->setMassMatrix( mass, mass*inertia ); + bod->setCenterOfMass(offset); bod->setStandardForceCallback(); box1->setMaterialName( "Simple/BumpyMetal" ); Modified: branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonApplication.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonApplication.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -75,9 +75,11 @@ //Ogre::Vector3 siz(100.0, 10.0, 100.0); - OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true ); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif //floornode->setScale( siz ); bod->attachNode( floornode ); @@ -191,7 +193,7 @@ box1node->attachObject( box1 ); box1node->setScale( size ); - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Box( m_World, size ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); @@ -200,11 +202,13 @@ // calculate the inertia based on box formula and mass Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); - +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif bod->attachNode( box1node ); bod->setMassMatrix( mass, mass*inertia ); + bod->setCenterOfMass(offset); bod->setStandardForceCallback(); box1->setMaterialName( "Simple/BumpyMetal" ); Modified: branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonFrameListener.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonFrameListener.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -114,8 +114,14 @@ Ogre::Vector3 localpt = bodorient.Inverse() * (globalpt - bodpos); // now we need to save this point to apply the spring force, I'm using the userData of the bodies in this example. + // (where is it used? probably not needed here...) +#ifndef OGRENEWT_NO_OGRE_ANY + info.mBody->setUserData( Ogre::Any(this) ); +#else info.mBody->setUserData( this ); +#endif + // now change the force callback from the standard one to the one that applies the spring (drag) force. info.mBody->setCustomForceAndTorqueCallback<OgreNewtonFrameListener>( &OgreNewtonFrameListener::dragCallback, this ); Modified: branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonApplication.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonApplication.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -75,8 +75,10 @@ // SceneNodes (parsing all children), and add collision for all meshes in the tree. OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* stat_col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser( m_World ); stat_col->parseScene( floornode, true ); - OgreNewt::Body* bod = new OgreNewt::Body( m_World, stat_col ); + OgreNewt::Body* bod = new OgreNewt::Body( m_World, OgreNewt::CollisionPtr(stat_col) ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete stat_col; +#endif bod->attachNode( floornode ); bod->setPositionOrientation( Ogre::Vector3(0.0,-20.0,0.0), Ogre::Quaternion::IDENTITY ); @@ -160,7 +162,7 @@ box1node->attachObject( box1 ); box1node->setScale( size ); - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Box( m_World, size ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); @@ -170,11 +172,13 @@ // calculate the inertia based on box formula and mass Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); - +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif bod->attachNode( box1node ); bod->setMassMatrix( mass, mass*inertia ); + bod->setCenterOfMass(offset); bod->setStandardForceCallback(); box1->setMaterialName( "Simple/BumpyMetal" ); Modified: branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonFrameListener.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonFrameListener.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -73,18 +73,23 @@ ent->setMaterialName( "Simple/dirt01" ); - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) )); OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); body->setMassMatrix( 10.0, 10.0*inertia ); + body->setCenterOfMass(offset); body->attachNode( node ); body->setStandardForceCallback(); body->setPositionOrientation( pos, camorient ); body->setVelocity( (dir * 50.0) ); timer = 0.2; + +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR + delete col; +#endif } } Modified: branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonApplication.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonApplication.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -49,9 +49,11 @@ floor->setCastShadows( false ); //Ogre::Vector3 siz(100.0, 10.0, 100.0); - OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true ); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif //floornode->setScale( siz ); bod->attachNode( floornode ); @@ -97,7 +99,7 @@ box1node->attachObject( box1 ); box1node->setScale( size ); - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Box( m_World, size ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); @@ -108,10 +110,13 @@ Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; +#endif bod->attachNode( box1node ); bod->setMassMatrix( mass, mass*inertia ); + bod->setCenterOfMass(offset); bod->setStandardForceCallback(); box1->setMaterialName( "Simple/BumpyMetal" ); Modified: branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonFrameListener.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonFrameListener.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -87,18 +87,23 @@ ent->setMaterialName( "Simple/dirt01" ); - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) )); OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); body->setMassMatrix( 10.0, 10.0*inertia ); + body->setCenterOfMass(offset); body->attachNode( node ); body->setStandardForceCallback(); body->setPositionOrientation( pos, camorient ); body->setVelocity( (dir * 50.0) ); timer = 0.2; + +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR + delete col; +#endif } } timer -= evt.timeSinceLastFrame; Modified: branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.cpp 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.cpp 2009-05-18 17:21:05 UTC (rev 2691) @@ -8,7 +8,11 @@ mParent = parent; mOgreBone = ogreBone; - OgreNewt::ConvexCollision* col = NULL; +#ifndef OGRENEWT_NO_COLLISION_SHAREDPTR + OgreNewt::ConvexCollisionPtr col; +#else + OgreNewt::ConvexCollisionPtr col = NULL; +#endif // in the case of the cylindrical primitives, they need to be rotated to align the main axis with the direction vector. Ogre::Quaternion orient = Ogre::Quaternion::IDENTITY; @@ -32,23 +36,23 @@ switch (shape) { case RagDoll::RagBone::BS_BOX: - col = new OgreNewt::CollisionPrimitives::Box( world, size ); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size )); break; case RagDoll::RagBone::BS_CAPSULE: - col = new OgreNewt::CollisionPrimitives::Capsule( world, size.y, size.x, orient, pos ); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Capsule( world, size.y, size.x, orient, pos )); break; case RagDoll::RagBone::BS_CONE: - col = new OgreNewt::CollisionPrimitives::Cone( world, size.y, size.x, orient, pos ); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cone( world, size.y, size.x, orient, pos )); break; case RagDoll::RagBone::BS_CYLINDER: - col = new OgreNewt::CollisionPrimitives::Cylinder( world, size.y, size.x, orient, pos ); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder( world, size.y, size.x, orient, pos )); break; case RagDoll::RagBone::BS_ELLIPSOID: - col = new OgreNewt::CollisionPrimitives::Ellipsoid( world, size ); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid( world, size )); break; case RagDoll::RagBone::BS_CONVEXHULL: @@ -56,24 +60,31 @@ break; default: - col = new OgreNewt::CollisionPrimitives::Box( world, size ); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size )); break; } mBody = new OgreNewt::Body( world, col ); - mBody->setUserData( this ); +#ifndef OGRENEWT_NO_OGRE_ANY + mBody->setUserData( Ogre::Any(this) ); +#else + mBody->setUserData( this ); +#endif mBody->setStandardForceCallback(); Ogre::Vector3 inertia; - Ogre::Vector3 com; - col->calculateInertialMatrix( inertia, com ); + Ogre::Vector3 offset; + col->calculateInertialMatrix( inertia, offset ); mBody->setMassMatrix( mass, inertia * mass ); - mBody->setCenterOfMass( com ); + mBody->setCenterOfMass( offset ); mBody->setCustomTransformCallback( RagDoll::_placementCallback ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR + delete col; +#endif } @@ -86,7 +97,11 @@ void RagDoll::RagBone::_hingeCallback( OgreNewt::BasicJoints::Hinge* me ) { +#ifndef OGRENEWT_NO_OGRE_ANY + RagDoll::RagBone* bone = Ogre::any_cast<RagDoll::RagBone*>(me->getUserData()); +#else RagDoll::RagBone* bone = (RagDoll::RagBone*)me->getUserData(); +#endif Ogre::Degree angle = me->getJointAngle(); Ogre::Degree lim1( bone->getLimit1() ); @@ -107,7 +122,7 @@ } -OgreNewt::ConvexCollision* RagDoll::RagBone::_makeConvexHull( OgreNewt::World* world, Ogre::MeshPtr mesh, Ogre::Real minWeight ) +OgreNewt::ConvexCollisionPtr RagDoll::RagBone::_makeConvexHull( OgreNewt::World* world, Ogre::MeshPtr mesh, Ogre::Real minWeight ) { std::vector< Ogre::Vector3 > vertexVector; @@ -197,7 +212,7 @@ } ////////////////////////////////////////////////////////////////////////////////// - OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::ConvexHull( world, verts, numVerts ); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::ConvexHull( world, verts, numVerts )); delete []verts; @@ -390,7 +405,11 @@ case RagDoll::JT_HINGE: joint = new OgreNewt::BasicJoints::Hinge( child->getBody()->getWorld(), child->getBody(), parent->getBody(), pos, pin ); ((OgreNewt::BasicJoints::Hinge*)joint)->setCallback( RagBone::_hingeCallback ); - joint->setUserData( child ); +#ifndef OGRENEWT_NO_OGRE_ANY + joint->setUserData( Ogre::Any(child) ); +#else + joint->setUserData( child ); +#endif child->setLimits( limit1, limit2 ); break; } @@ -400,7 +419,11 @@ void RagDoll::_placementCallback( OgreNewt::Body* me, const Ogre::Quaternion& orient, const Ogre::Vector3& pos, int threadindex ) { +#ifndef OGRENEWT_NO_OGRE_ANY + RagDoll::RagBone* bone = Ogre::any_cast<RagDoll::RagBone*>(me->getUserData()); +#else RagDoll::RagBone* bone = (RagDoll::RagBone*)me->getUserData(); +#endif RagDoll* doll = bone->getDoll(); // is this the root bone? Modified: branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.h =================================================================== --- branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -63,7 +63,7 @@ private: - OgreNewt::ConvexCollision* _makeConvexHull( OgreNewt::World* world, Ogre::MeshPtr mesh, Ogre::Real minWeight ); + OgreNewt::ConvexCollisionPtr _makeConvexHull( OgreNewt::World* world, Ogre::MeshPtr mesh, Ogre::Real minWeight ); // pointer to the doll to which this bone belongs. RagDoll* mDoll; Modified: branches/ogrenewt/newton20/inc/OgreNewt.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -64,13 +64,14 @@ - joints - collision-serializer - treecollision raycastcallback - - shared pointers for collisions (atm CollisionPtr := Collision*, but should be Ogre::SharedPtr<Collision>, but there was some problem...) \section new New in this version New in this version - this version uses cmake > 2.6.2! + - shared pointers for collisions, if you don't want to use shared pointers define OGRENEWT_NO_COLLISION_SHAREDPTR + - uses Ogre::Any instead of void* as userdata, if you want to use void* define OGRENEWT_NO_OGRE_ANY - several interface-breaking changes: - the ContactCallback passes a ContactJoint as argument that can be used to iterate through all contacts (the callback is not called for each contact any more, but for each pair of colliding bodies!) Modified: branches/ogrenewt/newton20/inc/OgreNewt_BasicFrameListener.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_BasicFrameListener.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_BasicFrameListener.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -29,9 +29,7 @@ namespace OgreNewt { -class World; - //! simple frame listener to update the physics. /*! updates the Newton World at the specified rate, with time-slicing, and Modified: branches/ogrenewt/newton20/inc/OgreNewt_Body.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_Body.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_Body.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -20,17 +20,12 @@ #include "OgreNewt_Prerequisites.h" #include "OgreNewt_MaterialID.h" #include "OgreNewt_Collision.h" -#include <boost/function.hpp> -#include <boost/bind.hpp> // OgreNewt namespace. all functions and classes use this namespace. namespace OgreNewt { -class World; -class MaterialID; - /* CLASS DEFINITION: @@ -82,7 +77,7 @@ \param col pointer to an OgreNewt::Collision object that represents the shape of the rigid body. \param bodytype simple integer value used to identify the type of rigid body, useful for determining bodies in callbacks. */ - Body( const World* W, const OgreNewt::Collision* col, int bodytype = 0 ); + Body( const World* W, const OgreNewt::CollisionPtr& col, int bodytype = 0 ); //! destructor ~Body(); @@ -92,10 +87,18 @@ you can use this to store a pointer to a parent class, etc. then inside one of the many callbacks, you can get the pointer using this "userData" system. */ +#ifndef OGRENEWT_NO_OGRE_ANY + void setUserData( const Ogre::Any& data ) { m_userdata = data; } +#else void setUserData( void* data ) { m_userdata = data; } +#endif //! retrieve pointer to previously set user data. +#ifndef OGRENEWT_NO_OGRE_ANY + const Ogre::Any& getUserData() const { return m_userdata; } +#else void* getUserData() const { return m_userdata; } +#endif //! get a pointer to the NewtonBody object /*! @@ -260,7 +263,7 @@ This can be used to change the collision shape of a body mid-simulation. for example making the collision for a character smaller when crouching, etc. \param col pointer to the new OgreNewt::Collision shape. */ - void setCollision( const OgreNewt::Collision* col ); + void setCollision( const OgreNewt::CollisionPtr& col ); //! set whether the body should "sleep" when equilibruim is reached. /*! @@ -275,7 +278,7 @@ //void setFreezeThreshold( Ogre::Real speed, Ogre::Real omega, int framecount ) { NewtonBodySetFreezeTreshold( m_body, (float)speed, (float)omega, framecount ); } //! get a pointer to the OgreNewt::Collision for this body - const OgreNewt::Collision* getCollision() const; + const OgreNewt::CollisionPtr& getCollision() const; //! get a pointer to the Material assigned to this body. const OgreNewt::MaterialID* getMaterialGroupID() const; @@ -398,7 +401,7 @@ /*! * usually it is also possible to get this via: body->getCollision()->getCollisionPrimitiveType() */ - CollisionPrimitive getCollisionPrimitiveType() const { return Collision::getCollisionPrimitiveType(getNewtonCollision()); } + CollisionPrimitiveType getCollisionPrimitiveType() const { return Collision::getCollisionPrimitiveType(getNewtonCollision()); } //! Returns the Newton Collision for this Body /*! @@ -408,20 +411,23 @@ protected: - NewtonBody* m_body; - const Collision* m_collision; - const MaterialID* m_matid; - const World* m_world; + NewtonBody* m_body; + OgreNewt::CollisionPtr m_collision; + const MaterialID* m_matid; + const World* m_world; - - void* m_userdata; +#ifndef OGRENEWT_NO_OGRE_ANY + Ogre::Any m_userdata; +#else + void* m_userdata; +#endif - int m_type; - Ogre::Node* m_node; + int m_type; + Ogre::Node* m_node; - ForceCallback m_forcecallback; - TransformCallback m_transformcallback; - buoyancyPlaneCallback m_buoyancycallback; + ForceCallback m_forcecallback; + TransformCallback m_transformcallback; + buoyancyPlaneCallback m_buoyancycallback; private: Modified: branches/ogrenewt/newton20/inc/OgreNewt_BodyInAABBIterator.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_BodyInAABBIterator.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_BodyInAABBIterator.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -15,17 +15,12 @@ #include "OgreNewt_Prerequisites.h" -#include <boost/function.hpp> -#include <boost/bind.hpp> // OgreNewt namespace. all functions and classes use this namespace. namespace OgreNewt { -class World; -class Body; - //! Iterate through all bodies in a specific AABB in the world. /*! this class is an easy way to loop through all bodies in an AABB in the world, performing some kind of action. Modified: branches/ogrenewt/newton20/inc/OgreNewt_Collision.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_Collision.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_Collision.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -14,30 +14,28 @@ #include "OgreNewt_Prerequisites.h" -#include "OgreNewt_World.h" -#include "OgreNewt_CollisionSerializer.h" + // OgreNewt namespace. all functions and classes use this namespace. namespace OgreNewt { -class World; -enum _OgreNewtExport CollisionPrimitive +enum _OgreNewtExport CollisionPrimitiveType { - BoxPrimitive = SERIALIZE_ID_BOX, - ConePrimitive = SERIALIZE_ID_CONE, - EllipsoidPrimitive = SERIALIZE_ID_SPHERE, - CapsulePrimitive = SERIALIZE_ID_CAPSULE, - CylinderPrimitive = SERIALIZE_ID_CYLINDER, - CompoundCollisionPrimitive = SERIALIZE_ID_COMPOUND, - ConvexHullPrimitive = SERIALIZE_ID_CONVEXHULL, - ConvexHullModifierPrimitive = SERIALIZE_ID_CONVEXMODIFIER, - ChamferCylinderPrimitive = SERIALIZE_ID_CHAMFERCYLINDER, - TreeCollisionPrimitive = SERIALIZE_ID_TREE, - NullPrimitive = SERIALIZE_ID_NULL, - HeighFieldPrimitive = SERIALIZE_ID_HEIGHTFIELD, - ScenePrimitive = SERIALIZE_ID_SCENE + BoxPrimitiveType = SERIALIZE_ID_BOX, + ConePrimitiveType = SERIALIZE_ID_CONE, + EllipsoidPrimitiveType = SERIALIZE_ID_SPHERE, + CapsulePrimitiveType = SERIALIZE_ID_CAPSULE, + CylinderPrimitiveType = SERIALIZE_ID_CYLINDER, + CompoundCollisionPrimitiveType = SERIALIZE_ID_COMPOUND, + ConvexHullPrimitiveType = SERIALIZE_ID_CONVEXHULL, + ConvexHullModifierPrimitiveType = SERIALIZE_ID_CONVEXMODIFIER, + ChamferCylinderPrimitiveType = SERIALIZE_ID_CHAMFERCYLINDER, + TreeCollisionPrimitiveType = SERIALIZE_ID_TREE, + NullPrimitiveType = SERIALIZE_ID_NULL, + HeighFieldPrimitiveType = SERIALIZE_ID_HEIGHTFIELD, + ScenePrimitiveType = SERIALIZE_ID_SCENE }; /* @@ -82,20 +80,21 @@ unsigned getUserID() const { return NewtonCollisionGetUserID( m_col ); } //! make unique - void makeUnique() { NewtonCollisionMakeUnique( m_world->getNewtonWorld(), m_col ); } + void makeUnique(); //! get the Axis-Aligned Bounding Box for this collision shape. Ogre::AxisAlignedBox getAABB( const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO ) const; //! Returns the Collisiontype for this Collision - CollisionPrimitive getCollisionPrimitiveType() const { return getCollisionPrimitiveType( m_col ); } + CollisionPrimitiveType getCollisionPrimitiveType() const { return getCollisionPrimitiveType( m_col ); } //! Returns the Collisiontype for the given Newton-Collision - static CollisionPrimitive getCollisionPrimitiveType(const NewtonCollision *col); + static CollisionPrimitiveType getCollisionPrimitiveType(const NewtonCollision *col); //! friend functions for the Serializer - friend void CollisionSerializer::exportCollision(const Collision* collision, const Ogre::String& filename); - friend void CollisionSerializer::importCollision(Ogre::DataStreamPtr& stream, Collision* pDest); + friend class OgreNewt::CollisionSerializer; + //friend void CollisionSerializer::exportCollision(const CollisionPtr& collision, const Ogre::String& filename); + //friend CollisionPtr CollisionSerializer::importCollision(Ogre::DataStreamPtr& stream, OgreNewt::World* world); protected: @@ -104,9 +103,8 @@ }; -//typedef Ogre::SharedPtr<Collision> CollisionPtr; -typedef Collision* CollisionPtr; + //! represents a collision shape that is explicitly convex. class _OgreNewtExport ConvexCollision : public Collision { @@ -135,14 +133,31 @@ }; +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR +typedef Collision* CollisionPtr; +typedef ConvexCollision* ConvexCollisionPtr; +#else +typedef boost::shared_ptr<Collision> CollisionPtr; +typedef boost::shared_ptr<ConvexCollision> ConvexCollisionPtr; +#endif + + + //! represents a scalable collision shape. -class _OgreNewtExport ConvexModifierCollision : public Collision +class _OgreNewtExport ConvexModifierCollision : public ConvexCollision { public: //! constructor - ConvexModifierCollision( const OgreNewt::World* world, const OgreNewt::Collision* col ); + /*! + Create a 'blank' box collision object. Can be used for CollisionSerializer::importCollision + \param world pointer to the OgreNewt::World + */ + ConvexModifierCollision( const OgreNewt::World* world ); + //! constructor + ConvexModifierCollision( const OgreNewt::World* world, const OgreNewt::ConvexCollisionPtr col ); + //! destructor ~ConvexModifierCollision(); Modified: branches/ogrenewt/newton20/inc/OgreNewt_CollisionPrimitives.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_CollisionPrimitives.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_CollisionPrimitives.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -264,7 +264,7 @@ /*! Create a tree collision object. \param world pointer to the OgreNewt::World - \param node pointer to an Ogre::SceneNode with a single entity attached. + \param ent pointer to an Ogre::Entitiy, if it is attached to a node, the scale of the parent node is used \param optimize bool whether you want to optimize the collision or not. */ TreeCollision( const World* world, Ogre::Entity* ent, bool optimize, FaceWinding fw = FW_DEFAULT ); @@ -388,7 +388,7 @@ \param world pointer to the OgreNewt::World \param col_array std::vector of pointers to existing collision objects. */ - CompoundCollision( const World* world, std::vector<OgreNewt::Collision*> col_array ); + CompoundCollision( const World* world, std::vector<OgreNewt::CollisionPtr> col_array ); //! destructor ~CompoundCollision() {} Modified: branches/ogrenewt/newton20/inc/OgreNewt_CollisionSerializer.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_CollisionSerializer.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_CollisionSerializer.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -14,12 +14,11 @@ #include "OgreNewt_Prerequisites.h" +#include "OgreNewt_Collision.h" // OgreNewt namespace. all functions and classes use this namespace. namespace OgreNewt { - class Collision; - /*! This class can be used to (de)serialize a Collision. Pre-building a Collision and serializing from a tool, then deserializing it at runtime may be more efficient than building the Collision on the fly, especially for complex objects. @@ -37,13 +36,13 @@ /*! Serialize the Collision to a file with the given name. */ - void exportCollision(const Collision* collision, const Ogre::String& filename); + void exportCollision(const OgreNewt::CollisionPtr& collision, const Ogre::String& filename); /*! Deserialize the Collision from a DataStream. this will create a NEW Collision object */ - void importCollision(Ogre::DataStreamPtr& stream, Collision* pDest); + OgreNewt::CollisionPtr importCollision(Ogre::DataStreamPtr& stream, OgreNewt::World* world); private: /*! Modified: branches/ogrenewt/newton20/inc/OgreNewt_ContactCallback.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_ContactCallback.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_ContactCallback.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -20,7 +20,6 @@ namespace OgreNewt { -class Body; //! custom contact behavior /*! Modified: branches/ogrenewt/newton20/inc/OgreNewt_ContactJoint.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_ContactJoint.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_ContactJoint.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -20,8 +20,6 @@ namespace OgreNewt { -class Contact; -class MaterialPair; //! with this class you can iterate through all contacts /*! Modified: branches/ogrenewt/newton20/inc/OgreNewt_Debugger.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_Debugger.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_Debugger.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -25,10 +25,6 @@ namespace OgreNewt { - class World; - class Body; - class MaterialID; - class Collision; //! For viewing the Newton rigid bodies visually. /*! @@ -90,7 +86,7 @@ void addRay(const Ogre::Vector3 &startpt, const Ogre::Vector3 &endpt); //! this function is used internally - void addConvexRay(const OgreNewt::Collision* col, const Ogre::Vector3 &startpt, const Ogre::Quaternion &colori, const Ogre::Vector3 &endpt); + void addConvexRay(const OgreNewt::ConvexCollisionPtr& col, const Ogre::Vector3 &startpt, const Ogre::Quaternion &colori, const Ogre::Vector3 &endpt); //! this function is used internally void addDiscardedBody(const OgreNewt::Body* body); @@ -117,8 +113,12 @@ struct BodyDebugData { - BodyDebugData() : m_lastcol(NULL), m_node(NULL), m_lines(NULL), m_text(NULL), m_updated(false) {} - const Collision* m_lastcol; + BodyDebugData() : +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR + m_lastcol(NULL), +#endif + m_node(NULL), m_lines(NULL), m_text(NULL), m_updated(false) {} + CollisionPtr m_lastcol; Ogre::SceneNode* m_node; Ogre::ManualObject* m_lines; OgreNewt::OgreAddons::MovableText* m_text; Modified: branches/ogrenewt/newton20/inc/OgreNewt_Joint.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_Joint.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_Joint.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -20,8 +20,6 @@ namespace OgreNewt { -class World; -class Body; //! base class for all joints. /*! @@ -71,22 +69,35 @@ /*! user data can be used to connect this class to other user classes through the use of this general pointer. */ - void setUserData( void* ptr ) { m_userdata = ptr; } +#ifndef OGRENEWT_NO_OGRE_ANY + void setUserData( const Ogre::Any& data ) { m_userdata = data; } +#else + void setUserData( void* data ) { m_userdata = data; } +#endif //! get user data for this joint /*! user data can be used to connect this class to other user classes through the use of this general pointer. */ +#ifndef OGRENEWT_NO_OGRE_ANY + const Ogre::Any& getUserData() const { return m_userdata; } +#else void* getUserData() const { return m_userdata; } +#endif - + protected: NewtonJoint* m_joint; const OgreNewt::World* m_world; - void* m_userdata; +#ifndef OGRENEWT_NO_OGRE_ANY + Ogre::Any m_userdata; +#else + void* m_userdata; +#endif + static void _CDECL destructor( const NewtonJoint* me ); }; Modified: branches/ogrenewt/newton20/inc/OgreNewt_MaterialID.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_MaterialID.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_MaterialID.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -19,7 +19,6 @@ namespace OgreNewt { -class World; //! represents a material class _OgreNewtExport MaterialID @@ -32,11 +31,6 @@ */ MaterialID( const World* world ); - /*! - Overloaded constructor, sets the internal ID manually. should not be used by the end-user. - */ - MaterialID( const World* world, int ID ); - //! destructor ~MaterialID(); @@ -45,6 +39,14 @@ protected: + friend class OgreNewt::World; + + /*! + Overloaded constructor, sets the internal ID manually. should not be used by the end-user. + */ + MaterialID( const World* world, int ID ); + +private: int id; const OgreNewt::World* m_world; Modified: branches/ogrenewt/newton20/inc/OgreNewt_PlayerController.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_PlayerController.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_PlayerController.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -21,9 +21,6 @@ namespace OgreNewt { -class Collision; -class ConvexCollision; - //! PlayerController /*! this class implements a player-controller based on the code of the CustomPlayerController-class in the Newton-CustomJoints library @@ -85,9 +82,9 @@ Ogre::Vector3 m_upVector; bool m_isInJumpState; - OgreNewt::ConvexCollision* m_verticalSensorShape; - OgreNewt::ConvexCollision* m_horizontalSensorShape; - OgreNewt::ConvexCollision* m_dynamicsSensorShape; + OgreNewt::ConvexCollisionPtr m_verticalSensorShape; + OgreNewt::ConvexCollisionPtr m_horizontalSensorShape; + OgreNewt::ConvexCollisionPtr m_dynamicsSensorShape; virtual bool convexStaticCastPreFilter(OgreNewt::Body *body); virtual bool convexDynamicCastPreFilter(OgreNewt::Body *body); @@ -133,7 +130,7 @@ public: StaticConvexCast(PlayerController *pc) : m_parent(pc) {} - void go(const OgreNewt::Collision* col, const Ogre::Vector3& startpt, + void go(const OgreNewt::ConvexCollisionPtr& col, const Ogre::Vector3& startpt, const Ogre::Quaternion &colori, const Ogre::Vector3& endpt, int maxcontactscount, int thread) { go(m_parent->getControlledBody()->getWorld(), col, startpt, colori, endpt, maxcontactscount, thread); @@ -150,7 +147,7 @@ public: DynamicConvexCast(PlayerController *pc) : m_parent(pc) {} - void go(const OgreNewt::Collision* col, const Ogre::Vector3& startpt, + void go(const OgreNewt::ConvexCollisionPtr& col, const Ogre::Vector3& startpt, const Ogre::Quaternion &colori, const Ogre::Vector3& endpt, int maxcontactscount, int thread) { go(m_parent->getControlledBody()->getWorld(), col, startpt, colori, endpt, maxcontactscount, thread); @@ -167,7 +164,7 @@ public: AllBodyConvexCast(PlayerController *pc) : m_parent(pc) {} - void go(const OgreNewt::Collision* col, const Ogre::Vector3& startpt, + void go(const OgreNewt::ConvexCollisionPtr& col, const Ogre::Vector3& startpt, const Ogre::Quaternion &colori, const Ogre::Vector3& endpt, int maxcontactscount, int thread) { go(m_parent->getControlledBody()->getWorld(), col, startpt, colori, endpt, maxcontactscount, thread); Modified: branches/ogrenewt/newton20/inc/OgreNewt_Prerequisites.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_Prerequisites.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_Prerequisites.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -22,6 +22,9 @@ # include <Ogre/OgreRenderable.h> # include <Ogre/OgreNode.h> # include <Ogre/OgreFrameListener.h> +# ifndef OGRENEWT_NO_OGRE_ANY +# include <Ogre/OgreAny.h> +# endif #else #include <OgreVector3.h> #include <OgreQuaternion.h> @@ -29,9 +32,17 @@ #include <OgreRenderable.h> #include <OgreNode.h> #include <OgreFrameListener.h> +# ifndef OGRENEWT_NO_OGRE_ANY +# include <OgreAny.h> +# endif #endif #include <Newton.h> +#include <boost/function.hpp> +#include <boost/bind.hpp> +#ifndef OGRENEWT_NO_COLLISION_SHAREDPTR +# include <boost/shared_ptr.hpp> +#endif #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 # define _CDECL _cdecl @@ -47,5 +58,28 @@ # define _CDECL #endif + +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR +#warning "the option OGRENEWT_NO_COLLISION_SHAREDPTR is set" +#endif + +#ifdef OGRENEWT_NO_OGRE_ANY +#warning "the option OGRENEWT_NO_OGRE_ANY is set" +#endif + +namespace OgreNewt +{ + class World; + class MaterialID; + class Joint; + class Contact; + class MaterialPair; + class Body; + class Collision; + class CollisionSerializer; + class ConvexCollision; + class Debugger; +} + #endif Modified: branches/ogrenewt/newton20/inc/OgreNewt_RayCast.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_RayCast.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_RayCast.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -21,8 +21,6 @@ namespace OgreNewt { -class World; -class Body; //! general raycast /*! @@ -186,7 +184,7 @@ \param maxcontactscount maximum number of contacts that should be saved, set to 0 if you only need the distance to the first intersection */ - void go( const OgreNewt::World* world, const OgreNewt::Collision* col, const Ogre::Vector3& startpt, const Ogre::Quaternion &colori, const Ogre::Vector3& endpt, int maxcontactscount, int threadIndex); + void go( const OgreNewt::World* world, const OgreNewt::ConvexCollisionPtr& col, const Ogre::Vector3& startpt, const Ogre::Quaternion &colori, const Ogre::Vector3& endpt, int maxcontactscount, int threadIndex); //! user callback pre-filter function. /*! @@ -254,7 +252,7 @@ \param endpt ending point of ray in global space \param maxcontactscount maximum number of contacts that should be saved */ - BasicConvexcast( const OgreNewt::World* world, const OgreNewt::Collision* col, const Ogre::Vector3& startpt, const Ogre::Quaternion &colori, const Ogre::Vector3& endpt, int maxcontactscount, int threadIndex); + BasicConvexcast( const OgreNewt::World* world, const OgreNewt::ConvexCollisionPtr& col, const Ogre::Vector3& startpt, const Ogre::Quaternion &colori, const Ogre::Vector3& endpt, int maxcontactscount, int threadIndex); //! destuctor. ~BasicConvexcast(); Modified: branches/ogrenewt/newton20/inc/OgreNewt_Tools.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_Tools.h 2009-04-27 23:06:24 UTC (rev 2690) +++ branches/ogrenewt/newton20/inc/OgreNewt_Tools.h 2009-05-18 17:21:05 UTC (rev 2691) @@ -14,12 +14,12 @@ #include "OgreNewt_Prerequisites.h" +#include "OgreNewt_Collision.h" namespace OgreNewt { - class World; - class Collision; + //! set of handy convertors. namespace Converters { @@ -70,7 +70,7 @@ \param retnormal returned normal on the collision primitive in global space */ _OgreNewtExport int CollisionPointDistance( const OgreNewt::World* world, const Ogre::Vector3& globalpt, - const OgreNewt::Collision* col, const Ogre::Quaternion& colorient, const Ogre::Vector3& colpos, + const OgreNewt::CollisionPtr& col, const Ogre::Quaternion& colorient, const Ogre::Vector3& colpos, Ogre::Vector3& retpt, Ogre::Vector3& retnormal, int threadIndex ); @@ -88,8 +88,8 @@ \param retPosB returned position on collision primitive B \param retNorm returned collision normal */ - _OgreNewtExport int CollisionClosestPoint( const OgreNewt::World* world, const OgreNewt::Collision* colA, const Ogre::Quaternion& colOrientA, const Ogre::Vector3& colPosA, - const OgreNewt::Collision* colB, const Ogre::Quaternion& colOrientB, const Ogre::Vector3& colPosB, + _OgreNewtExport int CollisionClosestPoint( const OgreNewt::World* world, const OgreNewt::CollisionPtr& colA, const Ogre::Quaternion& colOrientA, const Ogre::Vector3& colPosA, + const OgreNewt::CollisionPtr& colB, const Ogre::Quaternion& colOrientB, const Ogre::Vector3& colPosB, Ogre::Vector3& retPosA, Ogre::Vector3& retPosB, Ogre::Vector3& retNorm, int threadIndex ); @@ -110,8 +110,8 @@ \param retPenetrations returned penetrations for each contact. */ _OgreNewtExport int CollisionCollide( const OgreNewt::World* world, int maxSize, - const OgreNewt::Collision* colA, const Ogre::Quaternion& colOrientA, const Ogre::Vector3& colPosA, - const OgreNewt::Collision* colB, const Ogre::Quaternion& colOrientB, const Ogre::Vector3& colPosB, + const OgreNewt::CollisionP... [truncated message content] |