//----------------------------------------------------------------------------- // Sorts the components of a vector //----------------------------------------------------------------------------- static inline void SortAbsVectorComponents( const Vector& src, int* pVecIdx ) { Vector absVec( fabs(src[0]), fabs(src[1]), fabs(src[2]) ); int maxIdx = (absVec[0] > absVec[1]) ? 0 : 1; if (absVec[2] > absVec[maxIdx]) { maxIdx = 2; } // always choose something right-handed.... switch( maxIdx ) { case 0: pVecIdx[0] = 1; pVecIdx[1] = 2; pVecIdx[2] = 0; break; case 1: pVecIdx[0] = 2; pVecIdx[1] = 0; pVecIdx[2] = 1; break; case 2: pVecIdx[0] = 0; pVecIdx[1] = 1; pVecIdx[2] = 2; break; } }
bool pointInSphere(GLfloat *p1, GLfloat *p2, GLfloat radius) { GLfloat result[3]; diff(p1,p2,result); if(absVec(result) <= radius) return true; return false; }
GLfloat* norm(GLfloat *vec, GLfloat *result) { GLfloat abs = absVec(vec); if(abs == 1.0) return vec; if(abs != 0.0) { setVec(result, vec[0] / abs, vec[1] / abs, vec[2] / abs); return result; } setVec(result, 0.0, 0.0, 0.0); return result; }