-
-
Save yuripourre/69d782fc9d67748262757543bf33cd31 to your computer and use it in GitHub Desktop.
Frustum AABB Intersect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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