From 5c80ff1f7d9468f0db120ce79c300b10f9ee6bcc Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Thu, 5 Jul 2007 23:48:05 +0000 Subject: [PATCH] improved performance by adding constructors to btTransform/btMatrix3x3 to avoid conversions, compoundshape returns const references (instead of duplicate objects) Thanks Marten Svanfeldt, Starbreeze Studios --- Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp | 35 ------------------- .../btCompoundCollisionAlgorithm.cpp | 12 +++---- .../CollisionShapes/btCompoundShape.h | 4 +-- src/LinearMath/btMatrix3x3.h | 15 ++++++++ src/LinearMath/btTransform.h | 13 +++++++ 5 files changed, 36 insertions(+), 43 deletions(-) diff --git a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp index 146b14518..ec4a191fe 100644 --- a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp +++ b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp @@ -302,41 +302,6 @@ void CcdPhysicsDemo::clientMoveAndDisplay() updateCamera(); -#ifdef CENTER_OF_MASS_SHIFT - btScalar m[16]; - - if (m_dynamicsWorld) - { - int numObjects = m_dynamicsWorld->getNumCollisionObjects(); - btVector3 wireColor(1,0,0); - for (int i=0;igetCollisionObjectArray()[i]; - btRigidBody* body = btRigidBody::upcast(colObj); - - if (body && body->getMotionState()) - { - btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState(); - btTransform offsetTrans = myMotionState->m_graphicsWorldTrans; - - - btVector3 worldShift = offsetTrans.getBasis() * comOffsetVec; - offsetTrans.setOrigin(offsetTrans.getOrigin() + worldShift); - - - offsetTrans.getOpenGLMatrix(m); - - btVector3 wireColor(1.f,1.0f,1.f); //wants deactivation - - btSphereShape sphereTmp(CUBE_HALF_EXTENTS); - - GL_ShapeDrawer::drawOpenGL(m,&sphereTmp,wireColor,0); - } - } - - } -#endif //CENTER_OF_MASS_SHIFT - #ifdef USE_QUICKPROF btProfiler::endBlock("render"); diff --git a/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp b/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp index 2f96c2e13..92f4c8b28 100644 --- a/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp +++ b/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp @@ -77,9 +77,9 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt btTransform orgTrans = colObj->getWorldTransform(); btCollisionShape* orgShape = colObj->getCollisionShape(); - btTransform childTrans = compoundShape->getChildTransform(i); - btTransform newChildWorldTrans = orgTrans*childTrans ; - colObj->setWorldTransform( newChildWorldTrans ); + const btTransform& childTrans = compoundShape->getChildTransform(i); + //btTransform newChildWorldTrans = orgTrans*childTrans ; + colObj->setWorldTransform( orgTrans*childTrans ); //the contactpoint is still projected back using the original inverted worldtrans colObj->setCollisionShape( childShape ); m_childCollisionAlgorithms[i]->processCollision(colObj,otherObj,dispatchInfo,resultOut); @@ -119,9 +119,9 @@ btScalar btCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* btTransform orgTrans = colObj->getWorldTransform(); btCollisionShape* orgShape = colObj->getCollisionShape(); - btTransform childTrans = compoundShape->getChildTransform(i); - btTransform newChildWorldTrans = orgTrans*childTrans ; - colObj->setWorldTransform( newChildWorldTrans ); + const btTransform& childTrans = compoundShape->getChildTransform(i); + //btTransform newChildWorldTrans = orgTrans*childTrans ; + colObj->setWorldTransform( orgTrans*childTrans ); colObj->setCollisionShape( childShape ); btScalar frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut); diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.h b/src/BulletCollision/CollisionShapes/btCompoundShape.h index 2d384bd21..86dc1f809 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.h +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.h @@ -58,11 +58,11 @@ public: return m_childShapes[index]; } - btTransform getChildTransform(int index) + btTransform& getChildTransform(int index) { return m_childTransforms[index]; } - const btTransform getChildTransform(int index) const + const btTransform& getChildTransform(int index) const { return m_childTransforms[index]; } diff --git a/src/LinearMath/btMatrix3x3.h b/src/LinearMath/btMatrix3x3.h index fda348b42..94f53c3c0 100644 --- a/src/LinearMath/btMatrix3x3.h +++ b/src/LinearMath/btMatrix3x3.h @@ -45,6 +45,21 @@ class btMatrix3x3 { zx, zy, zz); } + SIMD_FORCE_INLINE btMatrix3x3 (const btMatrix3x3& other) + { + m_el[0] = other.m_el[0]; + m_el[1] = other.m_el[1]; + m_el[2] = other.m_el[2]; + } + + SIMD_FORCE_INLINE btMatrix3x3& operator=(const btMatrix3x3& other) + { + m_el[0] = other.m_el[0]; + m_el[1] = other.m_el[1]; + m_el[2] = other.m_el[2]; + return *this; + } + SIMD_FORCE_INLINE btVector3 getColumn(int i) const { return btVector3(m_el[0][i],m_el[1][i],m_el[2][i]); diff --git a/src/LinearMath/btTransform.h b/src/LinearMath/btTransform.h index b1f3dfca4..2d55fec83 100644 --- a/src/LinearMath/btTransform.h +++ b/src/LinearMath/btTransform.h @@ -42,6 +42,19 @@ public: m_origin(c) {} + SIMD_FORCE_INLINE btTransform (const btTransform& other) + : m_basis(other.m_basis), + m_origin(other.m_origin) + { + } + + SIMD_FORCE_INLINE btTransform& operator=(const btTransform& other) + { + m_basis = other.m_basis; + m_origin = other.m_origin; + return *this; + } + SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2) { m_basis = t1.m_basis * t2.m_basis;