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 BVHStaticBinary_hxx
19 #define BVHStaticBinary_hxx
21 #include <simgear/math/SGGeometry.hxx>
22 #include <simgear/structure/SGSharedPtr.hxx>
23 #include "BVHStaticNode.hxx"
27 class BVHStaticBinary : public BVHStaticNode {
29 BVHStaticBinary(unsigned splitAxis, const BVHStaticNode* leftChild,
30 const BVHStaticNode* rightChild, const SGBoxf& box);
31 virtual ~BVHStaticBinary();
32 virtual void accept(BVHVisitor& visitor, const BVHStaticData& data) const;
34 void traverse(BVHVisitor& visitor, const BVHStaticData& data) const
36 _leftChild->accept(visitor, data);
37 _rightChild->accept(visitor, data);
40 // Traverse call that first enters the child node that is potentially closer
41 // to the given point than the other.
43 void traverse(BVHVisitor& visitor, const BVHStaticData& data,
44 const SGVec3<T>& pt) const
46 float center = 0.5f*(_boundingBox.getMin()[_splitAxis]
47 + _boundingBox.getMax()[_splitAxis]);
48 if (pt[_splitAxis] < center) {
49 _leftChild->accept(visitor, data);
50 _rightChild->accept(visitor, data);
52 _rightChild->accept(visitor, data);
53 _leftChild->accept(visitor, data);
57 unsigned getSplitAxis() const
58 { return _splitAxis; }
60 const BVHStaticNode* getLeftChild() const
61 { return _leftChild; }
62 const BVHStaticNode* getRightChild() const
63 { return _rightChild; }
65 const SGBoxf& getBoundingBox() const
66 { return _boundingBox; }
69 // Note the order of the members, this is to avoid padding
71 SGSharedPtr<const BVHStaticNode> _leftChild;
72 SGSharedPtr<const BVHStaticNode> _rightChild;