osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 #include "DRoamNode" 00020 #include "CubeManifold" 00021 #include "GeodeticManifold" 00022 #include <osgEarth/Cube> 00023 #include <osgEarthDrivers/tms/TMSOptions> 00024 00025 using namespace osgEarth::Drivers; 00026 00027 #undef USE_GEODETIC_MANIFOLD 00028 00029 DRoamNode::DRoamNode( Map* map ) : 00030 _map( map ) 00031 { 00032 this->setCullCallback( new MyCullCallback ); 00033 this->setUpdateCallback( new MyUpdateCallback ); 00034 00035 // TODO: provide the ellipsoid in the ctor (like with MapNode->Map) 00036 this->setCoordinateSystem( "EPSG:4326" ); 00037 this->setFormat( "WKT" ); 00038 this->setEllipsoidModel( new osg::EllipsoidModel ); 00039 00040 #ifdef USE_GEODETIC_MANIFOLD 00041 _manifold = new GeodeticManifold(); 00042 #else 00043 _manifold = new CubeManifold(); 00044 #endif 00045 _mesh = new MeshManager( _manifold.get(), _map.get() ); 00046 00047 _mesh->_maxActiveLevel = MAX_ACTIVE_LEVEL; 00048 00049 this->setInitialBound( _manifold->initialBound() ); 00050 00051 this->addChild( _mesh->_amrGeode.get() ); 00052 00053 this->getOrCreateStateSet()->setMode( GL_LIGHTING, 0 ); 00054 } 00055 00056 DRoamNode::DRoamNode( const DRoamNode& rhs, const osg::CopyOp& op ) : 00057 osg::CoordinateSystemNode( rhs, op ), 00058 _manifold( rhs._manifold.get() ) 00059 { 00060 //nop 00061 } 00062 00063 void 00064 DRoamNode::cull( osg::NodeVisitor* nv ) 00065 { 00066 osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>( nv ); 00067 00068 // reset the drawable set list. we will populate it by traversing the 00069 // manifold and collecting drawables that are visible. The new drawables 00070 // list does not actually take effect until the next frame. So yes, the culling is 00071 // one frame out of sync with the draw. We should probably think of a way to fix that. 00072 //_mesh->_activeDrawables.clear(); 00073 00074 _mesh->_amrDrawList.clear(); 00075 00076 _manifold->cull( static_cast<osgUtil::CullVisitor*>( nv ) ); 00077 00078 // I know is not strictly kosher to modify the scene graph from the CULL traversal. But 00079 // we need frame-coherence, and both the Geode and all Geometry's are marked with DYNAMIC 00080 // data variance .. so hopefully this is safe. 00081 _mesh->_amrGeom->setDrawList( _mesh->_amrDrawList ); 00082 _mesh->_amrGeode->dirtyBound(); 00083 } 00084 00085 void 00086 DRoamNode::update( osg::NodeVisitor* nv ) 00087 { 00088 _mesh->update(); 00089 }