From 7beaf3705ec3e58abc7c5d06b31a5e8724102de1 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 23 Jul 2010 13:04:09 +0100 Subject: [PATCH] Add closest-point calculation to SGRay, to replace a vector.h helper. --- simgear/math/SGRay.hxx | 6 ++++++ 1 file changed, 6 insertions(+) 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; -- 2.39.5