1

I'm looking for a fast, efficient (even if sometimes false positive) way to determine if a cube intersects a frustum.

I've been using a brute force test of just seeing if all cube points are behind one of the planes, and rejecting on that basis, using this function:

inline char ClassifyPoint(Vector thePoint, char thePlane) 
{
    Vector aDir=mPlane[thePlane].mPos-thePoint;
    float aD=aDir.Dot(mPlane[thePlane].mNormal);
    if (aD<-0.0005f) return 1; // In front of plane
    if (aD>0.0005f) return -1; // Behind plane
    return 0; // "On" the plane
}

It also seems to work if I just use the center of each cube face, which saves me two tests.

But I wanted to know if there's a faster way, something more volume oriented.

KiraHoneybee
  • 495
  • 3
  • 12
  • You could approximate the cube with a sphere if you don't mind false positives. Sphere collision detection should be pretty fast. – mattlangford Jul 12 '21 at 14:35
  • "just use the center of each cube face" I strongly doubt that this works. – Marc Glisse Jul 12 '21 at 14:53
  • mattlangford: I think I might lose the speed computing the enclosing sphere. ... Marc Glisse: I've run a great many tests and it appears to work (any intersection puts at least ONE face in front of a plane). Can you think of a fail condition with this? Remember, I'm saying "the center of ALL faces are ALL behind one of the frustum planes." – KiraHoneybee Jul 12 '21 at 15:24
  • If speed if of the essence, you might want so return `aD` directly instead of forcing a test. Tests with unpredictable results are typically slow. By the way, why the odd `char` parameter for indexing? (yup, not answering the question, but figured it could be useful) – spectras Jul 12 '21 at 15:49
  • Just used char so it'd be one byte to return -1,0 or 1... I have a bad habit of minimizing (I know modern computers don't even see less than eight bytes at a time). I would love to return D except I find that when I don't use that .0005f wiggle room, floating point precision will give me false negatives. – KiraHoneybee Jul 12 '21 at 16:22
  • Depending on the viewing angle, can’t a cube’s corners lie entirely outside the frustum while its interior intersects it? – Davis Herring Jul 12 '21 at 16:34
  • @DavisHerring That's why I'm trying to find out if there's a volume solution. However, in the case of a cube being bigger than the frustum, it's still true that not ALL points will ALL be behind one of the planes, right? That's the check I'm doing-- for each frustum plane, if ALL corners of the cube are behind it, it's outside. Can that fail if the cube intersect the frustum? – KiraHoneybee Jul 12 '21 at 16:45
  • Is the cube axis-aligned? – jwezorek Jul 12 '21 at 18:57
  • @KiraHoneybee: Well, certainly if all vertices of a convex polyhedron are on one side of a plane, so is the interior. I thought you were combining results from multiple planes to reduce the false-positive rate. – Davis Herring Jul 12 '21 at 19:05

0 Answers0