]> git.mxchange.org Git - simgear.git/blob - simgear/scene/bvh/BVHGroup.cxx
Propagate the lanel loader through the options.
[simgear.git] / simgear / scene / bvh / BVHGroup.cxx
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 #include "BVHGroup.hxx"
19
20 #include <algorithm>
21
22 namespace simgear {
23
24 BVHGroup::BVHGroup()
25 {
26 }
27
28 BVHGroup::~BVHGroup()
29 {
30     ChildList::iterator i;
31     for (i = _children.begin(); i != _children.end(); ++i) {
32         (*i)->removeParent(this);
33         *i = 0;
34     }
35 }
36
37 void
38 BVHGroup::accept(BVHVisitor& visitor)
39 {
40     visitor.apply(*this);
41 }
42
43 void
44 BVHGroup::clear()
45 {
46     _children.clear();
47     invalidateBound();
48 }
49
50 void
51 BVHGroup::addChild(BVHNode* child)
52 {
53     if (!child)
54         return;
55     ChildList::iterator i;
56     i = std::find(_children.begin(), _children.end(), child);
57     if (i != _children.end())
58         return;
59     invalidateBound();
60     child->addParent(this);
61     _children.push_back(child);
62 }
63
64 void
65 BVHGroup::removeChild(BVHNode* child)
66 {
67     if (!child)
68         return;
69     ChildList::iterator i;
70     i = std::find(_children.begin(), _children.end(), child);
71     if (i == _children.end())
72         return;
73     invalidateBound();
74     child->removeParent(this);
75     _children.erase(i);
76 }
77
78 SGSphered
79 BVHGroup::computeBoundingSphere() const
80 {
81     SGSphered sphere;
82     ChildList::const_iterator i;
83     for (i = _children.begin(); i != _children.end(); ++i)
84         sphere.expandBy((*i)->getBoundingSphere());
85     return sphere;
86 }
87
88 }