🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Support function for Capsule (GJK and MPR)

Started by
4 comments, last by MikeNew 3 years, 5 months ago

Hello.

I need support function for capsule (for GJK and MPR algorithms).

Please help.

Advertisement

It's just the support function of the capsule's line segment (ie one of the two vertices), plus the vector “(support direction vector) * (radius of the capsule)”.

C_Vector3 C_ShapeCapsule :: GetSupportPoint( const C_Vector3 & dir ) const
{
	const float Dy = dir.Dot( m_Axis[1] );

	if (Math::Abs(Dy) > 0.9999f) // parallel
	{
		return( Dy > 0.0f ? m_P0 : m_P1 );
	}
	else if (Math::Abs(Dy) < 0.0001f) // perpendicular
	{
		return( m_Center - m_Radius * dir );
	}
	else
	{
		if (Dy < 0.0f)
		{
			return( m_P0 + m_Radius * dir );
		}
		else
		{
			return( m_P1 + m_Radius * dir );
		}
	}
}

Hm, in my experience you don't need the first set of if/else – in the perpendicular case, regardless of if you pick the midpoint or an endpoint, the projection of the support point along the support direction will be identical, so might as well just pick a vertex like the normal case. And AFAICT your parallel case has a bug since it's returning one of the capsule lineseg endpoints itself, but the correct support point should be pushed outwards from the lineseg by the radius of the capsule.

This one line should suffice:

return ((Dy < 0.0f ? m_P0 : m_P1) + m_Radius * dir);

Many thanks to all, now everything works.

This topic is closed to new replies.

Advertisement