mirror of
https://github.com/bulletphysics/bullet3
synced 2025-01-11 09:50:06 +00:00
bugfix: for btCompoundShape::getChildTransform: return (const) reference to btTransform, not a copy.
added btCompoundShape::updateChildTransform Thanks to ejtttje, see http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2831
This commit is contained in:
parent
463a1b74c1
commit
8865e38e5b
@ -17,7 +17,7 @@ subject to the following restrictions:
|
|||||||
#include "btCollisionShape.h"
|
#include "btCollisionShape.h"
|
||||||
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
||||||
|
|
||||||
btCompoundShape::btCompoundShape()
|
btCompoundShape::btCompoundShape(bool enableDynamicAabbTree)
|
||||||
: m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
|
: m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
|
||||||
m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
|
m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
|
||||||
m_collisionMargin(btScalar(0.)),
|
m_collisionMargin(btScalar(0.)),
|
||||||
@ -25,10 +25,14 @@ m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
|
|||||||
m_dynamicAabbTree(0)
|
m_dynamicAabbTree(0)
|
||||||
{
|
{
|
||||||
m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
|
m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
btCompoundShape::~btCompoundShape()
|
btCompoundShape::~btCompoundShape()
|
||||||
@ -76,6 +80,23 @@ void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisio
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform)
|
||||||
|
{
|
||||||
|
m_children[childIndex].m_transform = newChildTransform;
|
||||||
|
|
||||||
|
if (m_dynamicAabbTree)
|
||||||
|
{
|
||||||
|
///update the dynamic aabb tree
|
||||||
|
btVector3 localAabbMin,localAabbMax;
|
||||||
|
m_children[childIndex].m_childShape->getAabb(newChildTransform,localAabbMin,localAabbMax);
|
||||||
|
ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
|
||||||
|
int index = m_children.size()-1;
|
||||||
|
m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
recalculateLocalAabb();
|
||||||
|
}
|
||||||
|
|
||||||
void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
|
void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
|
||||||
{
|
{
|
||||||
btAssert(childShapeIndex >=0 && childShapeIndex < m_children.size());
|
btAssert(childShapeIndex >=0 && childShapeIndex < m_children.size());
|
||||||
@ -88,6 +109,8 @@ void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void btCompoundShape::removeChildShape(btCollisionShape* shape)
|
void btCompoundShape::removeChildShape(btCollisionShape* shape)
|
||||||
{
|
{
|
||||||
// Find the children containing the shape specified, and remove those children.
|
// Find the children containing the shape specified, and remove those children.
|
||||||
@ -99,6 +122,8 @@ void btCompoundShape::removeChildShape(btCollisionShape* shape)
|
|||||||
m_children.swap(i,m_children.size()-1);
|
m_children.swap(i,m_children.size()-1);
|
||||||
m_children.pop_back();
|
m_children.pop_back();
|
||||||
//remove it from the m_dynamicAabbTree too
|
//remove it from the m_dynamicAabbTree too
|
||||||
|
//@todo: this leads to problems due to caching in the btCompoundCollisionAlgorithm
|
||||||
|
//so effectively, removeChildShape is broken at the moment
|
||||||
//m_dynamicAabbTree->remove(m_aabbProxies[i]);
|
//m_dynamicAabbTree->remove(m_aabbProxies[i]);
|
||||||
//m_aabbProxies.swap(i,m_children.size()-1);
|
//m_aabbProxies.swap(i,m_children.size()-1);
|
||||||
//m_aabbProxies.pop_back();
|
//m_aabbProxies.pop_back();
|
||||||
|
@ -46,23 +46,23 @@ SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompou
|
|||||||
c1.m_childMargin == c2.m_childMargin );
|
c1.m_childMargin == c2.m_childMargin );
|
||||||
}
|
}
|
||||||
|
|
||||||
/// btCompoundShape allows to store multiple other btCollisionShapes
|
/// The btCompoundShape allows to store multiple other btCollisionShapes
|
||||||
/// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape.
|
/// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape.
|
||||||
|
/// It has an (optional) dynamic aabb tree to accelerate early rejection tests.
|
||||||
|
/// @todo: This aabb tree can also be use to speed up ray tests on btCompoundShape, see http://code.google.com/p/bullet/issues/detail?id=25
|
||||||
|
/// Currently, removal of child shapes is only supported when disabling the aabb tree (pass 'false' in the constructor of btCompoundShape)
|
||||||
ATTRIBUTE_ALIGNED16(class) btCompoundShape : public btCollisionShape
|
ATTRIBUTE_ALIGNED16(class) btCompoundShape : public btCollisionShape
|
||||||
{
|
{
|
||||||
//btAlignedObjectArray<btTransform> m_childTransforms;
|
|
||||||
//btAlignedObjectArray<btCollisionShape*> m_childShapes;
|
|
||||||
btAlignedObjectArray<btCompoundShapeChild> m_children;
|
btAlignedObjectArray<btCompoundShapeChild> m_children;
|
||||||
btVector3 m_localAabbMin;
|
btVector3 m_localAabbMin;
|
||||||
btVector3 m_localAabbMax;
|
btVector3 m_localAabbMax;
|
||||||
|
|
||||||
//btOptimizedBvh* m_aabbTree;
|
|
||||||
btDbvt* m_dynamicAabbTree;
|
btDbvt* m_dynamicAabbTree;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
btCompoundShape();
|
btCompoundShape(bool enableDynamicAabbTree = true);
|
||||||
|
|
||||||
virtual ~btCompoundShape();
|
virtual ~btCompoundShape();
|
||||||
|
|
||||||
@ -88,15 +88,18 @@ public:
|
|||||||
return m_children[index].m_childShape;
|
return m_children[index].m_childShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
btTransform getChildTransform(int index)
|
btTransform& getChildTransform(int index)
|
||||||
{
|
{
|
||||||
return m_children[index].m_transform;
|
return m_children[index].m_transform;
|
||||||
}
|
}
|
||||||
const btTransform getChildTransform(int index) const
|
const btTransform& getChildTransform(int index) const
|
||||||
{
|
{
|
||||||
return m_children[index].m_transform;
|
return m_children[index].m_transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///set a new transform for a child, and update internal data structures (local aabb and dynamic tree)
|
||||||
|
void updateChildTransform(int childIndex, const btTransform& newChildTransform);
|
||||||
|
|
||||||
|
|
||||||
btCompoundShapeChild* getChildList()
|
btCompoundShapeChild* getChildList()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user