diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp index 114a1f4c1..740f17836 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp @@ -62,9 +62,53 @@ void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisio } } +void btCompoundShape::removeChildShape(btCollisionShape* shape) +{ + bool done_removing; + + // Find the children containing the shape specified, and remove those children. + do + { + done_removing = true; + + for(int i = 0; i < m_children.size(); i++) + { + if(m_children[i].m_childShape == shape) + { + m_children.remove(m_children[i]); + done_removing = false; // Do another iteration pass after removing from the vector + break; + } + } + } + while (!done_removing); + + recalculateLocalAabb(); +} - - ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version +void btCompoundShape::recalculateLocalAabb() +{ + // Recalculate the local aabb + // Brute force, it iterates over all the shapes left. + m_localAabbMin = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30)); + m_localAabbMax = btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)); + + //extend the local aabbMin/aabbMax + for (int j = 0; j < m_children.size(); j++) + { + btVector3 localAabbMin,localAabbMax; + m_children[j].m_childShape->getAabb(m_children[j].m_transform, localAabbMin, localAabbMax); + for (int i=0;i<3;i++) + { + if (m_localAabbMin[i] > localAabbMin[i]) + m_localAabbMin[i] = localAabbMin[i]; + if (m_localAabbMax[i] < localAabbMax[i]) + m_localAabbMax[i] = localAabbMax[i]; + } + } +} + + ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const { btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin); diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.h b/src/BulletCollision/CollisionShapes/btCompoundShape.h index 2f92bfd1f..096680c23 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.h +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.h @@ -36,7 +36,15 @@ ATTRIBUTE_ALIGNED16(struct) btCompoundShapeChild int m_childShapeType; btScalar m_childMargin; }; - + +SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompoundShapeChild& c2) +{ + return ( c1.m_transform == c2.m_transform && + c1.m_childShape == c2.m_childShape && + c1.m_childShapeType == c2.m_childShapeType && + c1.m_childMargin == c2.m_childMargin ); +} + /// btCompoundShape allows to store multiple other btCollisionShapes /// This allows for concave collision objects. This is more general then the Static Concave btTriangleMeshShape. ATTRIBUTE_ALIGNED16(class) btCompoundShape : public btCollisionShape @@ -58,6 +66,12 @@ public: void addChildShape(const btTransform& localTransform,btCollisionShape* shape); + /** Remove all children shapes that contain the specified shape. */ + virtual void removeChildShape(btCollisionShape* shape); + + + + int getNumChildShapes() const { return int (m_children.size()); @@ -88,8 +102,11 @@ public: } ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version - void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; - + virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; + + /** Re-calculate the local Aabb. Is called at the end of removeChildShapes. + Use this yourself if you modify the children or their transforms. */ + virtual void recalculateLocalAabb(); virtual void setLocalScaling(const btVector3& scaling) { diff --git a/src/LinearMath/btMatrix3x3.h b/src/LinearMath/btMatrix3x3.h index 59680ff46..4c038d140 100644 --- a/src/LinearMath/btMatrix3x3.h +++ b/src/LinearMath/btMatrix3x3.h @@ -406,5 +406,11 @@ class btMatrix3x3 { } */ +SIMD_FORCE_INLINE bool operator==(const btMatrix3x3& m1, const btMatrix3x3& m2) +{ + return ( m1[0][0] == m2[0][0] && m1[1][0] == m2[1][0] && m1[2][0] == m2[2][0] && + m1[0][1] == m2[0][1] && m1[1][1] == m2[1][1] && m1[2][1] == m2[2][1] && + m1[0][2] == m2[0][2] && m1[1][2] == m2[1][2] && m1[2][2] == m2[2][2] ); +} #endif diff --git a/src/LinearMath/btTransform.h b/src/LinearMath/btTransform.h index 883b3a5d2..168cf8623 100644 --- a/src/LinearMath/btTransform.h +++ b/src/LinearMath/btTransform.h @@ -188,8 +188,13 @@ btTransform::operator*(const btTransform& t) const { return btTransform(m_basis * t.m_basis, (*this)(t.m_origin)); -} +} +SIMD_FORCE_INLINE bool operator==(const btTransform& t1, const btTransform& t2) +{ + return ( t1.getBasis() == t2.getBasis() && + t1.getOrigin() == t2.getOrigin() ); +} #endif @@ -198,3 +203,4 @@ btTransform::operator*(const btTransform& t) const +