btCapsuleShape, m_implicitShapeDimensions & margin

Romain Daize
Posts: 15
Joined: Tue Jan 06, 2009 10:04 am

btCapsuleShape, m_implicitShapeDimensions & margin

Post by Romain Daize »

Hi,

Things are not clear in the btCapsuleShape, and I'm not sure to understand how it is used in collision algorithm as GJK.
I'm looking at the constructor first :

Code: Select all

btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInternalShape ()
{
	m_shapeType = CAPSULE_SHAPE_PROXYTYPE;
	m_upAxis = 1;
	m_implicitShapeDimensions.setValue(radius,0.5f*height,radius);
}
So the margin is not setup here, it is kept to its default value (0.04). Then implicitShapeDimensions correspond to the initial capsule dimensions.

Now I'm looking to this implementation :

Code: Select all

	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;

	}
In this peace of code, it seems that implicitShapeDimensions are considered as the capsule dimensions reduced by the margin (as for the BoxShape). So definitively there is a incoherency between the btCapsuleShape constructor and its setMargin method. Moreover, the getAabb implementation add the margin to the Aabb....
Finally it seems that constructor is invalid, shouldn't it be as for the boxShape (implicitShapeDimensions = shapeSize - margin) ?

Code: Select all

	btBoxShape( const btVector3& boxHalfExtents) 
		: btPolyhedralConvexShape()
	{
		m_shapeType = BOX_SHAPE_PROXYTYPE;
		btVector3 margin(getMargin(),getMargin(),getMargin());
		m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
	};
I have practiced different values for my CapsuleShape. For example, changing margin (and not implicitShapeDimension) does not seem to have desired impact, indeed putting 1.0 will add an extra radius, but not of 1 meter. Looking at the btSphereShape makes me more perplex, as the implicitShapeDimension = margin, so how margin is handled in this case ? It does not seem to be an extra radius as for the box, but is it still used ?
Can you explain how GJK handles those different values ? Margin should be an extra radius in all case, shouldn't it ? Why implicitShapeDimension are not defined as shapeSize - margin in all case ? Maybe margin is an intra radius and not extra radius ? So why not putting capsule margin as its radius (like sphere) ? Sorry if I'm a bit confused...

Thanks a lot.

Romain