diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index c505ed5d5080..896cf83a5434 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -1303,10 +1303,10 @@ void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const const btCapsuleShape* capsuleShape = static_cast(shape); btScalar radius = capsuleShape->getRadius(); - btScalar halfHeight = capsuleShape->getHalfHeight(); + btScalar extend = capsuleShape->getExtend(); int upAxis = capsuleShape->getUpAxis(); - getDebugDrawer()->drawCapsule(radius, halfHeight, upAxis, worldTransform, color); + getDebugDrawer()->drawCapsule(radius, extend, upAxis, worldTransform, color); break; } case CONE_SHAPE_PROXYTYPE: diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp index 864df26e9314..94709dca599c 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp @@ -24,6 +24,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter m_shapeType = CAPSULE_SHAPE_PROXYTYPE; m_upAxis = 1; m_implicitShapeDimensions.setValue(radius,0.5f*height,radius); + btVector3 margin(getMargin(),getMargin(),getMargin()); + m_implicitShapeDimensions -= margin; } @@ -53,9 +55,9 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter { btVector3 pos(0,0,0); - pos[getUpAxis()] = getHalfHeight(); + pos[getUpAxis()] = getExtend(); - vtx = pos +vec*(radius) - vec * getMargin(); + vtx = pos +vec*(radius); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -65,9 +67,9 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter } { btVector3 pos(0,0,0); - pos[getUpAxis()] = -getHalfHeight(); + pos[getUpAxis()] = -getExtend(); - vtx = pos +vec*(radius) - vec * getMargin(); + vtx = pos +vec*(radius); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -95,8 +97,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter btScalar newDot; { btVector3 pos(0,0,0); - pos[getUpAxis()] = getHalfHeight(); - vtx = pos +vec*(radius) - vec * getMargin(); + pos[getUpAxis()] = getExtend(); + vtx = pos +vec*(radius); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -106,8 +108,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter } { btVector3 pos(0,0,0); - pos[getUpAxis()] = -getHalfHeight(); - vtx = pos +vec*(radius) - vec * getMargin(); + pos[getUpAxis()] = -getExtend(); + vtx = pos +vec*(radius); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -131,9 +133,9 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) con btScalar radius = getRadius(); btVector3 halfExtents(radius,radius,radius); - halfExtents[getUpAxis()]+=getHalfHeight(); + halfExtents[getUpAxis()]+=getExtend(); - btScalar margin = CONVEX_DISTANCE_MARGIN; + btScalar margin = getMargin(); btScalar lx=btScalar(2.)*(halfExtents[0]+margin); btScalar ly=btScalar(2.)*(halfExtents[1]+margin); @@ -153,6 +155,8 @@ btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height) { m_upAxis = 0; m_implicitShapeDimensions.setValue(0.5f*height, radius,radius); + btVector3 margin(getMargin(),getMargin(),getMargin()); + m_implicitShapeDimensions -= margin; } @@ -164,6 +168,8 @@ btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height) { m_upAxis = 2; m_implicitShapeDimensions.setValue(radius,radius,0.5f*height); + btVector3 margin(getMargin(),getMargin(),getMargin()); + m_implicitShapeDimensions -= margin; } diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h index f8c55ace4eb9..0cd256f95da1 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h @@ -55,13 +55,12 @@ ATTRIBUTE_ALIGNED16(class) btCapsuleShape : public btConvexInternalShape btConvexInternalShape::setMargin(collisionMargin); btVector3 newMargin(getMargin(),getMargin(),getMargin()); m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin; - } virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const { btVector3 halfExtents(getRadius(),getRadius(),getRadius()); - halfExtents[m_upAxis] = getRadius() + getHalfHeight(); + halfExtents[m_upAxis] += getExtend(); halfExtents += btVector3(getMargin(),getMargin(),getMargin()); btMatrix3x3 abs_b = t.getBasis().absolute(); btVector3 center = t.getOrigin(); @@ -92,16 +91,27 @@ ATTRIBUTE_ALIGNED16(class) btCapsuleShape : public btConvexInternalShape return m_implicitShapeDimensions[m_upAxis]; } + btScalar getExtend() const + { + return getHalfHeight() - getRadius(); + } + virtual void setLocalScaling(const btVector3& scaling) { - btVector3 oldMargin(getMargin(),getMargin(),getMargin()); - btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; - btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling; + const unsigned short r1 = (m_upAxis + 1) % 3; + const unsigned short r2 = (m_upAxis + 2) % 3; - btConvexInternalShape::setLocalScaling(scaling); + const float margin = getMargin(); + const float halfHeight = m_implicitShapeDimensions[m_upAxis]; + float radius = m_implicitShapeDimensions[r2]; + float radiusWithMargin = radius + margin; + const float halfHeightWithMargin = halfHeight + margin; - m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin; + const btVector3 scaleRatio = scaling / m_localScaling; + m_implicitShapeDimensions[r2] = radiusWithMargin * (scaleRatio[r1] + scaleRatio[r2]) / 2.0f - margin; + m_implicitShapeDimensions[m_upAxis] = halfHeightWithMargin * scaleRatio[m_upAxis] - margin; + btConvexInternalShape::setLocalScaling(scaling); } virtual btVector3 getAnisotropicRollingFrictionDirection() const diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.cpp index 2d83c8bfbac5..5e2aaebfe529 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.cpp @@ -144,4 +144,4 @@ void btConeShape::setLocalScaling(const btVector3& scaling) m_radius *= (scaling[r1] / m_localScaling[r1] + scaling[r2] / m_localScaling[r2]) / 2; m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height)); btConvexInternalShape::setLocalScaling(scaling); -} \ No newline at end of file +} diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp index 88018b4c6248..346b428c699c 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp @@ -227,7 +227,7 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ()); btCapsuleShape* capsuleShape = (btCapsuleShape*)this; - btScalar halfHeight = capsuleShape->getHalfHeight(); + btScalar extend = capsuleShape->getExtend(); int capsuleUpAxis = capsuleShape->getUpAxis(); btScalar radius = capsuleShape->getRadius(); @@ -249,10 +249,9 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV btScalar newDot; { btVector3 pos(0,0,0); - pos[capsuleUpAxis] = halfHeight; + pos[capsuleUpAxis] = extend; - //vtx = pos +vec*(radius); - vtx = pos +vec*(radius) - vec * capsuleShape->getMarginNV(); + vtx = pos +vec*(radius); newDot = vec.dot(vtx); @@ -264,10 +263,9 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV } { btVector3 pos(0,0,0); - pos[capsuleUpAxis] = -halfHeight; + pos[capsuleUpAxis] = -extend; - //vtx = pos +vec*(radius); - vtx = pos +vec*(radius) - vec * capsuleShape->getMarginNV(); + vtx = pos +vec*(radius); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -426,7 +424,7 @@ void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btCapsuleShape* capsuleShape = (btCapsuleShape*)this; btVector3 halfExtents(capsuleShape->getRadius(),capsuleShape->getRadius(),capsuleShape->getRadius()); int m_upAxis = capsuleShape->getUpAxis(); - halfExtents[m_upAxis] = capsuleShape->getRadius() + capsuleShape->getHalfHeight(); + halfExtents[m_upAxis] += capsuleShape->getExtend(); halfExtents += btVector3(capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual()); btMatrix3x3 abs_b = t.getBasis().absolute(); btVector3 center = t.getOrigin(); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index f8e9b84bd1a8..6488cd350b95 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -2897,7 +2897,7 @@ void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, K case OB_BOUND_CAPSULE: { shapeInfo->m_radius = MT_max(bounds_extends[0], bounds_extends[1]); - shapeInfo->m_height = 2.0f * (bounds_extends[2] - shapeInfo->m_radius); + shapeInfo->m_height = 2.0f * bounds_extends[2]; if (shapeInfo->m_height < 0.0f) shapeInfo->m_height = 0.0f; shapeInfo->m_shapeType = PHY_SHAPE_CAPSULE;