Skip to content

Instantly share code, notes, and snippets.

@yuripourre
Forked from Kinwailo/FrustumAABBIntersect.cpp
Created March 19, 2022 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuripourre/69d782fc9d67748262757543bf33cd31 to your computer and use it in GitHub Desktop.
Save yuripourre/69d782fc9d67748262757543bf33cd31 to your computer and use it in GitHub Desktop.
Frustum AABB Intersect
// Returns: INTERSECT : 0
// INSIDE : 1
// OUTSIDE : 2
int FrustumAABBIntersect(Plane *planes, Vector &mins, Vector &maxs) {
int ret = INSIDE;
Vector vmin, vmax;
for(int i = 0; i < 6; ++i) {
// X axis
if(planes[i].normal.x > 0) {
vmin.x = mins.x;
vmax.x = maxs.x;
} else {
vmin.x = maxs.x;
vmax.x = mins.x;
}
// Y axis
if(planes[i].normal.y > 0) {
vmin.y = mins.y;
vmax.y = maxs.y;
} else {
vmin.y = maxs.y;
vmax.y = mins.y;
}
// Z axis
if(planes[i].normal.z > 0) {
vmin.z = mins.z;
vmax.z = maxs.z;
} else {
vmin.z = maxs.z;
vmax.z = mins.z;
}
if(Vector::DotProduct(planes[i].normal, vmin) + planes[i].d > 0)
return OUTSIDE;
if(Vector::DotProduct(planes[i].normal, vmax) + planes[i].d >= 0)
ret = INTERSECT;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment