From 38b7f474c3bac6bf584642f4255389e8c5b3ebcf Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Sat, 28 Jul 2007 21:10:21 +0000 Subject: [PATCH] Added better support for btUniformScalingShape, by moving some data that is not shared from btConvexShape to btConvexInternalShape. This reduces the sizeof btUniformScalingShape to 16 bytes (from 64). This is good when having lots of re-used shapes with different sizes. Convex shapes will need to derive from btConvexInternalShape (which is a subclass of btConvexShape). We could have renamed btConvexShape to 'btConvexShapeInterface' (can still do that later) --- .../SpuGatheringCollisionTask.cpp | 8 +- .../SpuLocalSupport.h | 6 +- .../CollisionShapes/btCapsuleShape.h | 4 +- .../CollisionShapes/btConvexInternalShape.cpp | 77 +++++++++++++++ .../CollisionShapes/btConvexInternalShape.h | 99 +++++++++++++++++++ .../CollisionShapes/btConvexShape.cpp | 59 ----------- .../CollisionShapes/btConvexShape.h | 81 +++------------ .../CollisionShapes/btMinkowskiSumShape.h | 4 +- .../CollisionShapes/btMultiSphereShape.h | 4 +- .../CollisionShapes/btPolyhedralConvexShape.h | 4 +- .../CollisionShapes/btSphereShape.h | 8 +- .../CollisionShapes/btUniformScalingShape.cpp | 61 ++++++++++++ .../CollisionShapes/btUniformScalingShape.h | 22 +++++ src/btBulletCollisionCommon.h | 3 +- 14 files changed, 294 insertions(+), 146 deletions(-) create mode 100644 src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp create mode 100644 src/BulletCollision/CollisionShapes/btConvexInternalShape.h diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp index a0aea6adc..6d63b0f86 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp @@ -306,7 +306,7 @@ void ProcessConvexConcaveSpuCollision(SpuCollisionPairInput* wuInput, CollisionT //recalc aabbs btTransform convexInTriangleSpace; convexInTriangleSpace = wuInput->m_worldTransform1.inverse() * wuInput->m_worldTransform0; - btConvexShape* convexShape = (btConvexShape*)wuInput->m_spuCollisionShapes[0]; + btConvexInternalShape* convexShape = (btConvexInternalShape*)wuInput->m_spuCollisionShapes[0]; //calculate the aabb, given the types... switch (wuInput->m_shapeType0) { @@ -878,8 +878,8 @@ void processCollisionTask(void* userPtr, void* lsMemPtr) cellDmaWaitTagStatusAll(DMA_MASK(2)); } - btConvexShape* spuConvexShape0 = (btConvexShape*)lsMem.gCollisionShape0; - btConvexShape* spuConvexShape1 = (btConvexShape*)lsMem.gCollisionShape1; + btConvexInternalShape* spuConvexShape0 = (btConvexInternalShape*)lsMem.gCollisionShape0; + btConvexInternalShape* spuConvexShape1 = (btConvexInternalShape*)lsMem.gCollisionShape1; btVector3 dim0 = spuConvexShape0->getImplicitShapeDimensions(); btVector3 dim1 = spuConvexShape1->getImplicitShapeDimensions(); @@ -943,7 +943,7 @@ void processCollisionTask(void* userPtr, void* lsMemPtr) cellDmaGet(lsMem.gCollisionShape1, dmaPpuAddress2 , dmaSize, DMA_TAG(2), 0, 0); cellDmaWaitTagStatusAll(DMA_MASK(2)); } - btConvexShape* spuConvexShape0 = (btConvexShape*)lsMem.gCollisionShape0; + btConvexInternalShape* spuConvexShape0 = (btConvexInternalShape*)lsMem.gCollisionShape0; btBvhTriangleMeshShape* trimeshShape = (btBvhTriangleMeshShape*)lsMem.gCollisionShape1; btVector3 dim0 = spuConvexShape0->getImplicitShapeDimensions(); diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuLocalSupport.h b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuLocalSupport.h index 388c56343..a46e9eae7 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuLocalSupport.h +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuLocalSupport.h @@ -17,7 +17,7 @@ subject to the following restrictions: #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" -#include "BulletCollision/CollisionShapes/btConvexShape.h" +#include "BulletCollision/CollisionShapes/btConvexInternalShape.h" #include "BulletCollision/CollisionShapes/btCylinderShape.h" #define MAX_NUM_SPU_CONVEX_POINTS 128 @@ -47,7 +47,7 @@ inline btPoint3 localGetSupportingVertexWithoutMargin(int shapeType, void* shape case BOX_SHAPE_PROXYTYPE: { // spu_printf("SPU: getSupport BOX_SHAPE_PROXYTYPE\n"); - btConvexShape* convexShape = (btConvexShape*)shape; + btConvexInternalShape* convexShape = (btConvexInternalShape*)shape; btVector3 halfExtents = convexShape->getImplicitShapeDimensions(); float margin = convexShape->getMarginNV(); halfExtents -= btVector3(margin,margin,margin); @@ -137,7 +137,7 @@ inline btPoint3 localGetSupportingVertexWithoutMargin(int shapeType, void* shape //spu_printf("SPU: todo: getSupport CAPSULE_SHAPE_PROXYTYPE\n"); btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ()); - btConvexShape* cnvxShape = (btConvexShape*)shape; + btConvexInternalShape* cnvxShape = (btConvexInternalShape*)shape; btVector3 halfExtents = cnvxShape->getImplicitShapeDimensions(); btScalar halfHeight = halfExtents.getY(); btScalar radius = halfExtents.getX(); diff --git a/src/BulletCollision/CollisionShapes/btCapsuleShape.h b/src/BulletCollision/CollisionShapes/btCapsuleShape.h index 294c4a264..644af64c9 100644 --- a/src/BulletCollision/CollisionShapes/btCapsuleShape.h +++ b/src/BulletCollision/CollisionShapes/btCapsuleShape.h @@ -16,13 +16,13 @@ subject to the following restrictions: #ifndef BT_CAPSULE_SHAPE_H #define BT_CAPSULE_SHAPE_H -#include "btConvexShape.h" +#include "btConvexInternalShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types ///btCapsuleShape represents a capsule around the Y axis ///A more general solution that can represent capsules is the btMultiSphereShape -class btCapsuleShape : public btConvexShape +class btCapsuleShape : public btConvexInternalShape { public: diff --git a/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp b/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp new file mode 100644 index 000000000..c3613cf28 --- /dev/null +++ b/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp @@ -0,0 +1,77 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "btConvexInternalShape.h" + + +btConvexInternalShape::btConvexInternalShape() +: m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)), +m_collisionMargin(CONVEX_DISTANCE_MARGIN) +{ +} + + +void btConvexInternalShape::setLocalScaling(const btVector3& scaling) +{ + m_localScaling = scaling; +} + + + +void btConvexInternalShape::getAabbSlow(const btTransform& trans,btVector3&minAabb,btVector3&maxAabb) const +{ + + btScalar margin = getMargin(); + for (int i=0;i<3;i++) + { + btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.)); + vec[i] = btScalar(1.); + + btVector3 sv = localGetSupportingVertex(vec*trans.getBasis()); + + btVector3 tmp = trans(sv); + maxAabb[i] = tmp[i]+margin; + vec[i] = btScalar(-1.); + tmp = trans(localGetSupportingVertex(vec*trans.getBasis())); + minAabb[i] = tmp[i]-margin; + } +}; + + +btVector3 btConvexInternalShape::localGetSupportingVertex(const btVector3& vec)const +{ +#ifndef __SPU__ + + btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec); + + if ( getMargin()!=btScalar(0.) ) + { + btVector3 vecnorm = vec; + if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON)) + { + vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.)); + } + vecnorm.normalize(); + supVertex+= getMargin() * vecnorm; + } + return supVertex; + +#else + return btVector3(0,0,0); +#endif //__SPU__ + + } + + diff --git a/src/BulletCollision/CollisionShapes/btConvexInternalShape.h b/src/BulletCollision/CollisionShapes/btConvexInternalShape.h new file mode 100644 index 000000000..a03af873b --- /dev/null +++ b/src/BulletCollision/CollisionShapes/btConvexInternalShape.h @@ -0,0 +1,99 @@ + +#ifndef BT_CONVEX_INTERNAL_SHAPE_H +#define BT_CONVEX_INTERNAL_SHAPE_H + +#include "btConvexShape.h" + +///btConvexInternalShape carries some additional data, shared by most implementations +class btConvexInternalShape : public btConvexShape +{ + + protected: + + //local scaling. collisionMargin is not scaled ! + btVector3 m_localScaling; + + btVector3 m_implicitShapeDimensions; + + btScalar m_collisionMargin; + + btScalar m_padding[2]; + + + + +public: + + btConvexInternalShape(); + + virtual ~btConvexInternalShape() + { + + } + + + virtual btVector3 localGetSupportingVertex(const btVector3& vec)const; +#ifndef __SPU__ + virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0; + + //notice that the vectors should be unit length + virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0; +#endif //#ifndef __SPU__ + + const btVector3& getImplicitShapeDimensions() const + { + return m_implicitShapeDimensions; + } + + ///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 + { + getAabbSlow(t,aabbMin,aabbMax); + } + + + + virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; + + + virtual void setLocalScaling(const btVector3& scaling); + virtual const btVector3& getLocalScaling() const + { + return m_localScaling; + } + + const btVector3& getLocalScalingNV() const + { + return m_localScaling; + } + + virtual void setMargin(btScalar margin) + { + m_collisionMargin = margin; + } + virtual btScalar getMargin() const + { + return m_collisionMargin; + } + + btScalar getMarginNV() const + { + return m_collisionMargin; + } + + virtual int getNumPreferredPenetrationDirections() const + { + return 0; + } + + virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const + { + (void)penetrationVector; + (void)index; + btAssert(0); + } + +}; + + +#endif //BT_CONVEX_INTERNAL_SHAPE_H diff --git a/src/BulletCollision/CollisionShapes/btConvexShape.cpp b/src/BulletCollision/CollisionShapes/btConvexShape.cpp index 7edf1ea6d..7afcccf8b 100644 --- a/src/BulletCollision/CollisionShapes/btConvexShape.cpp +++ b/src/BulletCollision/CollisionShapes/btConvexShape.cpp @@ -16,62 +16,3 @@ subject to the following restrictions: #include "btConvexShape.h" -btConvexShape::btConvexShape() -: m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)), -m_collisionMargin(CONVEX_DISTANCE_MARGIN) -{ -} - - -void btConvexShape::setLocalScaling(const btVector3& scaling) -{ - m_localScaling = scaling; -} - - - -void btConvexShape::getAabbSlow(const btTransform& trans,btVector3&minAabb,btVector3&maxAabb) const -{ - - btScalar margin = getMargin(); - for (int i=0;i<3;i++) - { - btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.)); - vec[i] = btScalar(1.); - - btVector3 sv = localGetSupportingVertex(vec*trans.getBasis()); - - btVector3 tmp = trans(sv); - maxAabb[i] = tmp[i]+margin; - vec[i] = btScalar(-1.); - tmp = trans(localGetSupportingVertex(vec*trans.getBasis())); - minAabb[i] = tmp[i]-margin; - } -}; - - -btVector3 btConvexShape::localGetSupportingVertex(const btVector3& vec)const -{ -#ifndef __SPU__ - - btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec); - - if ( getMargin()!=btScalar(0.) ) - { - btVector3 vecnorm = vec; - if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON)) - { - vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.)); - } - vecnorm.normalize(); - supVertex+= getMargin() * vecnorm; - } - return supVertex; - -#else - return btVector3(0,0,0); -#endif //__SPU__ - - } - - diff --git a/src/BulletCollision/CollisionShapes/btConvexShape.h b/src/BulletCollision/CollisionShapes/btConvexShape.h index 7f2f9d75f..087e62861 100644 --- a/src/BulletCollision/CollisionShapes/btConvexShape.h +++ b/src/BulletCollision/CollisionShapes/btConvexShape.h @@ -28,27 +28,13 @@ struct btConvexCastResult; #define MAX_PREFERRED_PENETRATION_DIRECTIONS 10 /// btConvexShape is an abstract shape interface. -/// The explicit part provides plane-equations, the implicit part provides GetClosestPoint interface. +/// It describes general convex shapes using the localGetSupportingVertex interface /// used in combination with GJK or btConvexCast ATTRIBUTE_ALIGNED16(class) btConvexShape : public btCollisionShape { -protected: - - //local scaling. collisionMargin is not scaled ! - btVector3 m_localScaling; - - btVector3 m_implicitShapeDimensions; - - btScalar m_collisionMargin; - - btScalar m_padding[2]; - - - public: - btConvexShape(); virtual ~btConvexShape() { @@ -56,7 +42,7 @@ public: } - virtual btVector3 localGetSupportingVertex(const btVector3& vec)const; + virtual btVector3 localGetSupportingVertex(const btVector3& vec)const =0; #ifndef __SPU__ virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0; @@ -64,63 +50,24 @@ public: virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0; #endif //#ifndef __SPU__ - const btVector3& getImplicitShapeDimensions() const - { - return m_implicitShapeDimensions; - } ///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 - { - getAabbSlow(t,aabbMin,aabbMax); - } + void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0; + virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0; + virtual void setLocalScaling(const btVector3& scaling) =0; + virtual const btVector3& getLocalScaling() const =0; + + virtual void setMargin(btScalar margin)=0; + + virtual btScalar getMargin() const=0; + + virtual int getNumPreferredPenetrationDirections() const=0; - virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; + virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const=0; - - virtual void setLocalScaling(const btVector3& scaling); - virtual const btVector3& getLocalScaling() const - { - return m_localScaling; - } - - const btVector3& getLocalScalingNV() const - { - return m_localScaling; - } - - virtual void setMargin(btScalar margin) - { - m_collisionMargin = margin; - } - virtual btScalar getMargin() const - { - return m_collisionMargin; - } - - btScalar getMarginNV() const - { - return m_collisionMargin; - } - - virtual int getNumPreferredPenetrationDirections() const - { - return 0; - } - - virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const - { - (void)penetrationVector; - (void)index; - btAssert(0); - } - - - -} -; +}; diff --git a/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h b/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h index b586cbcb3..9a36a7493 100644 --- a/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h +++ b/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h @@ -16,11 +16,11 @@ subject to the following restrictions: #ifndef MINKOWSKI_SUM_SHAPE_H #define MINKOWSKI_SUM_SHAPE_H -#include "btConvexShape.h" +#include "btConvexInternalShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types /// btMinkowskiSumShape represents implicit (getSupportingVertex) based minkowski sum of two convex implicit shapes. -class btMinkowskiSumShape : public btConvexShape +class btMinkowskiSumShape : public btConvexInternalShape { btTransform m_transA; diff --git a/src/BulletCollision/CollisionShapes/btMultiSphereShape.h b/src/BulletCollision/CollisionShapes/btMultiSphereShape.h index 57ed90604..b22630e68 100644 --- a/src/BulletCollision/CollisionShapes/btMultiSphereShape.h +++ b/src/BulletCollision/CollisionShapes/btMultiSphereShape.h @@ -16,13 +16,13 @@ subject to the following restrictions: #ifndef MULTI_SPHERE_MINKOWSKI_H #define MULTI_SPHERE_MINKOWSKI_H -#include "btConvexShape.h" +#include "btConvexInternalShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types #define MAX_NUM_SPHERES 5 ///btMultiSphereShape represents implicit convex hull of a collection of spheres (using getSupportingVertex) -class btMultiSphereShape : public btConvexShape +class btMultiSphereShape : public btConvexInternalShape { diff --git a/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h b/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h index 9e712081d..2c0462d0c 100644 --- a/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h +++ b/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h @@ -18,11 +18,11 @@ subject to the following restrictions: #include "LinearMath/btPoint3.h" #include "LinearMath/btMatrix3x3.h" -#include "btConvexShape.h" +#include "btConvexInternalShape.h" ///PolyhedralConvexShape is an interface class for feature based (vertex/edge/face) convex shapes. -class btPolyhedralConvexShape : public btConvexShape +class btPolyhedralConvexShape : public btConvexInternalShape { protected: diff --git a/src/BulletCollision/CollisionShapes/btSphereShape.h b/src/BulletCollision/CollisionShapes/btSphereShape.h index 256c89983..1489789c2 100644 --- a/src/BulletCollision/CollisionShapes/btSphereShape.h +++ b/src/BulletCollision/CollisionShapes/btSphereShape.h @@ -16,11 +16,11 @@ subject to the following restrictions: #ifndef SPHERE_MINKOWSKI_H #define SPHERE_MINKOWSKI_H -#include "btConvexShape.h" +#include "btConvexInternalShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types ///btSphereShape implements an implicit (getSupportingVertex) Sphere -ATTRIBUTE_ALIGNED16(class) btSphereShape : public btConvexShape +ATTRIBUTE_ALIGNED16(class) btSphereShape : public btConvexInternalShape { @@ -47,13 +47,13 @@ public: virtual void setMargin(btScalar margin) { - btConvexShape::setMargin(margin); + btConvexInternalShape::setMargin(margin); } virtual btScalar getMargin() const { //to improve gjk behaviour, use radius+margin as the full margin, so never get into the penetration case //this means, non-uniform scaling is not supported anymore - return m_localScaling.getX() * getRadius() + btConvexShape::getMargin(); + return m_localScaling.getX() * getRadius() + btConvexInternalShape::getMargin(); } diff --git a/src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp b/src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp index 65089e6b1..772806a0a 100644 --- a/src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp +++ b/src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp @@ -43,6 +43,15 @@ void btUniformScalingShape::batchedUnitVectorGetSupportingVertexWithoutMargin(co } } + +btVector3 btUniformScalingShape::localGetSupportingVertex(const btVector3& vec)const +{ + btVector3 tmpVertex; + tmpVertex = m_childConvexShape->localGetSupportingVertex(vec); + return tmpVertex*m_uniformScalingFactor; +} + + void btUniformScalingShape::calculateLocalInertia(btScalar mass,btVector3& inertia) { @@ -51,3 +60,55 @@ void btUniformScalingShape::calculateLocalInertia(btScalar mass,btVector3& inert m_childConvexShape->calculateLocalInertia(mass,tmpInertia); inertia = tmpInertia * m_uniformScalingFactor; } + + + ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version +void btUniformScalingShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const +{ + m_childConvexShape->getAabb(t,aabbMin,aabbMax); + btVector3 aabbCenter = (aabbMax+aabbMin)*btScalar(0.5); + btVector3 scaledAabbHalfExtends = (aabbMax-aabbMin)*btScalar(0.5)*m_uniformScalingFactor; + + aabbMin = aabbCenter - scaledAabbHalfExtends; + aabbMax = aabbCenter + scaledAabbHalfExtends; + +} + +void btUniformScalingShape::getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const +{ + m_childConvexShape->getAabbSlow(t,aabbMin,aabbMax); + btVector3 aabbCenter = (aabbMax+aabbMin)*btScalar(0.5); + btVector3 scaledAabbHalfExtends = (aabbMax-aabbMin)*btScalar(0.5)*m_uniformScalingFactor; + + aabbMin = aabbCenter - scaledAabbHalfExtends; + aabbMax = aabbCenter + scaledAabbHalfExtends; +} + +void btUniformScalingShape::setLocalScaling(const btVector3& scaling) +{ + m_childConvexShape->setLocalScaling(scaling); +} + +const btVector3& btUniformScalingShape::getLocalScaling() const +{ + return m_childConvexShape->getLocalScaling(); +} + +void btUniformScalingShape::setMargin(btScalar margin) +{ + m_childConvexShape->setMargin(margin); +} +btScalar btUniformScalingShape::getMargin() const +{ + return m_childConvexShape->getMargin() * m_uniformScalingFactor; +} + +int btUniformScalingShape::getNumPreferredPenetrationDirections() const +{ + return m_childConvexShape->getNumPreferredPenetrationDirections(); +} + +void btUniformScalingShape::getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const +{ + return m_childConvexShape->getPreferredPenetrationDirection(index,penetrationVector); +} diff --git a/src/BulletCollision/CollisionShapes/btUniformScalingShape.h b/src/BulletCollision/CollisionShapes/btUniformScalingShape.h index 87692f101..b066321f0 100644 --- a/src/BulletCollision/CollisionShapes/btUniformScalingShape.h +++ b/src/BulletCollision/CollisionShapes/btUniformScalingShape.h @@ -33,6 +33,8 @@ class btUniformScalingShape : public btConvexShape virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const; + virtual btVector3 localGetSupportingVertex(const btVector3& vec)const; + virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; virtual void calculateLocalInertia(btScalar mass,btVector3& inertia); @@ -58,7 +60,27 @@ class btUniformScalingShape : public btConvexShape } virtual int getShapeType() const { return UNIFORM_SCALING_SHAPE_PROXYTYPE; } + + + /////////////////////////// + + + ///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 getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; + + virtual void setLocalScaling(const btVector3& scaling) ; + virtual const btVector3& getLocalScaling() const ; + + virtual void setMargin(btScalar margin); + virtual btScalar getMargin() const; + + virtual int getNumPreferredPenetrationDirections() const; + virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const; + + }; #endif //BT_UNIFORM_SCALING_SHAPE_H diff --git a/src/btBulletCollisionCommon.h b/src/btBulletCollisionCommon.h index 0fe20b2cb..482f21768 100644 --- a/src/btBulletCollisionCommon.h +++ b/src/btBulletCollisionCommon.h @@ -32,13 +32,14 @@ subject to the following restrictions: #include "BulletCollision/CollisionShapes/btConvexHullShape.h" #include "BulletCollision/CollisionShapes/btTriangleMesh.h" #include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h" +#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" #include "BulletCollision/CollisionShapes/btTriangleMeshShape.h" #include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h" #include "BulletCollision/CollisionShapes/btCompoundShape.h" #include "BulletCollision/CollisionShapes/btTetrahedronShape.h" #include "BulletCollision/CollisionShapes/btEmptyShape.h" -#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" #include "BulletCollision/CollisionShapes/btMultiSphereShape.h" +#include "BulletCollision/CollisionShapes/btUniformScalingShape.h" ///Narrowphase Collision Detector #include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h"