From 5e069f220e9c426e76b9cd221ca19e2be6f92924 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Fri, 18 Jun 2010 00:39:42 +0000 Subject: [PATCH] Issue 395: [Patch] implement btCompoundShape::createAabbTreeFromChildren Thanks Paul Dubois for the patch --- .../CollisionShapes/btCompoundShape.cpp | 21 +++++++++++++++++++ .../CollisionShapes/btCompoundShape.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp index 7087a703c..93df73baa 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp @@ -285,6 +285,27 @@ void btCompoundShape::setLocalScaling(const btVector3& scaling) } +void btCompoundShape::createAabbTreeFromChildren() +{ + if ( !m_dynamicAabbTree ) + { + void* mem = btAlignedAlloc(sizeof(btDbvt),16); + m_dynamicAabbTree = new(mem) btDbvt(); + btAssert(mem==m_dynamicAabbTree); + + for ( int index = 0; index < m_children.size(); index++ ) + { + btCompoundShapeChild &child = m_children[index]; + + //extend the local aabbMin/aabbMax + btVector3 localAabbMin,localAabbMax; + child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax); + + const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); + child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index); + } + } +} ///fills the dataBuffer and returns the struct name (and 0 on failure) diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.h b/src/BulletCollision/CollisionShapes/btCompoundShape.h index 179bb0091..95fc5a0b4 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.h +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.h @@ -149,6 +149,8 @@ public: return m_dynamicAabbTree; } + void createAabbTreeFromChildren(); + ///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia ///and the center of mass to the current coordinate system. "masses" points to an array of masses of the children. The resulting transform ///"principal" has to be applied inversely to all children transforms in order for the local coordinate system of the compound