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 #ifndef OSGEARTHUTIL_AUTOCLIPPLANEHANDLER_H 00020 #define OSGEARTHUTIL_AUTOCLIPPLANEHANDLER_H 00021 00022 #include <osgEarthUtil/Common> 00023 #include <osgEarth/MapNode> 00024 #include <osgGA/GUIEventHandler> 00025 #include <osgGA/EventVisitor> 00026 00027 namespace osgEarth { namespace Util 00028 { 00029 using namespace osgEarth; 00030 00038 class OSGEARTHUTIL_EXPORT AutoClipPlaneHandler : public osgGA::GUIEventHandler 00039 { 00040 public: 00044 AutoClipPlaneHandler( const Map* map =0L ); 00045 00049 void setAutoFarPlaneClipping(bool enabled) { _autoFarPlaneClipping = enabled; } 00050 bool getAutoFarPlaneClipping() const { return _autoFarPlaneClipping; } 00051 00052 00053 public: // EventHandler 00054 00055 virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ); 00056 00057 void frame( osgGA::GUIActionAdapter& aa ); 00058 00059 private: 00060 00061 osg::observer_ptr<osgEarth::MapNode> _mapNode; 00062 bool _geocentric; 00063 int _frame; 00064 double _nfrAtRadius, _nfrAtDoubleRadius, _rp; 00065 bool _autoFarPlaneClipping; 00066 }; 00067 00068 00069 class OSGEARTHUTIL_EXPORT AutoClipPlaneCallback : public osg::NodeCallback 00070 { 00071 public: 00072 AutoClipPlaneCallback( const Map* map =0L ) 00073 { 00074 _handler = new AutoClipPlaneHandler( map ); 00075 } 00076 00077 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ) 00078 { 00079 osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>( nv ); 00080 if ( ev ) { 00081 _handler->frame( *ev->getActionAdapter() ); 00082 } 00083 traverse( node, nv ); 00084 } 00085 00086 osg::ref_ptr<AutoClipPlaneHandler> _handler; 00087 }; 00088 00089 } } // namespace osgEarth::Util 00090 00091 #endif // OSGEARTHUTIL_AUTOCLIPPLANEHANDLER_H 00092