]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/CheckSceneryVisitor.cxx
Add preliminary spot light animation
[simgear.git] / simgear / scene / model / CheckSceneryVisitor.cxx
index 56a023680429d92d1f0765bcceeb9970bd1e3253..e0149c069a5a8f6bb00298a05ffba65b1d9ae7bf 100644 (file)
@@ -1,4 +1,5 @@
 // Copyright (C) 2008 Till Busch buti@bux.at
+// Copyright (C) 2011 Mathias Froehlich
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
 #endif
 
 #include <osg/Transform>
+#include <osg/ProxyNode>
+#include <osgDB/DatabasePager>
 
 #include <simgear/debug/logstream.hxx>
 
 #include "CheckSceneryVisitor.hxx"
-#include "SGPagedLOD.hxx"
 
 #include <simgear/math/SGMath.hxx>
 
 using namespace simgear;
 
-CheckSceneryVisitor::CheckSceneryVisitor(osgDB::DatabasePager* dbp, osg::Vec3 &position, double range)
+CheckSceneryVisitor::CheckSceneryVisitor(osgDB::DatabasePager* dbp, const osg::Vec3 &position, double range,
+                                         osg::FrameStamp* framestamp)
 :osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR,
                   osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN),
-_loaded(true), _position(position), _range(range), _dbp(dbp)
+ _position(position), _range(range), _loaded(true), _matrix(osg::Matrix::identity())
 {
-    _viewMatrices.push_back(osg::Matrix::identity());
+    setDatabaseRequestHandler(dbp);
+    setFrameStamp(framestamp);
 }
 
 void CheckSceneryVisitor::apply(osg::Node& node)
@@ -42,35 +46,62 @@ void CheckSceneryVisitor::apply(osg::Node& node)
     traverse(node);
 }
 
-void CheckSceneryVisitor::apply(osg::PagedLOD& node)
+void CheckSceneryVisitor::apply(osg::ProxyNode& node)
 {
-    SGPagedLOD *sgplod = dynamic_cast<SGPagedLOD*>(&node);
-    if (sgplod) {
-        osg::Vec3 pos = sgplod->getCenter() * _viewMatrices.back();
-        double dist = (pos-_position).length();
-        if (dist < _range) {
-            if (sgplod->getNumChildren() < 1) {
-                // if the DatabasePager would load LODs while the splashscreen
-                // is there, we could just wait for the models to be loaded
-                // by only setting setLoaded(false) here
-                sgplod->forceLoad(_dbp);
-                setLoaded(false);
-            }
+    osg::Vec3 pos = node.getCenter() * _matrix;
+    double dist = (pos - _position).length();
+    if (dist < _range) {
+        for (unsigned i = 0; i < node.getNumFileNames(); ++i) {
+            if (node.getFileName(i).empty())
+                continue;
+            // Check if this is already loaded.
+            if (i < node.getNumChildren() && node.getChild(i))
+                continue;
+
+            // if the DatabasePager would load LODs while the splashscreen
+            // is there, we could just wait for the models to be loaded
+            // by only setting setLoaded(false) here
+            osg::NodePath nodePath = getNodePath();
+            DatabaseRequestHandler* db = getDatabaseRequestHandler();
+            const osg::FrameStamp* fs = getFrameStamp();
+            db->requestNodeFile(node.getFileName(i), nodePath, 1.0 /*priority*/, fs,
+                                node.getDatabaseRequest(i), node.getDatabaseOptions());
+            setLoaded(false);
         }
     }
     traverse(node);
 }
 
-void CheckSceneryVisitor::apply(osg::Transform &node)
+void CheckSceneryVisitor::apply(osg::PagedLOD& node)
 {
-    osg::Matrix currMatrix = _viewMatrices.back();
-    bool pushMatrix = node.computeLocalToWorldMatrix(currMatrix, this);
+    osg::Vec3 pos = node.getCenter() * _matrix;
+    double dist = (pos - _position).length();
+    if (dist < _range) {
+        for (unsigned i = 0; i < node.getNumFileNames(); ++i) {
+            if (node.getFileName(i).empty())
+                continue;
+            // Check if this is already loaded.
+            if (i < node.getNumChildren() && node.getChild(i))
+                continue;
 
-    if (pushMatrix) {
-        _viewMatrices.push_back(currMatrix);
+            // if the DatabasePager would load LODs while the splashscreen
+            // is there, we could just wait for the models to be loaded
+            // by only setting setLoaded(false) here
+            osg::NodePath nodePath = getNodePath();
+            DatabaseRequestHandler* db = getDatabaseRequestHandler();
+            const osg::FrameStamp* fs = getFrameStamp();
+            db->requestNodeFile(node.getFileName(i), nodePath, 1.0 /*priority*/, fs,
+                                node.getDatabaseRequest(i), node.getDatabaseOptions());
+            setLoaded(false);
+        }
     }
     traverse(node);
-    if (pushMatrix) {
-        _viewMatrices.pop_back();
-    }
+}
+
+void CheckSceneryVisitor::apply(osg::Transform &node)
+{
+    osg::Matrix matrix = _matrix;
+    node.computeLocalToWorldMatrix(_matrix, this);
+    traverse(node);
+    _matrix = matrix;
 }