Jump to content
  • Advertisement
Sign in to follow this  

Frustum - AABB intersection

This topic is 5008 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

Hello. I can't quite get my intersection test beween a frustum and aabb box correct. I can test if the box is completely contained or reverse, if the frustum is completely contained. But i cant figure out how to do it if the box is intersecting with the frustum. I came up with a test that had like 50 if() cases, and it worked in most cases but not all. Is there some simpler elegant way to do this, like with the other test? This is what my intersection test between a box and a frustum looks like. It makes use of a function that tests intersection between a plane and a box. That function can return PLANE_INTERSECTION_BACK, PLANE_INTERSECTION_FRONT or PLANE_INTERSECTION_INTERSECT.
inline volume_intersection_t intersect(const box_t* a, const frustum_t* b)
		plane_intersection_t left = intersect(&b->m_left_plane, a);
		plane_intersection_t right = intersect(&b->m_right_plane, a);
		plane_intersection_t top = intersect(&b->m_top_plane, a);
		plane_intersection_t bottom = intersect(&b->m_bottom_plane, a);
		plane_intersection_t near = intersect(&b->m_near_plane, a);
		plane_intersection_t far = intersect(&b->m_far_plane, a);

		// box contains the frustum
		// the frustum contains the box
		else if( (left		== PLANE_INTERSECTION_BACK)
				&& (right	== PLANE_INTERSECTION_BACK) 
				&& (bottom	== PLANE_INTERSECTION_BACK)
		// the box and the frustum is intersecting
		else if(???)


Extra question: I find it hard to debug the frustum. Boxes and spheres i can create meshes of and render to make sure they are performing correctly. But i cant really render a frustum, as it is now i just stear the camera and look at things, and guess that what is outside the view frustum isnt renderd. Or look at what is beeing renderd from another camera that the frustum isnt attached to. But does anyone have any tip for a simple way to visualize the frustum? Thanks in advance! :-)

Share this post

Link to post
Share on other sites
I am at work, so this will be abreviated. It looks like you may be misunderstanding the AABB/frustum test. Let's say that your box/plane test is correct (you might post the code to be sure). Then the standard box/frustum test is:

for (int i = 0; i < 6; ++i)
if (TestBoxPlane(box, frustum.planes) == OUTSIDE)
return false;
return true;

Whether OUTSIDE is FRONT or BACK depends on which way your plane normals point.

Note that this is not a perfect test - it can return false positives. But for frustum culling it is generally considered to be accurate enough.

For drawing your frustum, you can find the corners of the truncated pyramid that represents it by intersecting the frustum planes in sets of three. Look up 'plane intersection' for how to do this.

Gotta run, but 'hope that was of some help.

Share this post

Link to post
Share on other sites
Thanks for your awnser.

Yes i found the approach you mention to be the standard. But the thing is that i want to be able to tell if a box is inside the frustum, or completly containing the frustum, or is intersecting with the frustum.

The above approach dosnt work if a box is completely containing the frustum, or atleast i think so.. my brain is boiling from trying to visualisze all this. :-)

The two first tests are easy, if a box is completely containing the frustum, all planes of the frustum should repoart that the they are intersecting with the box. (this is wrong in my code).

The second test, if the frustum is completely containg the box, all planes should repoart that the box is infront of them(normals pointing inwards).

But the third test.. if the box is intersecting with the frustum..
Hmm, maybe i can get that result if i use your test after i have tested if the frustum is completely containg the box, than that option isnt avalible anymore.. and if there are no planes that report behind.. than it should be a collision right? hmm, i will try that! :-P

Share this post

Link to post
Share on other sites
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!