Jump to content
  • Advertisement
Kuxy

SAT OBB-OBB - collision normal

Recommended Posts

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 :)

Edited by Kuxy

Share this post


Link to post
Share on other sites
Advertisement

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 :)

Edited by Kuxy

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!