From: James Turner Date: Fri, 23 Jul 2010 12:04:09 +0000 (+0100) Subject: Add closest-point calculation to SGRay, to replace a vector.h helper. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7beaf3705ec3e58abc7c5d06b31a5e8724102de1;p=simgear.git Add closest-point calculation to SGRay, to replace a vector.h helper. --- diff --git a/simgear/math/SGRay.hxx b/simgear/math/SGRay.hxx index afd7b041..eef28cc4 100644 --- a/simgear/math/SGRay.hxx +++ b/simgear/math/SGRay.hxx @@ -47,6 +47,12 @@ public: SGVec3 getNormalizedDirection() const { return normalize(getDirection()); } + SGVec3 getClosestPointTo(const SGVec3& point) + { + SGVec3 u(getNormalizedDirection()), + v(point - _origin); + return (dot(u, v) * u) + _origin; + } private: SGVec3 _origin; SGVec3 _direction;