#ifndef _BBCUTIL_H #define _BBCUTIL_H #include namespace BBC { const Ogre::Real EPSILON_INTERSECT = 0.00000001; class _BBCExport Util { public: static Ogre::String getBaseName(Ogre::String fileName) { Ogre::String baseName; size_t pos = fileName.find_last_of("."); baseName = fileName.substr(0, pos); return baseName; } static Ogre::String getExtensionName(Ogre::String fileName) { Ogre::String ext; size_t pos = fileName.find_last_of("."); ext = fileName.substr(pos+1); return ext; } static unsigned int nextPowerOf2(unsigned int nPlanes) { unsigned int depth = 1; while (depth < nPlanes) { depth = depth << 1; } return depth; } // Calculate the line segment PaPb that is the shortest route between // two lines P1P2 and P3P4. Calculate also the values of mua and mub where // Pa = P1 + mua (P2 - P1) // Pb = P3 + mub (P4 - P3) // Return false if no solution exists. static int lineLineIntersect( Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, Ogre::Vector3 *pa, Ogre::Vector3 *pb, Ogre::Real *mua, Ogre::Real *mub) { Ogre::Vector3 p13,p43,p21; Ogre::Real d1343,d4321,d1321,d4343,d2121; Ogre::Real numer,denom; p13.x = p1.x - p3.x; p13.y = p1.y - p3.y; p13.z = p1.z - p3.z; p43.x = p4.x - p3.x; p43.y = p4.y - p3.y; p43.z = p4.z - p3.z; if (Ogre::Math::Abs(p43.x) < EPSILON_INTERSECT && Ogre::Math::Abs(p43.y) < EPSILON_INTERSECT && Ogre::Math::Abs(p43.z) < EPSILON_INTERSECT) { return(false); } p21.x = p2.x - p1.x; p21.y = p2.y - p1.y; p21.z = p2.z - p1.z; if (Ogre::Math::Abs(p21.x) < EPSILON_INTERSECT && Ogre::Math::Abs(p21.y) < EPSILON_INTERSECT && Ogre::Math::Abs(p21.z) < EPSILON_INTERSECT) { return(false); } d1343 = p13.x * p43.x + p13.y * p43.y + p13.z * p43.z; d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z; d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z; d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z; d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z; denom = d2121 * d4343 - d4321 * d4321; if (Ogre::Math::Abs(denom) < EPSILON_INTERSECT) { return(false); } numer = d1343 * d4321 - d1321 * d4343; *mua = numer / denom; *mub = (d1343 + d4321 * (*mua)) / d4343; pa->x = p1.x + *mua * p21.x; pa->y = p1.y + *mua * p21.y; pa->z = p1.z + *mua * p21.z; pb->x = p3.x + *mub * p43.x; pb->y = p3.y + *mub * p43.y; pb->z = p3.z + *mub * p43.z; return(true); } }; /* extern "C" _BBCExport Ogre::Real fround(Ogre::Real n, unsigned d) { return floor(n * pow((Ogre::Real)10.,(int) d) + .5) / pow((Ogre::Real)10.,(int) d); } extern "C" _BBCExport int iround(Ogre::Real x) { return (int)floor(x + 0.5); } */ } #endif