From fd4ae96697eb6b645f82f8dd3015aa771632820b Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Fri, 4 Mar 2011 20:16:50 +0000 Subject: [PATCH] Performance optimization for btCompoundShape::setLocalScaling Thanks to Mirza, See Issue 487 backward compatibility fix for recent improvement in btRaycastVehicle 'rollinfluence' Thanks to Mihail, See Issue 468 --- .../CollisionShapes/btCompoundShape.cpp | 13 +++++++++---- .../CollisionShapes/btCompoundShape.h | 2 +- src/BulletDynamics/Vehicle/btRaycastVehicle.cpp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp index c4f3dffac..4eb860c57 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp @@ -85,7 +85,7 @@ void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisio } -void btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform) +void btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform,bool shouldRecalculateLocalAabb) { m_children[childIndex].m_transform = newChildTransform; @@ -99,7 +99,10 @@ void btCompoundShape::updateChildTransform(int childIndex, const btTransform& ne m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds); } - recalculateLocalAabb(); + if (shouldRecalculateLocalAabb) + { + recalculateLocalAabb(); + } } void btCompoundShape::removeChildShapeByIndex(int childShapeIndex) @@ -283,10 +286,12 @@ void btCompoundShape::setLocalScaling(const btVector3& scaling) childScale = childScale * scaling / m_localScaling; m_children[i].m_childShape->setLocalScaling(childScale); childTrans.setOrigin((childTrans.getOrigin())*scaling); - updateChildTransform(i, childTrans); - recalculateLocalAabb(); + updateChildTransform(i, childTrans,false); } + m_localScaling = scaling; + recalculateLocalAabb(); + } diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.h b/src/BulletCollision/CollisionShapes/btCompoundShape.h index fe9e9c203..7f41dd451 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.h +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.h @@ -106,7 +106,7 @@ public: } ///set a new transform for a child, and update internal data structures (local aabb and dynamic tree) - void updateChildTransform(int childIndex, const btTransform& newChildTransform); + void updateChildTransform(int childIndex, const btTransform& newChildTransform, bool shouldRecalculateLocalAabb = true); btCompoundShapeChild* getChildList() diff --git a/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp b/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp index af9163b5d..345dca6a1 100644 --- a/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp +++ b/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp @@ -699,7 +699,7 @@ void btRaycastVehicle::updateFriction(btScalar timeStep) #if defined ROLLING_INFLUENCE_FIX // fix. It only worked if car's up was along Y - VT. btVector3 vChassisWorldUp = getRigidBody()->getCenterOfMassTransform().getBasis().getColumn(1); - rel_pos -= vChassisWorldUp * (vChassisWorldUp.dot(rel_pos) * wheelInfo.m_rollInfluence); + rel_pos -= vChassisWorldUp * (vChassisWorldUp.dot(rel_pos) * (1.f-wheelInfo.m_rollInfluence)); #else rel_pos[m_indexUpAxis] *= wheelInfo.m_rollInfluence; #endif