1 // Copyright (C) 2008 - 2009 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.
18 #ifndef BVHBoundingBoxVisitor_hxx
19 #define BVHBoundingBoxVisitor_hxx
21 #include <simgear/math/SGGeometry.hxx>
23 #include "BVHVisitor.hxx"
24 #include "BVHNode.hxx"
25 #include "BVHGroup.hxx"
26 #include "BVHTransform.hxx"
27 #include "BVHMotionTransform.hxx"
28 #include "BVHLineGeometry.hxx"
30 #include "BVHStaticData.hxx"
32 #include "BVHStaticNode.hxx"
33 #include "BVHStaticTriangle.hxx"
34 #include "BVHStaticBinary.hxx"
35 #include "BVHStaticGeometry.hxx"
39 class BVHBoundingBoxVisitor : public BVHVisitor {
41 virtual ~BVHBoundingBoxVisitor() {}
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()); }
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)); }
62 const SGBoxf& getBox() const
66 void expandBy(const SGSphered& sphere)
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));
72 void expandBy(const SGBoxf& box)
73 { _box.expandBy(box); }