]> git.mxchange.org Git - simgear.git/blob - simgear/bvh/BVHTransform.hxx
Fix removal of directories.
[simgear.git] / simgear / bvh / BVHTransform.hxx
1 // Copyright (C) 2008 - 2009  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 BVHTransform_hxx
19 #define BVHTransform_hxx
20
21 #include "BVHGroup.hxx"
22
23 namespace simgear {
24
25 class BVHTransform : public BVHGroup {
26 public:
27     BVHTransform();
28     virtual ~BVHTransform();
29
30     virtual void accept(BVHVisitor& visitor);
31     
32     void setTransform(const BVHTransform& transform);
33
34     void setToWorldTransform(const SGMatrixd& transform);
35     const SGMatrixd& getToWorldTransform() const
36     { return _toWorld; }
37
38     void setToLocalTransform(const SGMatrixd& transform);
39     const SGMatrixd& getToLocalTransform() const
40     { return _toLocal; }
41     
42     SGVec3d ptToWorld(const SGVec3d& point) const
43     { return _toWorld.xformPt(point); }
44     SGVec3d ptToLocal(const SGVec3d& point) const
45     { return _toLocal.xformPt(point); }
46     
47     SGVec3d vecToWorld(const SGVec3d& vec) const
48     { return _toWorld.xformVec(vec); }
49     SGVec3d vecToLocal(const SGVec3d& vec) const
50     { return _toLocal.xformVec(vec); }
51     
52     SGLineSegmentd lineSegmentToWorld(const SGLineSegmentd& lineSeg) const
53     { return lineSeg.transform(_toWorld); }
54     SGLineSegmentd lineSegmentToLocal(const SGLineSegmentd& lineSeg) const
55     { return lineSeg.transform(_toLocal); }
56     
57     SGSphered sphereToWorld(const SGSphered& sphere) const
58     {
59         SGVec3d center = ptToWorld(sphere.getCenter());
60         double radius = _toWorldAmplification*sphere.getRadius();
61         return SGSphered(center, radius);
62     }
63     SGSphered sphereToLocal(const SGSphered& sphere) const
64     {
65         SGVec3d center = ptToLocal(sphere.getCenter());
66         double radius = _toLocalAmplification*sphere.getRadius();
67         return SGSphered(center, radius);
68     }
69
70 private:
71     virtual SGSphered computeBoundingSphere() const;
72     void updateAmplificationFactors();
73     
74     SGMatrixd _toWorld;
75     SGMatrixd _toLocal;
76     double _toWorldAmplification;
77     double _toLocalAmplification;
78 };
79
80 }
81
82 #endif