Jump to content
  • Advertisement
Sign in to follow this  
0xFF

Transforming frustum to OBB space

This topic is 3628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there! :) I need to check if the static mesh is in frustum. I already have a 'Frustum-AABB' test and it works, but I also need a 'Frustum-OBB' test... but everything I have is AABB in local space and object transform :) I tried to transform normals of frustum planes and add object translation to AABB 'min' and 'max', but this works only if I have translation OR rotation matrix applied to object. If I concatenate this transforms( R*T ) my function doesn't work :( Here is the code I wrote to check if OBB is in frustum:
// ** Only AABB in local space
// ** and object transform, as mentioned above :)
bool cFrustum::BoxInside( const cBoundingBox& box, const cMatrix4& T ) const
{
	// ** Add object translation to AABB 'min' and 'max'
	cBoundingBox aabb = box + T.GetTranslation();

	const cVector3& min = aabb.min;
	const cVector3& max = aabb.max;
	cVector3 c = aabb.GetCenter();

	// ** Half-extents
	float w = aabb.GetWidth() * 0.5f;
	float h = aabb.GetHeight() * 0.5f;
	float d = aabb.GetDepth() * 0.5f;

	// ** I don't have scale in matrix, so I just calculate a transpose
	cMatrix4 tT = cMatrix4::Transpose( T );

	for(int i = 0; i < 6; i++ )
	{
		cVector3 N = frustum.normal;
		// ** Multiplies N by 3x3 transposed rotation matrix
		tT.TransformVector( N );

		// ** Intersection test as if it is an AABB
		if( N * min + frustum.distance > 0 ) continue;
		if( N * max + frustum.distance > 0 ) continue;

		if(N.x * (c.x + w) + N.y * (c.y - h) + N.z * (c.z - d) + frustum.distance > 0)
			continue;
		if(N.x * (c.x - w) + N.y * (c.y + h) + N.z * (c.z - d) + frustum.distance > 0)
			continue;
		if(N.x * (c.x + w) + N.y * (c.y + h) + N.z * (c.z - d) + frustum.distance > 0)
			continue;
		if(N.x * (c.x - w) + N.y * (c.y - h) + N.z * (c.z + d) + frustum.distance > 0)
			continue;
		if(N.x * (c.x + w) + N.y * (c.y - h) + N.z * (c.z + d) + frustum.distance > 0)
			continue;
		if(N.x * (c.x - w) + N.y * (c.y + h) + N.z * (c.z + d) + frustum.distance > 0)
			continue;

		return false;
	}
}
Thanks :)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!