00001 #ifndef __util__ 00002 #define __util__ 00003 00004 #include <osg/Vec3> 00005 #include <osg/Vec4> 00006 #include <osg/Quat> 00007 #include <osg/Camera> 00008 #include <osg/NodeVisitor> 00009 #include <osg/BoundingBox> 00010 #include <osg/BoundingSphere> 00011 #include <osg/MatrixTransform> 00012 #include <osg/Billboard> 00013 #include <string> 00014 #include <sstream> 00015 00016 using namespace std; 00017 00018 00019 namespace util { 00020 00021 namespace math { 00022 00023 extern const double PI; 00024 00025 float dotProduct(osg::Vec3f& a, osg::Vec3f& b); 00026 double dotProduct(osg::Vec3d& a, osg::Vec3d& b); 00027 00028 float distance(osg::Vec3f& a, osg::Vec3f& b); 00029 double distance(osg::Vec3d& a, osg::Vec3d& b); 00030 00031 osg::Vec4d rotateVectorAroundAxis(osg::Vec4d& vector, osg::Vec4d& axis, double angle); 00032 00033 osg::Vec3 quaternionToEuler(osg::Quat& rotation); 00034 osg::Quat eulerToQuaternion(osg::Vec3& rotation); 00035 00036 osg::Matrix makeEulerRotation(osg::Vec3f rotation); 00037 00038 template <class T> T getMax(T a, T b, T c){ 00039 if(a>b && a>c) 00040 return a; 00041 else if(b>a && b>c) 00042 return b; 00043 else return c; 00044 } 00045 00046 void getRayFromCamera(const osg::Camera* camera, const int x, const int y, osg::Vec3d& direction, osg::Vec3d& point); 00047 bool getLineSphereIntersection(const osg::BoundingSphere& boundingSphere, const osg::Vec3d& direction, const osg::Vec3d& point, osg::Vec3d& hit1, osg::Vec3d& hit2); 00048 bool getLineBoxIntersection(const osg::BoundingBox& boundingBox, const osg::Vec3d& lineStart, const osg::Vec3d& lineEnd, osg::Vec3d& hit); 00049 }; 00050 00051 00052 bool isOneOf(const char item, const char* set); 00053 00054 string reverse(const string& str); 00055 00056 string trim_left(const string& str, const char* trimchars = " "); 00057 string trim_right(const string& str, const char* trimchars = " "); 00058 00059 string trim(const string& str, const char* trimchars = " "); 00060 00061 00062 template <class T> string to_string(const T& arg) { 00063 stringstream stream; 00064 stream << arg; 00065 return stream.str(); 00066 } 00067 00068 template <class T> T from_string(const char* arg) { 00069 T result; 00070 stringstream stream; 00071 00072 stream << arg; 00073 stream >> result; 00074 00075 return result; 00076 } 00077 00078 template <class T> T from_string(const string& arg) { 00079 T result; 00080 stringstream stream; 00081 00082 stream << arg; 00083 stream >> result; 00084 00085 return result; 00086 } 00087 00088 }; 00089 00090 #endif