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