Changeset View
Changeset View
Standalone View
Standalone View
extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp
| Show All 12 Lines | |||||
| 3. This notice may not be removed or altered from any source distribution. | 3. This notice may not be removed or altered from any source distribution. | ||||
| */ | */ | ||||
| #include "btCompoundShape.h" | #include "btCompoundShape.h" | ||||
| #include "btCollisionShape.h" | #include "btCollisionShape.h" | ||||
| #include "BulletCollision/BroadphaseCollision/btDbvt.h" | #include "BulletCollision/BroadphaseCollision/btDbvt.h" | ||||
| #include "LinearMath/btSerializer.h" | #include "LinearMath/btSerializer.h" | ||||
| btCompoundShape::btCompoundShape(bool enableDynamicAabbTree) | btCompoundShape::btCompoundShape(bool enableDynamicAabbTree, const int initialChildCapacity) | ||||
| : m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)), | : m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)), | ||||
| m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)), | m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)), | ||||
| m_dynamicAabbTree(0), | m_dynamicAabbTree(0), | ||||
| m_updateRevision(1), | m_updateRevision(1), | ||||
| m_collisionMargin(btScalar(0.)), | m_collisionMargin(btScalar(0.)), | ||||
| m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)) | m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)) | ||||
| { | { | ||||
| m_shapeType = COMPOUND_SHAPE_PROXYTYPE; | m_shapeType = COMPOUND_SHAPE_PROXYTYPE; | ||||
| if (enableDynamicAabbTree) | if (enableDynamicAabbTree) | ||||
| { | { | ||||
| void* mem = btAlignedAlloc(sizeof(btDbvt),16); | void* mem = btAlignedAlloc(sizeof(btDbvt),16); | ||||
| m_dynamicAabbTree = new(mem) btDbvt(); | m_dynamicAabbTree = new(mem) btDbvt(); | ||||
| btAssert(mem==m_dynamicAabbTree); | btAssert(mem==m_dynamicAabbTree); | ||||
| } | } | ||||
| m_children.reserve(initialChildCapacity); | |||||
| } | } | ||||
| btCompoundShape::~btCompoundShape() | btCompoundShape::~btCompoundShape() | ||||
| { | { | ||||
| if (m_dynamicAabbTree) | if (m_dynamicAabbTree) | ||||
| { | { | ||||
| m_dynamicAabbTree->~btDbvt(); | m_dynamicAabbTree->~btDbvt(); | ||||
| Show All 27 Lines | for (int i=0;i<3;i++) | ||||
| { | { | ||||
| m_localAabbMax[i] = localAabbMax[i]; | m_localAabbMax[i] = localAabbMax[i]; | ||||
| } | } | ||||
| } | } | ||||
| if (m_dynamicAabbTree) | if (m_dynamicAabbTree) | ||||
| { | { | ||||
| const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); | const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); | ||||
| int index = m_children.size(); | size_t index = m_children.size(); | ||||
| child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index); | child.m_node = m_dynamicAabbTree->insert(bounds,reinterpret_cast<void*>(index) ); | ||||
| } | } | ||||
| m_children.push_back(child); | m_children.push_back(child); | ||||
| } | } | ||||
| void btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform,bool shouldRecalculateLocalAabb) | void btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform,bool shouldRecalculateLocalAabb) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | if ( !m_dynamicAabbTree ) | ||||
| { | { | ||||
| btCompoundShapeChild &child = m_children[index]; | btCompoundShapeChild &child = m_children[index]; | ||||
| //extend the local aabbMin/aabbMax | //extend the local aabbMin/aabbMax | ||||
| btVector3 localAabbMin,localAabbMax; | btVector3 localAabbMin,localAabbMax; | ||||
| child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax); | child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax); | ||||
| const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); | const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); | ||||
| child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index); | size_t index2 = index; | ||||
| child.m_node = m_dynamicAabbTree->insert(bounds, reinterpret_cast<void*>(index2) ); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ///fills the dataBuffer and returns the struct name (and 0 on failure) | ///fills the dataBuffer and returns the struct name (and 0 on failure) | ||||
| const char* btCompoundShape::serialize(void* dataBuffer, btSerializer* serializer) const | const char* btCompoundShape::serialize(void* dataBuffer, btSerializer* serializer) const | ||||
| { | { | ||||
| Show All 33 Lines | |||||