1 // Copyright (C) 2008 Till Busch buti@bux.at
2 // Copyright (C) 2011 Mathias Froehlich
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # include <simgear_config.h>
22 #include <osg/Transform>
23 #include <osg/ProxyNode>
24 #include <osgDB/DatabasePager>
26 #include <simgear/debug/logstream.hxx>
28 #include "CheckSceneryVisitor.hxx"
30 using namespace simgear;
32 CheckSceneryVisitor::CheckSceneryVisitor(osgDB::DatabasePager* dbp, const osg::Vec3 &position, double range,
33 osg::FrameStamp* framestamp)
34 :osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR,
35 osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN),
36 _position(position), _range(range), _loaded(true), _matrix(osg::Matrix::identity())
38 setDatabaseRequestHandler(dbp);
39 setFrameStamp(framestamp);
42 void CheckSceneryVisitor::apply(osg::Node& node)
47 void CheckSceneryVisitor::apply(osg::ProxyNode& node)
49 osg::Vec3 pos = node.getCenter() * _matrix;
50 double dist = (pos - _position).length();
52 for (unsigned i = 0; i < node.getNumFileNames(); ++i) {
53 if (node.getFileName(i).empty())
55 // Check if this is already loaded.
56 if (i < node.getNumChildren() && node.getChild(i))
59 // if the DatabasePager would load LODs while the splashscreen
60 // is there, we could just wait for the models to be loaded
61 // by only setting setLoaded(false) here
62 osg::NodePath nodePath = getNodePath();
63 DatabaseRequestHandler* db = getDatabaseRequestHandler();
64 const osg::FrameStamp* fs = getFrameStamp();
65 db->requestNodeFile(node.getFileName(i), nodePath, 1.0 /*priority*/, fs,
66 node.getDatabaseRequest(i), node.getDatabaseOptions());
73 void CheckSceneryVisitor::apply(osg::PagedLOD& node)
75 osg::Vec3 pos = node.getCenter() * _matrix;
76 double dist = (pos - _position).length();
78 for (unsigned i = 0; i < node.getNumFileNames(); ++i) {
79 if (node.getFileName(i).empty())
81 // Check if this is already loaded.
82 if (i < node.getNumChildren() && node.getChild(i))
85 // if the DatabasePager would load LODs while the splashscreen
86 // is there, we could just wait for the models to be loaded
87 // by only setting setLoaded(false) here
88 osg::NodePath nodePath = getNodePath();
89 DatabaseRequestHandler* db = getDatabaseRequestHandler();
90 const osg::FrameStamp* fs = getFrameStamp();
91 db->requestNodeFile(node.getFileName(i), nodePath, 1.0 /*priority*/, fs,
92 node.getDatabaseRequest(i), node.getDatabaseOptions());
99 void CheckSceneryVisitor::apply(osg::Transform &node)
101 osg::Matrix matrix = _matrix;
102 node.computeLocalToWorldMatrix(_matrix, this);