diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2008-09-03 06:27:16 +0400 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2008-09-03 06:27:16 +0400 |
commit | 1926e846500212d11061c23cacdbd08d88e375da (patch) | |
tree | ad72fe64632cfc22a4878e065578b66d52de218d /extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h | |
parent | 33ac84e888ee3e3217f15f955e1b389a9c4bb230 (diff) |
Finally upgraded to latest Bullet subversion, about to release 2.71. Some recent changes in extern/bullet2 need to be re-applied, will check with Benoit. Ray tests in 0_FPS_Template.blend is broken, didn't figure out why yet.
HELP BUILD SYSTEM MAINTAINERS: Please help with updating all build systems: the newly added files need to be added. Note that the src/SoftBody has been added for future extension of real-time soft bodies.
Diffstat (limited to 'extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h')
-rw-r--r-- | extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h | 104 |
1 files changed, 67 insertions, 37 deletions
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h index bc42f146c7c..4d4fbefea37 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h @@ -18,11 +18,11 @@ subject to the following restrictions: #include "btPolyhedralConvexShape.h" #include "btCollisionMargin.h" -#include "../BroadphaseCollision/btBroadphaseProxy.h" -#include "../../LinearMath/btPoint3.h" -#include "../../LinearMath/btSimdMinMax.h" +#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" +#include "LinearMath/btPoint3.h" +#include "LinearMath/btMinMax.h" -///btBoxShape implements both a feature based (vertex/edge/plane) and implicit (getSupportingVertex) Box +///The btBoxShape is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates. When used as part of a btCollisionObject or btRigidBody it will be an oriented box in world space. class btBoxShape: public btPolyhedralConvexShape { @@ -31,47 +31,52 @@ class btBoxShape: public btPolyhedralConvexShape public: - btVector3 getHalfExtents() const; - + btVector3 getHalfExtentsWithMargin() const + { + btVector3 halfExtents = getHalfExtentsWithoutMargin(); + btVector3 margin(getMargin(),getMargin(),getMargin()); + halfExtents += margin; + return halfExtents; + } + + const btVector3& getHalfExtentsWithoutMargin() const + { + return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included + } + + virtual int getShapeType() const { return BOX_SHAPE_PROXYTYPE;} virtual btVector3 localGetSupportingVertex(const btVector3& vec) const { + btVector3 halfExtents = getHalfExtentsWithoutMargin(); + btVector3 margin(getMargin(),getMargin(),getMargin()); + halfExtents += margin; - btVector3 halfExtents = getHalfExtents(); - - btVector3 supVertex; - supVertex = btPoint3(vec.x() < btScalar(0.0) ? -halfExtents.x() : halfExtents.x(), - vec.y() < btScalar(0.0) ? -halfExtents.y() : halfExtents.y(), - vec.z() < btScalar(0.0) ? -halfExtents.z() : halfExtents.z()); - - return supVertex; + return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()), + btFsels(vec.y(), halfExtents.y(), -halfExtents.y()), + btFsels(vec.z(), halfExtents.z(), -halfExtents.z())); } - virtual inline btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const + SIMD_FORCE_INLINE btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const { - btVector3 halfExtents = getHalfExtents(); - btVector3 margin(getMargin(),getMargin(),getMargin()); - halfExtents -= margin; - - return btVector3(vec.x() < btScalar(0.0) ? -halfExtents.x() : halfExtents.x(), - vec.y() < btScalar(0.0) ? -halfExtents.y() : halfExtents.y(), - vec.z() < btScalar(0.0) ? -halfExtents.z() : halfExtents.z()); + const btVector3& halfExtents = getHalfExtentsWithoutMargin(); + + return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()), + btFsels(vec.y(), halfExtents.y(), -halfExtents.y()), + btFsels(vec.z(), halfExtents.z(), -halfExtents.z())); } virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const { - btVector3 halfExtents = getHalfExtents(); - btVector3 margin(getMargin(),getMargin(),getMargin()); - halfExtents -= margin; - - + const btVector3& halfExtents = getHalfExtentsWithoutMargin(); + for (int i=0;i<numVectors;i++) { const btVector3& vec = vectors[i]; - supportVerticesOut[i].setValue(vec.x() < btScalar(0.0) ? -halfExtents.x() : halfExtents.x(), - vec.y() < btScalar(0.0) ? -halfExtents.y() : halfExtents.y(), - vec.z() < btScalar(0.0) ? -halfExtents.z() : halfExtents.z()); + supportVerticesOut[i].setValue(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()), + btFsels(vec.y(), halfExtents.y(), -halfExtents.y()), + btFsels(vec.z(), halfExtents.z(), -halfExtents.z())); } } @@ -79,14 +84,38 @@ public: btBoxShape( const btVector3& boxHalfExtents) { - m_implicitShapeDimensions = boxHalfExtents; + btVector3 margin(getMargin(),getMargin(),getMargin()); + m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin; }; - + + virtual void setMargin(btScalar collisionMargin) + { + //correct the m_implicitShapeDimensions for the margin + btVector3 oldMargin(getMargin(),getMargin(),getMargin()); + btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; + + btConvexInternalShape::setMargin(collisionMargin); + btVector3 newMargin(getMargin(),getMargin(),getMargin()); + m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin; + + } + virtual void setLocalScaling(const btVector3& scaling) + { + btVector3 oldMargin(getMargin(),getMargin(),getMargin()); + btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; + btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling; + + btConvexInternalShape::setLocalScaling(scaling); + + m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin; + + } + virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; - virtual void calculateLocalInertia(btScalar mass,btVector3& inertia); + virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const { @@ -116,7 +145,7 @@ public: virtual void getVertex(int i,btVector3& vtx) const { - btVector3 halfExtents = getHalfExtents(); + btVector3 halfExtents = getHalfExtentsWithoutMargin(); vtx = btVector3( halfExtents.x() * (1-(i&1)) - halfExtents.x() * (i&1), @@ -127,7 +156,7 @@ public: virtual void getPlaneEquation(btVector4& plane,int i) const { - btVector3 halfExtents = getHalfExtents(); + btVector3 halfExtents = getHalfExtentsWithoutMargin(); switch (i) { @@ -234,7 +263,7 @@ public: virtual bool isInside(const btPoint3& pt,btScalar tolerance) const { - btVector3 halfExtents = getHalfExtents(); + btVector3 halfExtents = getHalfExtentsWithoutMargin(); //btScalar minDist = 2*tolerance; @@ -250,7 +279,7 @@ public: //debugging - virtual char* getName()const + virtual const char* getName()const { return "Box"; } @@ -291,3 +320,4 @@ public: #endif //OBB_BOX_MINKOWSKI_H + |