From: <me...@us...> - 2009-08-01 20:10:01
|
Revision: 2722 http://ogreaddons.svn.sourceforge.net/ogreaddons/?rev=2722&view=rev Author: melven2 Date: 2009-08-01 20:09:43 +0000 (Sat, 01 Aug 2009) Log Message: ----------- -updated to newton 2.04 -interface changes (concerning collisions) -some multithreading fixes and the linux version now uses pthreads -probably very unstable (I didn't have much time), so use the revision 2676 instead with an older version of newton 2.0 beta Revision Links: -------------- http://ogreaddons.svn.sourceforge.net/ogreaddons/?rev=2676&view=rev 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/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/OgreNewtonApplication.cpp branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/OgreNewtonFrameListener.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/inc/OgreNewt.h branches/ogrenewt/newton20/inc/OgreNewt_BasicJoints.h branches/ogrenewt/newton20/inc/OgreNewt_Body.h branches/ogrenewt/newton20/inc/OgreNewt_Collision.h branches/ogrenewt/newton20/inc/OgreNewt_CollisionPrimitives.h branches/ogrenewt/newton20/inc/OgreNewt_World.h branches/ogrenewt/newton20/src/OgreNewt_BasicJoints.cpp branches/ogrenewt/newton20/src/OgreNewt_Body.cpp branches/ogrenewt/newton20/src/OgreNewt_CollisionPrimitives.cpp branches/ogrenewt/newton20/src/OgreNewt_Debugger.cpp branches/ogrenewt/newton20/src/OgreNewt_PlayerController.cpp branches/ogrenewt/newton20/src/OgreNewt_World.cpp Modified: branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonApplication.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonApplication.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -55,7 +55,7 @@ // here's where we make a collision shape for the physics. note that we use the same size as // above. - OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder(m_World, 2.5, 5)); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder(m_World, 2.5, 5, 0)); // now we make a new rigid body based on this collision shape. OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); Modified: branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonFrameListener.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo01_TheBasics/OgreNewtonFrameListener.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -80,7 +80,7 @@ //ent->setNormaliseNormals(true); // again, make the collision shape. - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder(m_World, 1, 1)); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder(m_World, 1, 1, 0)); // then make the rigid body. OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); @@ -125,6 +125,10 @@ debug.stopRaycastRecording(); } + + if (mKeyboard->isKeyDown(OIS::KC_T)) + m_World->setThreadCount( m_World->getThreadCount() % 2 + 1); + if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; Modified: branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonApplication.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonApplication.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -73,7 +73,7 @@ // using the new "SceneParser" TreeCollision primitive. this will automatically parse an entire tree of // 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 ); + stat_col->parseScene( floornode, true, 0 ); OgreNewt::Body* bod = new OgreNewt::Body( m_World, OgreNewt::CollisionPtr(stat_col) ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete stat_col; @@ -162,7 +162,7 @@ box1node->setScale( size ); // box1->setNormaliseNormals(true); - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); Modified: branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonFrameListener.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo02_Joints/OgreNewtonFrameListener.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -74,7 +74,7 @@ ent->setMaterialName( "Simple/dirt01" ); // ent->setNormaliseNormals(true); - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(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), 0 )); OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR @@ -112,6 +112,10 @@ + + if (mKeyboard->isKeyDown(OIS::KC_T)) + m_World->setThreadCount( m_World->getThreadCount() % 2 + 1); + if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; Modified: branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorBelt.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorBelt.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/ConveyorBelt.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -27,7 +27,7 @@ mNode->setScale( size ); // create the collision object for the conveyor belt. - OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size )); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size, 0 )); mBody = new OgreNewt::Body( world, col, conveyorType ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; Modified: branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonApplication.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonApplication.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -79,7 +79,7 @@ floor->setCastShadows( false ); //Ogre::Vector3 siz(100.0, 10.0, 100.0); - OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true )); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR @@ -125,7 +125,7 @@ mFrameListener = new OgreNewtonFrameListener( mWindow, mCamera, mSceneMgr, m_World); mRoot->addFrameListener(mFrameListener); - mNewtonListener = new OgreNewt::BasicFrameListener( mWindow, m_World, 60 ); + mNewtonListener = new OgreNewt::BasicFrameListener( mWindow, m_World, 600 ); mRoot->addFrameListener(mNewtonListener); } Modified: branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonFrameListener.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo03_CollisionCallbacks/OgreNewtonFrameListener.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -68,7 +68,7 @@ ent->setMaterialName( "Simple/BumpyMetal" ); - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size, 0 )); OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); Ogre::Vector3 inertia, offset; @@ -106,6 +106,10 @@ + + if (mKeyboard->isKeyDown(OIS::KC_T)) + m_World->setThreadCount( m_World->getThreadCount() % 2 + 1); + if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; Modified: branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonApplication.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonApplication.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -75,7 +75,7 @@ //Ogre::Vector3 siz(100.0, 10.0, 100.0); - OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true )); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; @@ -176,7 +176,7 @@ box1node->attachObject( box1 ); box1node->setScale( size ); - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); Modified: branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonFrameListener.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo04_Raycasting/OgreNewtonFrameListener.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -180,6 +180,10 @@ + if (mKeyboard->isKeyDown(OIS::KC_T)) + m_World->setThreadCount( m_World->getThreadCount() % 2 + 1); + + if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; Modified: branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/OgreNewtonApplication.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/OgreNewtonApplication.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -48,7 +48,7 @@ floor->setCastShadows( false ); //Ogre::Vector3 siz(100.0, 10.0, 100.0); - OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floornode, false ); + OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floornode, false, 0 ); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); delete col; Modified: branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/OgreNewtonFrameListener.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo05_SimpleVehicle/OgreNewtonFrameListener.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -74,7 +74,7 @@ ent->setMaterialName( "Simple/dirt01" ); - OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) ); + OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1), 0 ); OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcSphereSolid( 10.0, 1.0 ); @@ -140,6 +140,10 @@ + if (mKeyboard->isKeyDown(OIS::KC_T)) + m_World->setThreadCount( m_World->getThreadCount() % 2 + 1); + + if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) { if (mCar) Modified: branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonApplication.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonApplication.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -75,7 +75,7 @@ //Ogre::Vector3 siz(100.0, 10.0, 100.0); - OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true )); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; @@ -193,7 +193,7 @@ box1node->attachObject( box1 ); box1node->setScale( size ); - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); Modified: branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonFrameListener.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo06_SimpleBuoyancy/OgreNewtonFrameListener.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -165,7 +165,7 @@ { debug.showDebugInformation(); debug.startRaycastRecording(); - debug.clearRaycastsRecorded(); + //debug.clearRaycastsRecorded(); } else { @@ -176,6 +176,10 @@ + if (mKeyboard->isKeyDown(OIS::KC_T)) + m_World->setThreadCount( m_World->getThreadCount() % 2 + 1); + + if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; @@ -214,12 +218,15 @@ Ogre::Vector3 dragForce = ((campt - bodpt) * mass * 8.0) - me->getVelocity(); // draw a 3D line between these points for visual effect :) + /* remove3DLine(); mDragLine->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST ); mDragLine->position( campt ); mDragLine->position( bodpt ); + // ---------------------------- I get an error here using multithreading... ------------------------------- mDragLine->end(); mDragLineNode->attachObject( mDragLine ); + */ // Add the force! Modified: branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonApplication.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonApplication.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -74,7 +74,7 @@ // using the new "SceneParser" TreeCollision primitive. this will automatically parse an entire tree of // 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 ); + stat_col->parseScene( floornode, true, 0 ); OgreNewt::Body* bod = new OgreNewt::Body( m_World, OgreNewt::CollisionPtr(stat_col) ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete stat_col; @@ -162,7 +162,7 @@ box1node->attachObject( box1 ); box1node->setScale( size ); - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); Modified: branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonFrameListener.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo07_CustomJoints/OgreNewtonFrameListener.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -73,7 +73,7 @@ ent->setMaterialName( "Simple/dirt01" ); - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(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), 0 )); OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); Ogre::Vector3 inertia, offset; @@ -111,6 +111,10 @@ + + if (mKeyboard->isKeyDown(OIS::KC_T)) + m_World->setThreadCount( m_World->getThreadCount() % 2 + 1); + if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; Modified: branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonApplication.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonApplication.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -49,7 +49,7 @@ floor->setCastShadows( false ); //Ogre::Vector3 siz(100.0, 10.0, 100.0); - OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true )); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; @@ -99,7 +99,7 @@ box1node->attachObject( box1 ); box1node->setScale( size ); - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size )); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); Modified: branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonFrameListener.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo08_RagdollExample/OgreNewtonFrameListener.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -87,7 +87,7 @@ ent->setMaterialName( "Simple/dirt01" ); - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(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), 0 )); OgreNewt::Body* body = new OgreNewt::Body( m_World, col ); Ogre::Vector3 inertia, offset; @@ -185,6 +185,8 @@ + if (mKeyboard->isKeyDown(OIS::KC_T)) + m_World->setThreadCount( m_World->getThreadCount() % 2 + 1); if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; Modified: branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/demos/Demo08_RagdollExample/Ragdoll.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -36,23 +36,23 @@ switch (shape) { case RagDoll::RagBone::BS_BOX: - col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size )); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size, 0 )); break; case RagDoll::RagBone::BS_CAPSULE: - col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Capsule( world, size.y, size.x, orient, pos )); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Capsule( world, size.y, size.x, 0, orient, pos )); break; case RagDoll::RagBone::BS_CONE: - col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cone( world, size.y, size.x, orient, pos )); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cone( world, size.y, size.x, 0, orient, pos )); break; case RagDoll::RagBone::BS_CYLINDER: - col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder( world, size.y, size.x, orient, pos )); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder( world, size.y, size.x, 0, orient, pos )); break; case RagDoll::RagBone::BS_ELLIPSOID: - col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid( world, size )); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid( world, size, 0 )); break; case RagDoll::RagBone::BS_CONVEXHULL: @@ -60,7 +60,7 @@ break; default: - col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size )); + col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size, 0 )); break; } @@ -212,7 +212,7 @@ } ////////////////////////////////////////////////////////////////////////////////// - OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::ConvexHull( world, verts, numVerts )); + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::ConvexHull( world, verts, numVerts, 0 )); delete []verts; Modified: branches/ogrenewt/newton20/inc/OgreNewt.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt.h 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/inc/OgreNewt.h 2009-08-01 20:09:43 UTC (rev 2722) @@ -9,9 +9,9 @@ main header file. - current version: 2.00 ( I only raised the version number to indicate that this is for Newton2.0! ) + current version: 2.04.0 - Newton version: 2.0 beta (31.01.2009) + Newton version: 2.04 (beta) Ogre version: Shoggoth (1.6.x) @@ -41,7 +41,7 @@ #include "OgreNewt_BodyInAABBIterator.h" #include "OgreNewt_Debugger.h" -/*! \mainpage OgreNewt Library version 2.00 +/*! \mainpage OgreNewt Library version 2.04.0 (for newton version 2.04) \section into_sec Introduction @@ -69,6 +69,11 @@ \section new New in this version New in this version + - first attempts to support multithreading + - update the nodes of the bodies after the newton world update, because Ogre doesn't support multithreaded access to nodes + - linux: added a pthread-mutex for Ogre in OgreNewt::World, so it can be used for access to Ogre from multiple threads + - updated to newton 2.04 -- interface breaking changes (not compatible with newton 2.03!) + - set the collision id when creating a collision - 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 Modified: branches/ogrenewt/newton20/inc/OgreNewt_BasicJoints.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_BasicJoints.h 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/inc/OgreNewt_BasicJoints.h 2009-08-01 20:09:43 UTC (rev 2722) @@ -490,6 +490,28 @@ Ogre::Quaternion mLocalOrient1; }; + //! CustomDryRollingFriction + /*! + * This joint is usefully to simulate the rolling friction of a rolling ball over a flat surface. + * Normally this is not important for non spherical objects, but for games like poll, pinball, bolling, golf + * or any other where the movement of balls is the main objective the rolling friction is a real big problem. + */ + /* // not tested yet + class _OgreNewtExport CustomDryRollingFriction : public OgreNewt::CustomJoint + { + public: + CustomDryRollingFriction( OgreNewt::Body* child, Ogre::Real radius, Ogre::Real rollingFrictionCoefficient ); + ~CustomDryRollingFriction(); + + void submitConstraint( Ogre::Real timestep, int threadIndex ); + + private: + Ogre::Real mFrictionCoefficient; + Ogre::Real mFrictionTorque; + OgreNewt::Body* mChild; + }; + */ + } // end NAMESPACE PrebuiltCustomJoints Modified: branches/ogrenewt/newton20/inc/OgreNewt_Body.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_Body.h 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/inc/OgreNewt_Body.h 2009-08-01 20:09:43 UTC (rev 2722) @@ -179,8 +179,9 @@ generally in a physics engine you shouldn't directly set the location/rotation of a Body, because this defies physics laws. this command exists to set up bodies initially. \param orient quaternion representing body orientation in world space. \param pos vector representing body position in world space. + \param threadIndex only set the thread-index if you don't want the node to be updated immediatly but queued (Ogre doesn't support modifying nodes from several threads) */ - void setPositionOrientation( const Ogre::Vector3& pos, const Ogre::Quaternion& orient ); + void setPositionOrientation( const Ogre::Vector3& pos, const Ogre::Quaternion& orient , int threadIndex = -1); //! set the mass and inertia for the body. /*! @@ -409,6 +410,21 @@ */ NewtonCollision *getNewtonCollision() const { return NewtonBodyGetCollision( m_body ); } + //! Call this to signify that the position/orientation of the attached node needs to be updated + /*! + * This function actually adds this body to a list of bodies that need to be updated. This is done automaticalle after the next world update + * using the updateNode method. + * This function is needed for multithreading support + * \param forceNodeUpdate even request an update if there's already an update request + */ + void requestNodeUpdate(int threadIndex, bool forceNodeUpdate = false); + + //! Return if an node update was requested + bool isNodeUpdateNeeded() const {return m_nodeupdateneeded;} + + //! update the position of the node (if attached) and sets m_nodeupdateneeded to false + void updateNode(); + protected: NewtonBody* m_body; @@ -424,6 +440,7 @@ int m_type; Ogre::Node* m_node; + bool m_nodeupdateneeded; ForceCallback m_forcecallback; TransformCallback m_transformcallback; Modified: branches/ogrenewt/newton20/inc/OgreNewt_Collision.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_Collision.h 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/inc/OgreNewt_Collision.h 2009-08-01 20:09:43 UTC (rev 2722) @@ -69,12 +69,13 @@ */ const World* getWorld() const {return m_world;} - //! set a user ID for collision callback identification - /*! - you can set different IDs for each piece in a compound collision object, and then use these IDs in a collision callback to - determine which part is currently colliding. - */ - void setUserID( unsigned id ) const { NewtonCollisionSetUserID( m_col, id); } +// this is not possible any more (since newton 2.04), you can only set the id when creating the collision +// //! set a user ID for collision callback identification +// /*! +// you can set different IDs for each piece in a compound collision object, and then use these IDs in a collision callback to +// determine which part is currently colliding. +// */ +// void setUserID( unsigned id ) const { NewtonCollisionSetUserID( m_col, id); } //! get user ID, for collision callback identification unsigned getUserID() const { return NewtonCollisionGetUserID( m_col ); } Modified: branches/ogrenewt/newton20/inc/OgreNewt_CollisionPrimitives.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_CollisionPrimitives.h 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/inc/OgreNewt_CollisionPrimitives.h 2009-08-01 20:09:43 UTC (rev 2722) @@ -15,6 +15,7 @@ #include "OgreNewt_Prerequisites.h" #include "OgreNewt_Collision.h" +#include "OgreNewt_MaterialID.h" // OgreNewt namespace. all functions and classes use this namespace. @@ -54,10 +55,11 @@ /*! \param world pointer to OgreNewt::World \param size vector representing width, height, depth + \param id an id for this shape, can be received with collision->getUserId() \param orient orientation offset of the primitive \param pos position offset of the primitive */ - Box( const World* world, const Ogre::Vector3& size, + Box( const World* world, const Ogre::Vector3& size, int id, const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO ); //! destructor @@ -80,10 +82,11 @@ for a sphere, pass the same radius for all 3 axis. \param world pointer to OgreNewt::World \param size vector representing radius for all 3 axis + \param id an id for this shape, can be received with collision->getUserId() \param orient orientation offset of the primitive \param pos position offset of the primitive */ - Ellipsoid(const World* world, const Ogre::Vector3& size, + Ellipsoid(const World* world, const Ogre::Vector3& size, int id, const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO ); //! destructor @@ -107,10 +110,11 @@ \param world pointer to OgreNewt::World \param radius radius of the cylinder (Y and Z axis) \param height height of the cylinder (X axis) + \param id an id for this shape, can be received with collision->getUserId() \param orient orientation offset of the primitive \param pos position offset of the primitive */ - Cylinder( const World* world, Ogre::Real radius, Ogre::Real height, + Cylinder( const World* world, Ogre::Real radius, Ogre::Real height, int id, const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO ); //! destructor @@ -134,10 +138,11 @@ \param world pointer to OgreNewt::World \param radius radius of the capsule (Y and Z axis) \param height height of the capsule (X axis) + \param id an id for this shape, can be received with collision->getUserId() \param orient orientation offset of the primitive \param pos position offset of the primitive */ - Capsule( const World* world, Ogre::Real radius, Ogre::Real height, + Capsule( const World* world, Ogre::Real radius, Ogre::Real height, int id, const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO ); //! destructor @@ -161,10 +166,11 @@ \param world pointer to OgreNewt::World \param radius radius of the cone (Y and Z axis) \param height height of the cone (X axis) + \param id an id for this shape, can be received with collision->getUserId() \param orient orientation offset of the primitive \param pos position offset of the primitive */ - Cone( const World* world, Ogre::Real radius, Ogre::Real height, + Cone( const World* world, Ogre::Real radius, Ogre::Real height, int id, const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO ); //! destructor @@ -188,10 +194,11 @@ \param world pointer to OgreNewt::World \param radius radius of the chamfer cylinder (Y and Z axis) \param height height of the chamfer cylinder (X axis) + \param id an id for this shape, can be received with collision->getUserId() \param orient orientation offset of the primitive \param pos position offset of the primitive */ - ChamferCylinder( const World* world, Ogre::Real radius, Ogre::Real height, + ChamferCylinder( const World* world, Ogre::Real radius, Ogre::Real height, int id, const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO ); //! destructor @@ -215,15 +222,16 @@ //! constructor /*! Overloaded constructor. pass an Entity*, and it will use its vertex data. if it is attached to Node*, the collision - will be scaled apperently (entity->getParentNode()->getScale()) + will be scaled apperently (entity->getParentNode()->getScale()), but if the scale changes, you need to adopt your collision by yourself \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::Entity + \param id an id for this shape, can be received with collision->getUserId() \param orient orientation offset of the primitive \param pos position offset of the primitive \parem tolerance a tolerance passed to newton \param forceScale if set to something else then (0,0,0), the value of this argument will be used as scale instead of the parent-node's scale */ - ConvexHull( const World* world, Ogre::Entity* ent, + ConvexHull( const World* world, Ogre::Entity* ent, int id, const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO, Ogre::Real tolerance = 0.001f , const Ogre::Vector3& forceScale = Ogre::Vector3::ZERO); /*! @@ -231,11 +239,12 @@ \param world pointer to the OgreNewt::World \param verts pointer to an array of Ogre::Vector3's that contain vertex position data \param vertcount number ot vetices in the array + \param id an id for this shape, can be received with collision->getUserId() \param orient orientation offset of the primitive \param pos position offset of the primitive \param tolerance a tolerance passed to newton */ - ConvexHull( const World* world, const Ogre::Vector3* verts, int vertcount, + ConvexHull( const World* world, const Ogre::Vector3* verts, int vertcount,int id, const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO, Ogre::Real tolerance = 0.001f ); //! destructor @@ -266,8 +275,9 @@ \param world pointer to the OgreNewt::World \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. + \param id an id for this shape, can be received with collision->getUserId() */ - TreeCollision( const World* world, Ogre::Entity* ent, bool optimize, FaceWinding fw = FW_DEFAULT ); + TreeCollision( const World* world, Ogre::Entity* ent, bool optimize, int id, FaceWinding fw = FW_DEFAULT ); //! constructor /*! @@ -279,8 +289,9 @@ \param vertices pointer to array of vertices (positions only). \param indices pointer to array of indices. \param optimize bool whether you want to optimize the collision or not. + \param id an id for this shape, can be received with collision->getUserId() */ - TreeCollision( const World* world, int numVertices, int numIndices, const float *vertices, const int *indices, bool optimize, FaceWinding fw = FW_DEFAULT); + TreeCollision( const World* world, int numVertices, int numIndices, const float *vertices, const int *indices, bool optimize, int id, FaceWinding fw = FW_DEFAULT); //! constructor /*! @@ -291,14 +302,15 @@ \param vertices pointer to array of Ogre::Vector3 vertices (positions only) \param indexData pointer to Ogre::IndexData for the mesh \param optimize bool whether you want to optimize the collision or not. + \param id an id for this shape, can be received with collision->getUserId() */ - TreeCollision( const World* world, int numVertices, Ogre::Vector3* vertices, Ogre::IndexData* indexData, bool optimize, FaceWinding fw = FW_DEFAULT); + TreeCollision( const World* world, int numVertices, Ogre::Vector3* vertices, Ogre::IndexData* indexData, bool optimize, int id, FaceWinding fw = FW_DEFAULT); //! destructor virtual ~TreeCollision() {} //! start a tree collision creation - void start(); + void start(int id); //! add a poly to the tree collision /*! @@ -345,7 +357,7 @@ ~TreeCollisionSceneParser() {} //! parse the scene. - void parseScene( Ogre::SceneNode* startNode, bool optimize = true, FaceWinding fw = FW_DEFAULT ); + void parseScene( Ogre::SceneNode* startNode, int id, bool optimize = true, FaceWinding fw = FW_DEFAULT ); protected: @@ -418,11 +430,12 @@ /*! \param world pointer to the OgreNewt::World \param size Ogre::Vector3 size. + \param id an id for this shape, can be received with collision->getUserId() \param orient orientation offset of the primitive \param pos position offset of the primitive \param tolerance a tolerance passed to newton */ - Pyramid( const World* world, const Ogre::Vector3& size, + Pyramid( const World* world, const Ogre::Vector3& size, int id, const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO, Ogre::Real tolerance = 0.001f ); //! destructor Modified: branches/ogrenewt/newton20/inc/OgreNewt_World.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt_World.h 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/inc/OgreNewt_World.h 2009-08-01 20:09:43 UTC (rev 2722) @@ -11,6 +11,9 @@ #ifndef _INCLUDE_OGRENEWT_WORLD #define _INCLUDE_OGRENEWT_WORLD +#ifndef WIN32 +#include <pthread.h> +#endif #include "OgreNewt_Prerequisites.h" #include "OgreNewt_BodyInAABBIterator.h" @@ -64,7 +67,7 @@ public: //! Standard Constructor, creates the world. - World(); + World( NewtonAllocMemory newtonAlloc = NULL, NewtonFreeMemory newtonFree = NULL ); //! Standard Destructor, destroys the world. ~World(); @@ -127,6 +130,13 @@ */ void setPlatformArchitecture( int mode ) { NewtonSetPlatformArchitecture( m_world, mode ); } + //! get the architecture used for physics calculations. + /*! + \param description returns a description-string for the currently used mode + \return int representing the current mode + */ + int getPlatformArchitecture(Ogre::String& description) { char desc[265]; int mode = NewtonGetPlatformArchitecture( m_world, desc ); description = desc; return mode;} + //! get the number of bodies in the simulation. /*! returns the number of bodies in the simulation. @@ -139,17 +149,20 @@ //! multithread settings void setMultithreadSolverOnSingleIsland( int mode ) { NewtonSetMultiThreadSolverOnSingleIsland( m_world, mode ); } - //! set the number of threads for the physics simulation to use. + //! get multithread settings + int getMultithreadSolverOnSingleIsland( ) const { return NewtonGetMultiThreadSolverOnSingleIsland( m_world ); } + + //! set the number of threads for the physics simulation to use, don't do this while world update void setThreadCount(int threads) { NewtonSetThreadsCount( m_world, threads ); } //! get the number of threads the simulation is using. int getThreadCount() const { return NewtonGetThreadsCount( m_world ); } //! notify an entrance to a critical section of code. - void criticalSectionLock() { NewtonWorldCriticalSectionLock( m_world ); } + void criticalSectionLock() const { NewtonWorldCriticalSectionLock( m_world ); } //! notify the exit of a critical section of code. - void cricicalSectionUnlock() { NewtonWorldCriticalSectionUnlock( m_world ); } + void criticalSectionUnlock() const { NewtonWorldCriticalSectionUnlock( m_world ); } //! set minimum framerate void setMinimumFrameRate( Ogre::Real frame ) { NewtonSetMinimumFrameRate( m_world, frame ); } @@ -205,17 +218,50 @@ */ Debugger& getDebugger() const {return *m_debugger;} + //! adds an update request for the body, this means that after the next world update the function body->updateNode will be called, if the bodie needs updating + void addBodyUpdateNodeRequest( int threadIndex, OgreNewt::Body* body ) const ; + + +#ifndef WIN32 + //! notify an entrance to a critical section of code concerning Ogre (and only concerning Ogre!) + /*! + * This function is only used in OgreNewt and can be used by the user, it is independent of Ogre's own thread support... + */ + void ogreCriticalSectionLock() const { pthread_mutex_lock(&m_ogreMutex); } + + //! notify the exit of a critical section of code concerning Ogre (and only concerning Ogre!) + /*! + * This function is only used in OgreNewt and can be used by the user, it is independent of Ogre's own thread support... + */ + void ogreCriticalSectionUnlock() const { pthread_mutex_unlock(&m_ogreMutex); } + + //! notify an entrance to a critical section of code concerning Ogre (and only concerning Ogre!) + /*! + * This function is only used in OgreNewt and can be used by the user, it is independent of Ogre's own thread support... + * \return true if not already locked + */ + // bool ogreCriticalSectionTryLock() const { return (EBUSY != pthread_mutex_trylock(&m_ogreMutex)); } +#endif + protected: NewtonWorld* m_world; MaterialID* m_defaultMatID; LeaveWorldCallback m_leaveCallback; - + BodyInAABBIterator m_bodyInAABBIterator; + typedef std::vector< OgreNewt::Body* > BodyVector; + typedef std::vector< BodyVector > BodyVectorVector; + mutable BodyVectorVector m_bodyUpdateNodeRequests; + mutable Debugger* m_debugger; +#ifndef WIN32 + mutable pthread_mutex_t m_ogreMutex; +#endif + private: static void _CDECL newtonLeaveWorld( const NewtonBody* body, int threadIndex ); Modified: branches/ogrenewt/newton20/src/OgreNewt_BasicJoints.cpp =================================================================== --- branches/ogrenewt/newton20/src/OgreNewt_BasicJoints.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/src/OgreNewt_BasicJoints.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -604,8 +604,53 @@ addAngularRow( angle, globalOrient0 * Ogre::Vector3::UNIT_X ); } +/* +CustomDryRollingFriction::CustomDryRollingFriction( OgreNewt::Body* child, Ogre::Real radius, Ogre::Real rollingFrictionCoefficient ) : + OgreNewt::CustomJoint(1, child, NULL), + mChild(child) +{ + Ogre::Real mass; + Ogre::Vector3 inertia; + child->getMassMatrix( mass, inertia ); + mFrictionCoefficient = rollingFrictionCoefficient; + mFrictionTorque = inertia.x * radius; +} + +CustomDryRollingFriction::~CustomDryRollingFriction() +{ +} + + +// copied from CustomDryRollingFriction joint in newton +void CustomDryRollingFriction::submitConstraint( Ogre::Real timestep, int threadIndex ) +{ + Ogre::Vector3 omega; + Ogre::Real omegaMag; + Ogre::Real torqueFriction; + + + omega = mChild->getOmega(); + omegaMag = omega.length(); + + if( omegaMag > 0.1f ) + { + addAngularRow(Ogre::Radian(0), omega.normalisedCopy()); + setRowAcceleration( -omegaMag/timestep ); + torqueFriction = mFrictionTorque*mFrictionCoefficient; + setRowMinimumFriction(-torqueFriction); + setRowMaximumFriction(torqueFriction); + } + else + { + mChild->setOmega(omega*0.2f); + } + +} +*/ + + } // end NAMESPACE PrebuiltCustomJoints Modified: branches/ogrenewt/newton20/src/OgreNewt_Body.cpp =================================================================== --- branches/ogrenewt/newton20/src/OgreNewt_Body.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/src/OgreNewt_Body.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -23,6 +23,8 @@ m_transformcallback = NULL; m_buoyancycallback = NULL; + m_nodeupdateneeded = false; + m_body = NewtonCreateBody( m_world->getNewtonWorld(), col->getNewtonCollision() ); NewtonBodySetUserData( m_body, this ); @@ -100,8 +102,7 @@ void Body::standardTransformCallback( OgreNewt::Body* me, const Ogre::Quaternion& orient, const Ogre::Vector3& pos, int threadIndex ) { - me->m_node->setOrientation( orient ); - me->m_node->setPosition( pos ); + me->requestNodeUpdate(threadIndex); } @@ -140,11 +141,16 @@ m_node = node; if (m_body) { - setCustomTransformCallback( &Body::standardTransformCallback ); + if( m_node ) + setCustomTransformCallback( &Body::standardTransformCallback ); + else + setCustomTransformCallback( NULL ); + + updateNode(); } } -void Body::setPositionOrientation( const Ogre::Vector3& pos, const Ogre::Quaternion& orient ) +void Body::setPositionOrientation( const Ogre::Vector3& pos, const Ogre::Quaternion& orient, int threadIndex) { if (m_body) { @@ -155,8 +161,10 @@ if (m_node) { - m_node->setOrientation( orient ); - m_node->setPosition( pos ); + if( threadIndex != -1 ) + requestNodeUpdate(threadIndex); + else + updateNode(); } } } @@ -342,7 +350,10 @@ Ogre::Quaternion bodyorient; getPositionOrientation( bodypos, bodyorient ); - Ogre::Vector3 topoint = pos - bodypos; + Ogre::Vector3 localMassCenter = getCenterOfMass(); + Ogre::Vector3 globalMassCenter = bodyorient * localMassCenter; + + Ogre::Vector3 topoint = pos - bodypos - globalMassCenter; Ogre::Vector3 torque = topoint.crossProduct( force ); addForce( force ); @@ -371,7 +382,41 @@ return NULL; } +void Body::requestNodeUpdate( int threadIndex, bool forceNodeUpdate ) +{ + if( !m_node ) + return; + if( m_nodeupdateneeded && !forceNodeUpdate ) + return; + + m_nodeupdateneeded = true; + + m_world->addBodyUpdateNodeRequest( threadIndex, this ); +} + +void Body::updateNode() +{ + m_nodeupdateneeded = false; + + if( !m_node ) + return; + + Ogre::Vector3 pos; + Ogre::Quaternion orient; + getPositionOrientation(pos, orient); + +#ifndef WIN32 + m_world->ogreCriticalSectionLock(); +#endif + m_node->setPosition(pos); + m_node->setOrientation(orient); +#ifndef WIN32 + m_world->ogreCriticalSectionUnlock(); +#endif +} + + // -------------------------------------------------------------------------------------- Modified: branches/ogrenewt/newton20/src/OgreNewt_CollisionPrimitives.cpp =================================================================== --- branches/ogrenewt/newton20/src/OgreNewt_CollisionPrimitives.cpp 2009-07-25 11:11:25 UTC (rev 2721) +++ branches/ogrenewt/newton20/src/OgreNewt_CollisionPrimitives.cpp 2009-08-01 20:09:43 UTC (rev 2722) @@ -30,13 +30,13 @@ Box::Box(const World* world) : ConvexCollision( world ) {} - Box::Box( const World* world, const Ogre::Vector3& size, const Ogre::Quaternion& orient, const Ogre::Vector3& pos ) : ConvexCollision( world ) + Box::Box( const World* world, const Ogre::Vector3& size, int id, const Ogre::Quaternion& orient, const Ogre::Vector3& pos ) : ConvexCollision( world ) { float matrix[16]; OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] ); - m_col = NewtonCreateBox( m_world->getNewtonWorld(), (float)size.x, (float)size.y, (float)size.z, &matrix[0] ); + m_col = NewtonCreateBox( m_world->getNewtonWorld(), (float)size.x, (float)size.y, (float)size.z, id, &matrix[0] ); } @@ -45,13 +45,13 @@ Ellipsoid::Ellipsoid(const World* world) : ConvexCollision( world ) {} - Ellipsoid::Ellipsoid( const World* world, const Ogre::Vector3& size, const Ogre::Quaternion& orient, const Ogre::Vector3& pos ) : ConvexCollision( world ) + Ellipsoid::Ellipsoid( const World* world, const Ogre::Vector3& size, int id, const Ogre::Quaternion& orient, const Ogre::Vector3& pos ) : ConvexCollision( world ) { float matrix[16]; OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] ); - m_col = NewtonCreateSphere( m_world->getNewtonWorld(), (float)size.x, (float)size.y, (float)size.z, &matrix[0] ); + m_col = NewtonCreateSphere( m_world->getNewtonWorld(), (float)size.x, (float)size.y, (float)size.z, id, &matrix[0] ); } @@ -59,14 +59,14 @@ Cylinder::Cylinder(const World* world) : ConvexCollision( world ) {} - Cylinder::Cylinder( const World* world, Ogre::Real radius, Ogre::Real height, + Cylinder::Cylinder( const World* world, Ogre::Real radius, Ogre::Real height, int id, const Ogre::Quaternion& orient, const Ogre::Vector3& pos ) : ConvexCollision( world ) { float matrix[16]; OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] ); - m_col = NewtonCreateCylinder( m_world->getNewtonWorld(), (float)radius, (float)height, &matrix[0] ); + m_col = NewtonCreateCylinder( m_world->getNewtonWorld(), (float)radius, (float)height, id, &matrix[0] ); } @@ -74,14 +74,14 @@ Capsule::Capsule(const World* world) : ConvexCollision( world ) {} - Capsule::Capsule( const World* world, Ogre::Real radius, Ogre::Real height, + Capsule::Capsule( const World* world, Ogre::Real radius, Ogre::Real height, int id, const Ogre::Quaternion& orient, const Ogre::Vector3& pos ) : ConvexCollision( world ) { float matrix[16]; OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] ); - m_col = NewtonCreateCapsule( m_world->getNewtonWorld(), (float)radius, (float)height, &matrix[0] ); + m_col = NewtonCreateCapsule( m_world->getNewtonWorld(), (float)radius, (float)height, id, &matrix[0] ); } @@ -89,28 +89,28 @@ Cone::Cone(const World* world) : ConvexCollision( world ) {} - Cone::Cone( const World* world, Ogre::Real radius, Ogre::Real height, + Cone::Cone( const World* world, Ogre::Real radius, Ogre::Real height, int id, const Ogre::Quaternion& orient, const Ogre::Vector3& pos ) : ConvexCollision( world ) { float matrix[16]; OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] ); - m_col = NewtonCreateCone( m_world->getNewtonWorld(), (float)radius, (float)height, &matrix[0] ); + m_col = NewtonCreateCone( m_world->getNewtonWorld(), (float)radius, (float)height, id, &matrix[0] ); } // OgreNewt::CollisionPrimitives::ChamferCylinder ChamferCylinder::ChamferCylinder(const World* world) : ConvexCollision( world ) {} - ChamferCylinder::ChamferCylinder( const World* world, Ogre::Real radius, Ogre::Real height, + ChamferCylinder::ChamferCylinder( const World* world, Ogre::Real radius, Ogre::Real height, int id, const Ogre::Quaternion& orient, const Ogre::Vector3& pos ) : ConvexCollision( world ) { float matrix[16]; OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] ); - m_col = NewtonCreateChamferCylinder( m_world->getNewtonWorld(), (float)radius, (float)height, &matrix[0] ); + m_col = NewtonCreateChamferCylinder( m_world->getNewtonWorld(), (float)radius, (float)height, id, &matrix[0] ); } @@ -119,7 +119,7 @@ ConvexHull::ConvexHull(const World* world) : ConvexCollision( world ) {} - ConvexHull::ConvexHull( const World* world, Ogre::Entity* obj, const Ogre::Quaternion& orient, const Ogre::Vector3& pos, Ogre::Real tolerance, const Ogre::Vector3& forceScale ) : ConvexCollision( world ) + ConvexHull::ConvexHull( const World* world, Ogre::Entity* obj, int id, const Ogre::Quaternion& orient, const Ogre::Vector3& pos, Ogre::Real tolerance, const Ogre::Vector3& forceScale ) : ConvexCollision( world ) { Ogre::Vector3 scale(1.0,1.0,1.0); @@ -235,7 +235,7 @@ OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] ); //okay, let's try making the ConvexHull! - m_col = NewtonCreateConvexHull( m_world->getNewtonWorld(), (int)total_verts, (float*)&vertices[0].x, sizeof(Ogre::Vector3), tolerance, &matrix[0] ); + m_col = NewtonCreateConvexHull( m_world->getNewtonWorld(), (int)total_verts, (float*)&vertices[0].x, sizeof(Ogre::Vector3), tolerance, id, &matrix[0] ); delete []vertices; @@ -243,13 +243,13 @@ // OgreNewt::CollisionPrimitives::ConvexHull - ConvexHull::ConvexHull( const World* world, const Ogre::Vector3* verts, int vertcount, const Ogre::Quaternion& orient, const Ogre::Vector3& pos, Ogre::Real tolerance ) : ConvexCollision( world ) + ConvexHull::ConvexHull( const World* world, const Ogre::Vector3* verts, int vertcount, int id, const Ogre::Quaternion& orient, const Ogre::Vector3& pos, Ogre::Real tolerance ) : ConvexCollision( world ) { float matrix[16]; OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] ); //make the collision primitive. - m_col = NewtonCreateConvexHull( m_world->getNewtonWorld(), vertcount, (float*)&verts[0].x, sizeof(Ogre::Vector3), tolerance, &matrix[0]); + m_col = NewtonCreateConvexHull( m_world->getNewtonWorld(), vertcount, (float*)&verts[0].x, sizeof(Ogre::Vector3), tolerance, id, &matrix[0]); } @@ -260,11 +260,11 @@ } - TreeCollision::TreeCollision( const World* world, Ogre::Entity* obj, bool optimize, FaceWinding fw ) : Collision( world ) + TreeCollision::TreeCollision( const World* world, Ogre::Entity* obj, bool optimize, int id, FaceWinding fw ) : Collision( world ) { Ogre::Vector3 scale; - start(); + start(id); Ogre::MeshPtr mesh = obj->getMesh(); @@ -394,9 +394,9 @@ } - TreeCollision::TreeCollision(const OgreNewt::World *world, int numVertices, int numIndices, const float *vertices, const int *indices, bool optimize, FaceWinding fw) : OgreNewt::Collision( world ) + TreeCollision::TreeCollision(const OgreNewt::World *world, int numVertices, int numIndices, const float *vertices, const int *indices, bool optimize, int id, FaceWinding fw) : OgreNewt::Collision( world ) { - start(); + start(id); int numPolys = numIndices / 3; @@ -435,9 +435,9 @@ } - TreeCollision::TreeCollision( const World* world, int numVertices, Ogre::Vector3* vertices, Ogre::IndexData* indexData, bool optimize, FaceWinding fw) : Collision( world ) + TreeCollision::TreeCollision( const World* world, int numVertices, Ogre::Vector3* vertices, Ogre::IndexData* indexData, bool optimize, int id, FaceWinding fw) : Collision( world ) { - start(); + start(id); unsigned int numPolys = indexData->indexCount / 3; Ogre::HardwareIndexBufferSharedPtr hwIndexBuffer=indexData->indexBuffer; @@ -499,9 +499,9 @@ } - void TreeCollision::start() + void TreeCollision::start(int id) { - m_col = NewtonCreateTreeCollision( m_world->getNewtonWorld() ); + m_col = NewtonCreateTreeCollision( m_world->getNewtonWorld(), id ); NewtonTreeCollisionBeginBuild( m_col ); } @@ -546,11 +546,11 @@ { } - void TreeCollisionSceneParser::parseScene( Ogre::SceneNode *startNode, bool optimize, FaceWinding fw) + void TreeCollisionSceneParser::parseScene( Ogre::SceneNode *startNode, int id, bool optimize, FaceWinding fw) { count = 0; - start(); + start(id); // parse the individual nodes. Ogre::Quaternion rootOrient = Ogre::Quaternion::IDE... [truncated message content] |