]> git.mxchange.org Git - simgear.git/blob - simgear/bvh/BVHBoundingBoxVisitor.hxx
hla: Use a different extrapolation method for HLALocation.
[simgear.git] / simgear / bvh / BVHBoundingBoxVisitor.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 BVHBoundingBoxVisitor_hxx
19 #define BVHBoundingBoxVisitor_hxx
20
21 #include <simgear/math/SGGeometry.hxx>
22
23 #include "BVHVisitor.hxx"
24 #include "BVHNode.hxx"
25 #include "BVHGroup.hxx"
26 #include "BVHPageNode.hxx"
27 #include "BVHTransform.hxx"
28 #include "BVHMotionTransform.hxx"
29 #include "BVHLineGeometry.hxx"
30
31 #include "BVHStaticData.hxx"
32
33 #include "BVHStaticNode.hxx"
34 #include "BVHStaticTriangle.hxx"
35 #include "BVHStaticBinary.hxx"
36 #include "BVHStaticGeometry.hxx"
37
38 namespace simgear {
39
40 class BVHBoundingBoxVisitor : public BVHVisitor {
41 public:
42     virtual ~BVHBoundingBoxVisitor() {}
43     
44     void clear()
45     { _box.clear(); }
46     
47     virtual void apply(BVHGroup& node)
48     { expandBy(node.getBoundingSphere()); }
49     virtual void apply(BVHPageNode& node)
50     { expandBy(node.getBoundingSphere()); }
51     virtual void apply(BVHTransform& node)
52     { expandBy(node.getBoundingSphere()); }
53     virtual void apply(BVHMotionTransform& node)
54     { expandBy(node.getBoundingSphere()); }
55     virtual void apply(BVHLineGeometry& node)
56     { expandBy(node.getBoundingSphere()); }
57     virtual void apply(BVHStaticGeometry& node)
58     { expandBy(node.getBoundingSphere()); }
59     
60     virtual void apply(const BVHStaticBinary& node, const BVHStaticData& data)
61     { expandBy(node.getBoundingBox()); }
62     virtual void apply(const BVHStaticTriangle& node, const BVHStaticData& data)
63     { expandBy(node.computeBoundingBox(data)); }
64     
65     const SGBoxf& getBox() const
66     { return _box; }
67     
68 private:
69     void expandBy(const SGSphered& sphere)
70     {
71         SGVec3f v0(sphere.getCenter() - sphere.getRadius()*SGVec3d(1, 1, 1));
72         SGVec3f v1(sphere.getCenter() + sphere.getRadius()*SGVec3d(1, 1, 1));
73         _box.expandBy(SGBoxf(v0, v1));
74     }
75     void expandBy(const SGBoxf& box)
76     { _box.expandBy(box); }
77     
78     SGBoxf _box;
79 };
80
81 }
82
83 #endif