🎉 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!

SAT OBB-OBB - collision normal

Started by
5 comments, last by Dirk Gregorius 5 years, 5 months ago

Hello.

I'm in process of implementing the SAT for OBB-OBB test and the detection part is working fine and all that i'm missing is collision normal. Tried few options but it never works perfectly (comparing it with Unity's).

I'd appreciate any kind of input on that matter. Thanks :)

Advertisement

http://www.randygaul.net/2014/05/22/deriving-obb-to-obb-intersection-sat/

Yes i've already read your blog and it was very informative in many ways. This time I also checked the Dirk Gregorius GDC talk and i guess the conclusion is: Sutherland-Hodgman clipping. Even though that subject is barely touched (as far as i could see) on the D. Gregorious slides (that were otherwise very thorough and insightful) your finished implementation definitely helps a lot. Thanks :)

Sutherland-Hodgman clipping is really easy. You basically need a function that clips a segment (edge) against a plane and then you iterate the polygon edges and clip each against the current plane keeping points as specified in the algorithm. You repeat this for every plane.

I found the example code in Christer Ericson book "Real-Time Collision Detection" very useful.

Normals are working perfect and now i feel pretty bad because it really is easy and intuitive :)  I've look a bit into clipping and i'll do my best to make it work. And after that i'll try the Gauss map optimisation that you showed in your talk.

Thanks again for all the help and all the information you guys provide.

SInce someone else asked a similar question. Here is some example code for SH-clipping. 


//--------------------------------------------------------------------------------------------------
RnArray< RnVector3 > rnClipPolygon( const RnArray< RnVector3 >& Polygon, const RnPlane& Plane, int Edge )
	{
	RN_ASSERT( Polygon.Size() >= 3 );
	RnArray< RnVector3 > Out;
	
	RnVector3 Vertex1 = Polygon.Back();
	float Distance1 = rnDistance( Plane, Vertex1 );
	
	for ( int Index = 0; Index < Polygon.Size(); ++Index )
		{
		RnVector3 Vertex2 = Polygon[ Index ];
		float Distance2 = rnDistance( Plane, Vertex2 );
	
		if ( Distance1 <= 0.0f && Distance2 <= 0.0f )
			{
			// Both vertices are behind the plane - keep vertex2
			Out.PushBack( Vertex2 );
			}
		else if ( Distance1 <= 0.0f && Distance2 > 0.0f )
			{
			// Vertex1 is behind of the plane, vertex2 is in front -> intersection point
			float Fraction = Distance1 / ( Distance1 - Distance2 );
			RnVector3 IntersectionPoint = Vertex1.Position + Fraction * ( Vertex2.Position - Vertex1.Position );
	
			// Keep intersection point
			Out.PushBack( IntersectionPoint );
			}
		else if ( Distance2 <= 0.0f && Distance1 > 0 )
			{
			// Vertex2 is behind of the plane, vertex1 is in front -> intersection point
			float Fraction = Distance1 / ( Distance1 - Distance2 );
			RnVector3 IntersectionPoint = Vertex1.Position + Fraction * ( Vertex2.Position - Vertex1.Position );
	
			// Keep intersection point
			Out.PushBack( IntersectionPoint );
	
			// And also keep vertex2
			Out.PushBack( Vertex2 );
			}
	
		// Keep vertex2 as starting vertex for next edge
		Vertex1 = Vertex2;
		Distance1 = Distance2;
		}
  
	return Out;
	}

HTH,

-Dirk

This topic is closed to new replies.

Advertisement