Jump to content
  • Advertisement
Sign in to follow this  
lordikon

Rectangle<->Frustum Intersection test?

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

I'm basically just trying to check if a flat quad rectangle lies within the view frustum or not. The rectangle is not axis-aligned, it can have any scale or transform (position, rotation). The current frustum information I have is just the 6 planes that make up the frustum, although if I truly need I could probably calculate the 8 corners of the frustum.

I searched all over google and most of the results seem to be plane checks rather than rectangles.

EDIT: I think I might have it. Let me know if this sounds like it would work:

Check each point on the rectangle against the frustum. If any point is in the frustum then it's in view. If no points are within the frustum check if any edge of the rectangle intersects any of the frustum planes. If any edges intersect a frustum plane then it's in view.

I think this will work, and I already have the algorithms for checking points against the frustum, so I should be able to use that algorithm and the fact that all the points are outside of the frustum to handle either case.

Share this post


Link to post
Share on other sites
Advertisement
If the rectangle is bigger than the frustum, you'll have problems as not only will no points be inside, but no lines will pass through since it's larger in all respects. If the rectangle-line check fails, try checking the frustum's lines for intersection with the rectangle.

Share this post


Link to post
Share on other sites
If you only check for those factors you will completely miss any quad that is larger than the frustum. A common way is to test if all points are on the same side of a single frustum plane. You will get false positives in some cases, but that's usually better than the other way around. If you want perfect results, you will probably end up checking for intersection in both ways. Don't just see if the polygon points/edges intersect the frustum, but also if the frustum edges intersect the polygon.

Edit: I really need to stop taking so much time when writing answers.

Share this post


Link to post
Share on other sites
There would have to be a huge speed bonus in calculation and not much speed increase in culling (if that's what this is for) to use your first method. That's a lot of false positives :lol: In fact, wouldn't there always be a plane in the frustum with the points on the same side?

Share this post


Link to post
Share on other sites
Hidden
There would have to be a huge speed bonus in calculation and not much speed increase in culling (if that's what this is for) to use your first method. That's a lot of false positives :lol:

Share this post


Link to post

There would have to be a huge speed bonus in calculation and not much speed increase in culling (if that's what this is for) to use your first method. That's a lot of false positives :lol: In fact, wouldn't there always be a plane in the frustum with the points on the same side?


You're right. Replace "same side" of a plane with "outside" of a single plane, ie. all points are left/right/above/below/behind/beyond the frustum.

Share this post


Link to post
Share on other sites
Good stuff guys, thanks. I do believe that checking if all four points of the rectangle are on the outside of any of the planes then that will mean it's not colliding. Thanks!

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!