Add closest-point calculation to SGRay, to replace a vector.h helper.
This commit is contained in:
@@ -47,6 +47,12 @@ public:
|
|||||||
SGVec3<T> getNormalizedDirection() const
|
SGVec3<T> getNormalizedDirection() const
|
||||||
{ return normalize(getDirection()); }
|
{ return normalize(getDirection()); }
|
||||||
|
|
||||||
|
SGVec3<T> getClosestPointTo(const SGVec3<T>& point)
|
||||||
|
{
|
||||||
|
SGVec3<T> u(getNormalizedDirection()),
|
||||||
|
v(point - _origin);
|
||||||
|
return (dot(u, v) * u) + _origin;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
SGVec3<T> _origin;
|
SGVec3<T> _origin;
|
||||||
SGVec3<T> _direction;
|
SGVec3<T> _direction;
|
||||||
|
|||||||
Reference in New Issue
Block a user