]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGRay.hxx
math: Move lerp function into SGMisc.
[simgear.git] / simgear / math / SGRay.hxx
index 8e2b5b350361b2669ba367a9a606464b4068571f..eef28cc46beadbae5ae2582fbddf0e7045fd3d1a 100644 (file)
@@ -26,6 +26,10 @@ public:
   SGRay(const SGVec3<T>& origin, const SGVec3<T>& dir) :
     _origin(origin), _direction(dir)
   { }
+  template<typename S>
+  explicit SGRay(const SGRay<S>& ray) :
+    _origin(ray.getOrigin()), _direction(ray.getDirection())
+  { }
 
   void set(const SGVec3<T>& origin, const SGVec3<T>& dir)
   { _origin = origin; _direction = dir; }
@@ -43,6 +47,12 @@ public:
   SGVec3<T> getNormalizedDirection() const
   { return normalize(getDirection()); }
 
+  SGVec3<T> getClosestPointTo(const SGVec3<T>& point)
+  {
+      SGVec3<T> u(getNormalizedDirection()),
+          v(point - _origin);
+      return (dot(u, v) * u) + _origin; 
+  }
 private:
   SGVec3<T> _origin;
   SGVec3<T> _direction;