Created
February 1, 2009 18:16
-
-
Save bradtgmurray/55933 to your computer and use it in GitHub Desktop.
This file contains 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
void ClipEndAgainstPlane(Vector4D& a, Vector4D& b, int axis) | |
{ | |
std::cout << " ClipEndAgainstPane " << a << b << std::endl; | |
// Positive side | |
if (a[axis] > a[3]) | |
{ | |
double alpha = (a[3] - a[axis])/(b[axis] - a[axis]); | |
std::cout << " Clipping against positive " << alpha << std::endl; | |
for(int i = 0; i < 4; ++i) | |
{ | |
a[i] = a[i] + (alpha * (b[i] - a[i])); | |
} | |
} | |
if (a[axis] < -a[3]) | |
{ | |
double alpha = (a[3] + a[axis])/(b[axis] - a[axis]); | |
std::cout << " Clipping against negative " << alpha << std::endl; | |
for(int i = 0; i < 4; ++i) | |
{ | |
a[i] = a[i] + (alpha * (b[i] - a[i])); | |
} | |
} | |
std::cout << " End ClipEndAgainstPane " << a << b << std::endl; | |
} | |
bool ClipLineAgainstPlane(Vector4D& a, Vector4D& b, int axis) | |
{ | |
std::cout << "ClipLineAgainstPane " << axis << a << b << std::endl; | |
// If both ends are outside, don't use the line at all. | |
if (a[axis] > a[3] && b[axis] > a[3]) return true; | |
ClipEndAgainstPlane(a, b, axis); | |
ClipEndAgainstPlane(b, a, axis); | |
std::cout << "End ClipLineAgainstPane " << a << b << std::endl; | |
// Line is useful | |
return false; | |
} | |
bool eliminated = false; | |
for (int i = 0; i < 3 && !eliminated; ++i) | |
{ | |
if (ClipLineAgainstPlane(projBegin, projEnd, i)) eliminated = true; | |
} | |
if (eliminated) continue; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment