]> git.mxchange.org Git - simgear.git/blob - simgear/math/SGRay.hxx
- allow for (rather unusual) ////// cloud groups
[simgear.git] / simgear / math / SGRay.hxx
1 // Copyright (C) 2006  Mathias Froehlich - Mathias.Froehlich@web.de
2 //
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.
7 //
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.
12 //
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.
16 //
17
18 #ifndef SGRay_H
19 #define SGRay_H
20
21 template<typename T>
22 class SGRay {
23 public:
24   SGRay()
25   { }
26   SGRay(const SGVec3<T>& origin, const SGVec3<T>& dir) :
27     _origin(origin), _direction(dir)
28   { }
29
30   void set(const SGVec3<T>& origin, const SGVec3<T>& dir)
31   { _origin = origin; _direction = dir; }
32
33   void setOrigin(const SGVec3<T>& origin)
34   { _origin = origin; }
35   const SGVec3<T>& getOrigin() const
36   { return _origin; }
37
38   void setDirection(const SGVec3<T>& direction)
39   { _direction = direction; }
40   const SGVec3<T>& getDirection() const
41   { return _direction; }
42
43   SGVec3<T> getNormalizedDirection() const
44   { return normalize(getDirection()); }
45
46 private:
47   SGVec3<T> _origin;
48   SGVec3<T> _direction;
49 };
50
51 /// Output to an ostream
52 template<typename char_type, typename traits_type, typename T>
53 inline
54 std::basic_ostream<char_type, traits_type>&
55 operator<<(std::basic_ostream<char_type, traits_type>& s,
56            const SGRay<T>& ray)
57 {
58   return s << "ray: origin = " << ray.getOrigin()
59            << ", direction = " << ray.getDirection();
60 }
61
62 #endif