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 #include <simgear/math/SGMath.hxx>
32 using namespace simgear;
34 CheckSceneryVisitor::CheckSceneryVisitor(osgDB::DatabasePager* dbp, const osg::Vec3 &position, double range,
35 osg::FrameStamp* framestamp)
36 :osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR,
37 osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN),
38 _position(position), _range(range), _loaded(true), _matrix(osg::Matrix::identity())
40 setDatabaseRequestHandler(dbp);
41 setFrameStamp(framestamp);
44 void CheckSceneryVisitor::apply(osg::Node& node)
49 void CheckSceneryVisitor::apply(osg::ProxyNode& node)
51 osg::Vec3 pos = node.getCenter() * _matrix;
52 double dist = (pos - _position).length();
54 for (unsigned i = 0; i < node.getNumFileNames(); ++i) {
55 if (node.getFileName(i).empty())
57 // Check if this is already loaded.
58 if (i < node.getNumChildren() && node.getChild(i))
61 // if the DatabasePager would load LODs while the splashscreen
62 // is there, we could just wait for the models to be loaded
63 // by only setting setLoaded(false) here
64 osg::NodePath nodePath = getNodePath();
65 DatabaseRequestHandler* db = getDatabaseRequestHandler();
66 const osg::FrameStamp* fs = getFrameStamp();
67 db->requestNodeFile(node.getFileName(i), nodePath, 1.0 /*priority*/, fs,
68 node.getDatabaseRequest(i), node.getDatabaseOptions());
75 void CheckSceneryVisitor::apply(osg::PagedLOD& node)
77 osg::Vec3 pos = node.getCenter() * _matrix;
78 double dist = (pos - _position).length();
80 for (unsigned i = 0; i < node.getNumFileNames(); ++i) {
81 if (node.getFileName(i).empty())
83 // Check if this is already loaded.
84 if (i < node.getNumChildren() && node.getChild(i))
87 // if the DatabasePager would load LODs while the splashscreen
88 // is there, we could just wait for the models to be loaded
89 // by only setting setLoaded(false) here
90 osg::NodePath nodePath = getNodePath();
91 DatabaseRequestHandler* db = getDatabaseRequestHandler();
92 const osg::FrameStamp* fs = getFrameStamp();
93 db->requestNodeFile(node.getFileName(i), nodePath, 1.0 /*priority*/, fs,
94 node.getDatabaseRequest(i), node.getDatabaseOptions());
101 void CheckSceneryVisitor::apply(osg::Transform &node)
103 osg::Matrix matrix = _matrix;
104 node.computeLocalToWorldMatrix(_matrix, this);