]> git.mxchange.org Git - simgear.git/commitdiff
Add closest-point calculation to SGRay, to replace a vector.h helper.
authorJames Turner <zakalawe@mac.com>
Fri, 23 Jul 2010 12:04:09 +0000 (13:04 +0100)
committerJames Turner <zakalawe@mac.com>
Fri, 23 Jul 2010 12:04:09 +0000 (13:04 +0100)
simgear/math/SGRay.hxx

index afd7b0413f11d27449e51a0b8f480576cd7959c5..eef28cc46beadbae5ae2582fbddf0e7045fd3d1a 100644 (file)
@@ -47,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;