1 // Copyright (C) 2006 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 SGRay(const SGVec3<T>& origin, const SGVec3<T>& dir) :
27 _origin(origin), _direction(dir)
30 explicit SGRay(const SGRay<S>& ray) :
31 _origin(ray.getOrigin()), _direction(ray.getDirection())
34 void set(const SGVec3<T>& origin, const SGVec3<T>& dir)
35 { _origin = origin; _direction = dir; }
37 void setOrigin(const SGVec3<T>& origin)
39 const SGVec3<T>& getOrigin() const
42 void setDirection(const SGVec3<T>& direction)
43 { _direction = direction; }
44 const SGVec3<T>& getDirection() const
45 { return _direction; }
47 SGVec3<T> getNormalizedDirection() const
48 { return normalize(getDirection()); }
50 SGVec3<T> getClosestPointTo(const SGVec3<T>& point)
52 SGVec3<T> u(getNormalizedDirection()),
54 return (dot(u, v) * u) + _origin;
61 /// Output to an ostream
62 template<typename char_type, typename traits_type, typename T>
64 std::basic_ostream<char_type, traits_type>&
65 operator<<(std::basic_ostream<char_type, traits_type>& s,
68 return s << "ray: origin = " << ray.getOrigin()
69 << ", direction = " << ray.getDirection();