#include "SimpleVec.h" #include // Given min a vector to minimize and a candidate vector, replace // elements of min whose corresponding elements in Candidate are // smaller. This function is used for finding objects' bounds, // among other things. void Minimize(SimpleVec &min, const SimpleVec &Candidate) { if (Candidate.x < min.x) min.x = Candidate.x; if (Candidate.y < min.y) min.y = Candidate.y; if (Candidate.z < min.z) min.z = Candidate.z; } // Given min a vector to minimize and a candidate vector, replace // elements of min whose corresponding elements in Candidate are // larger. This function is used for finding objects' bounds, // among other things. void Maximize(SimpleVec &max, const SimpleVec &Candidate) { if (Candidate.x > max.x) max.x = Candidate.x; if (Candidate.y > max.y) max.y = Candidate.y; if (Candidate.z > max.z) max.z = Candidate.z; } // Project the vector onto the YZ, XZ, or XY plane depending on which. // which Coordinate plane to project onto // 0 YZ // 1 XZ // 2 XY // This function is used by the polygon intersection code. void SimpleVec::ExtractVerts(float *px, float *py, int which) const { switch (which) { case 0: *px = y; *py = z; break; case 1: *px = x; *py = z; break; case 2: *px = x; *py = y; break; } } // returns the axis, where the vector has the largest value int SimpleVec::DrivingAxis(void) const { int axis = 0; float val = fabs(x); if (fabs(y) > val) { val = fabs(y); axis = 1; } if (fabs(z) > val) axis = 2; return axis; } // returns the axis, where the vector has the smallest value int SimpleVec::TinyAxis(void) const { int axis = 0; float val = fabs(x); if (fabs(y) < val) { val = fabs(y); axis = 1; } if (fabs(z) < val) axis = 2; return axis; } bool SimpleVec::CheckValidity() const { #ifdef _WIN32 return !(_isnan(x) || _isnan(y) || _isnan(z)); #else return !(isnan(x) || isnan(y) || isnan(z)); #endif }