Skip to content

Instantly share code, notes, and snippets.

@Kinwailo
Last active November 23, 2023 15:09
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Kinwailo/d9a07f98d8511206182e50acda4fbc9b to your computer and use it in GitHub Desktop.
Save Kinwailo/d9a07f98d8511206182e50acda4fbc9b 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;
}
@Gerard097
Copy link

Nice bro, this helped me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment