]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGVec4.hxx
Compile SGReaderWriterOptions.cxx under Windows
[simgear.git] / simgear / math / SGVec4.hxx
index baf9137daa2aba31e290c5c81a022f72d2254847..6e42d957d8710f9a3a56c85cfa9d0b3ddf41f0bd 100644 (file)
 #ifndef SGVec4_H
 #define SGVec4_H
 
-#ifndef NO_OPENSCENEGRAPH_INTERFACE
-#include <osg/Vec4f>
-#include <osg/Vec4d>
-#endif
-
 /// 4D Vector Class
 template<typename T>
 class SGVec4 {
@@ -288,7 +283,12 @@ template<typename T>
 inline
 SGVec4<T>
 normalize(const SGVec4<T>& v)
-{ return (1/norm(v))*v; }
+{
+  T normv = norm(v);
+  if (normv <= SGLimits<T>::min())
+    return SGVec4<T>::zeros();
+  return (1/normv)*v;
+}
 
 /// Return true if exactly the same
 template<typename T>
@@ -383,6 +383,18 @@ T
 distSqr(const SGVec4<T>& v1, const SGVec4<T>& v2)
 { SGVec4<T> tmp = v1 - v2; return dot(tmp, tmp); }
 
+// calculate the projection of u along the direction of d.
+template<typename T>
+inline
+SGVec4<T>
+projection(const SGVec4<T>& u, const SGVec4<T>& d)
+{
+  T denom = dot(d, d);
+  T ud = dot(u, d);
+  if (SGLimits<T>::min() < denom) return u;
+  else return d * (dot(u, d) / denom);
+}
+
 #ifndef NDEBUG
 template<typename T>
 inline
@@ -411,26 +423,4 @@ SGVec4d
 toVec4d(const SGVec4f& v)
 { return SGVec4d(v(0), v(1), v(2), v(3)); }
 
-#ifndef NO_OPENSCENEGRAPH_INTERFACE
-inline
-SGVec4d
-toSG(const osg::Vec4d& v)
-{ return SGVec4d(v[0], v[1], v[2], v[3]); }
-
-inline
-SGVec4f
-toSG(const osg::Vec4f& v)
-{ return SGVec4f(v[0], v[1], v[2], v[3]); }
-
-inline
-osg::Vec4d
-toOsg(const SGVec4d& v)
-{ return osg::Vec4d(v[0], v[1], v[2], v[3]); }
-
-inline
-osg::Vec4f
-toOsg(const SGVec4f& v)
-{ return osg::Vec4f(v[0], v[1], v[2], v[3]); }
-#endif
-
 #endif