From 0ff15db3f3b2939597128ce49ab8d681ba3eef05 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Tue, 30 Sep 2008 18:37:01 +0000 Subject: [PATCH] + capsule should subtract margin, and take local scaling into account. + boxshape uses btFsels + add assert in btGjkPairDetector that the new non-virtual method produces the same result as old non-virtual --- .../CollisionShapes/btConvexShape.cpp | 14 ++++++++----- .../btGjkPairDetector.cpp | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/BulletCollision/CollisionShapes/btConvexShape.cpp b/src/BulletCollision/CollisionShapes/btConvexShape.cpp index 3be208d0c..cafcb87a9 100644 --- a/src/BulletCollision/CollisionShapes/btConvexShape.cpp +++ b/src/BulletCollision/CollisionShapes/btConvexShape.cpp @@ -67,9 +67,9 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV btConvexInternalShape* convexShape = (btConvexInternalShape*)this; const btVector3& halfExtents = convexShape->getImplicitShapeDimensions(); - return btVector3(localDir.getX() < 0.0f ? -halfExtents.x() : halfExtents.x(), - localDir.getY() < 0.0f ? -halfExtents.y() : halfExtents.y(), - localDir.getZ() < 0.0f ? -halfExtents.z() : halfExtents.z()); + return btVector3(btFsels(localDir.x(), halfExtents.x(), -halfExtents.x()), + btFsels(localDir.y(), halfExtents.y(), -halfExtents.y()), + btFsels(localDir.z(), halfExtents.z(), -halfExtents.z())); } break; case TRIANGLE_SHAPE_PROXYTYPE: @@ -173,8 +173,11 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV btVector3 pos(0,0,0); pos[capsuleUpAxis] = halfHeight; - vtx = pos +vec*(radius); + //vtx = pos +vec*(radius); + vtx = pos +vec*capsuleShape->getLocalScalingNV()*(radius) - vec * capsuleShape->getMarginNV(); newDot = vec.dot(vtx); + + if (newDot > maxDot) { maxDot = newDot; @@ -185,7 +188,8 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV btVector3 pos(0,0,0); pos[capsuleUpAxis] = -halfHeight; - vtx = pos +vec*(radius); + //vtx = pos +vec*(radius); + vtx = pos +vec*capsuleShape->getLocalScalingNV()*(radius) - vec * capsuleShape->getMarginNV(); newDot = vec.dot(vtx); if (newDot > maxDot) { diff --git a/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp b/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp index 7db869d51..93f7b1524 100644 --- a/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp +++ b/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp @@ -18,7 +18,10 @@ subject to the following restrictions: #include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h" #include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h" + + #if defined(DEBUG) || defined (_DEBUG) +#define TEST_NON_VIRTUAL 1 #include //for debug printf #ifdef __SPU__ #include @@ -59,9 +62,18 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& localTransA.getOrigin() -= positionOffset; localTransB.getOrigin() -= positionOffset; + btScalar marginA = m_minkowskiA->getMarginNonVirtual(); btScalar marginB = m_minkowskiB->getMarginNonVirtual(); +#ifdef TEST_NON_VIRTUAL + btScalar marginAv = m_minkowskiA->getMargin(); + btScalar marginBv = m_minkowskiB->getMargin(); + + btAssert(marginA == marginAv); + btAssert(marginB == marginBv); +#endif //TEST_NON_VIRTUAL + gNumGjkChecks++; #ifdef DEBUG_SPU_COLLISION_DETECTION @@ -105,8 +117,17 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& btVector3 seperatingAxisInA = (-m_cachedSeparatingAxis)* input.m_transformA.getBasis(); btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis(); +#ifdef TEST_NON_VIRTUAL + btVector3 pInAv = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA); + btVector3 qInBv = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB); +#endif btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA); btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB); +#ifdef TEST_NON_VIRTUAL + btAssert((pInAv-pInA).length() < 0.0001); + btAssert((qInBv-qInB).length() < 0.0001); +#endif // + btPoint3 pWorld = localTransA(pInA); btPoint3 qWorld = localTransB(qInB);