Add closest-point calculation to SGRay, to replace a vector.h helper.

This commit is contained in:
James Turner
2010-07-23 13:04:09 +01:00
parent bbd61977f1
commit 7beaf3705e

View 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;