Bug adding contact point with scaled cylinder shape

Nacho
Posts: 31
Joined: Tue Mar 04, 2008 1:41 pm

Bug adding contact point with scaled cylinder shape

Post by Nacho »

Hi,

I see that when a capsule collide with a scaled cylinder, the distance1 in btPersistentManifold is erroneous.

In btGjkPairDetector::getClosestPointsNonVirtual, before call output.addContactPoint, the data is computed correctly, but in btManifoldResult::addContactPoint, the localA and localB are wrong computed because is used btTransform::invXform function that uses transpose matrix, not real inverse matrix (in no scale matrix, transpose==inverse). Then, when btManifoldResult::refreshContactPoints is called later, m_positionWorldOnA, m_positionWorldOnB and distance1 are updated, the result is wrong by the error in m_localPointA or m_localPointB computed.

I think the solution would be something like:

Code: Select all

	btMatrix3x3 inv;
	// Do this because btTransform::inverse uses transpose instead of real inverse too
	inv= m_rootTransA.getBasis().inverse();
	btTransform transInvA(inv, inv * -m_rootTransA.getOrigin());
	inv= m_rootTransB.getBasis().inverse();
	btTransform transInvB(inv, inv * -m_rootTransB.getOrigin());
	if (isSwapped)
	{
		localA = transInvB(pointA);
		localB = transInvA(pointInWorld);
//		localA = m_rootTransB.invXform(pointA );
//		localB = m_rootTransA.invXform(pointInWorld);
	} else
	{
		localA = transInvA(pointA);
		localB = transInvB(pointInWorld);
//		localA = m_rootTransA.invXform(pointA );
//		localB = m_rootTransB.invXform(pointInWorld);
	}
Nacho
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Bug adding contact point with scaled cylinder shape

Post by Erwin Coumans »

The world matrix shouldn't include any scaling, so the transpose == inverse. You are using the cylinder shape setLocalScaling right?

Thanks,
Erwin
Nacho
Posts: 31
Joined: Tue Mar 04, 2008 1:41 pm

Re: Bug adding contact point with scaled cylinder shape

Post by Nacho »

ups! Indeed, I do that mistake. :oops:

Thanks for open my eyes.
Nacho.