osgEarth 2.1.1
|
Public Member Functions | |
AutoClipPlaneHandler (const Map *map=0L) | |
void | setAutoFarPlaneClipping (bool enabled) |
bool | getAutoFarPlaneClipping () const |
virtual bool | handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) |
void | frame (osgGA::GUIActionAdapter &aa) |
Private Attributes | |
osg::observer_ptr < osgEarth::MapNode > | _mapNode |
bool | _geocentric |
int | _frame |
double | _nfrAtRadius |
double | _nfrAtDoubleRadius |
double | _rp |
bool | _autoFarPlaneClipping |
An event handler that automatically calculates optimal near and far clip planes for a geocentric map node. Just add this to your main Viewer and go.
This only works properly for geocentric (round earth) maps.
Definition at line 38 of file AutoClipPlaneHandler.
AutoClipPlaneHandler::AutoClipPlaneHandler | ( | const Map * | map = 0L | ) |
Constructs a new clip plane handler.
Definition at line 25 of file AutoClipPlaneHandler.cpp.
: _geocentric(false), _frame(0), _nfrAtRadius( 0.00001 ), _nfrAtDoubleRadius( 0.0049 ), _rp( -1 ), _autoFarPlaneClipping(true) { //NOP if ( map ) { _geocentric = map->isGeocentric(); if ( _geocentric ) _rp = map->getProfile()->getSRS()->getEllipsoid()->getRadiusPolar(); } }
void AutoClipPlaneHandler::frame | ( | osgGA::GUIActionAdapter & | aa | ) |
Definition at line 53 of file AutoClipPlaneHandler.cpp.
{ osg::Camera* cam = aa.asView()->getCamera(); if ( _rp < 0 ) { osg::ref_ptr<MapNode> tempNode = osgEarth::findTopMostNodeOfType<MapNode>( cam ); if ( tempNode.valid() && tempNode->getMap()->getProfile() ) { _geocentric = tempNode->getMap()->isGeocentric(); if ( _geocentric ) _rp = tempNode->getMap()->getProfile()->getSRS()->getEllipsoid()->getRadiusPolar(); else OE_INFO << "[AutoClipPlaneHandler] disabled for non-geocentric map" << std::endl; //_mapNode = tempNode.get(); } } if ( _rp > 0 && _geocentric ) // _mapNode.valid() && _geocentric ) { cam->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR ); osg::Vec3d eye, center, up; cam->getViewMatrixAsLookAt( eye, center, up ); double d = eye.length(); if ( d < _rp ) d = _rp; if ( d > _rp ) { double fovy, ar, znear, zfar, finalZfar; cam->getProjectionMatrixAsPerspective( fovy, ar, znear, finalZfar ); // far clip at the horizon: zfar = sqrt( d*d - _rp*_rp ); if (_autoFarPlaneClipping) { finalZfar = zfar; } double nfr = _nfrAtRadius + _nfrAtDoubleRadius * ((d-_rp)/d); znear = osg::clampAbove( zfar * nfr, 1.0 ); cam->setProjectionMatrixAsPerspective( fovy, ar, znear, finalZfar ); //OE_NOTICE << fixed // << "near=" << znear << ", far=" << zfar << std::endl; } } }
bool osgEarth::Util::AutoClipPlaneHandler::getAutoFarPlaneClipping | ( | ) | const [inline] |
Definition at line 50 of file AutoClipPlaneHandler.
{ return _autoFarPlaneClipping; }
bool AutoClipPlaneHandler::handle | ( | const osgGA::GUIEventAdapter & | ea, |
osgGA::GUIActionAdapter & | aa | ||
) | [virtual] |
Definition at line 43 of file AutoClipPlaneHandler.cpp.
{ if ( ea.getEventType() == osgGA::GUIEventAdapter::FRAME && _frame++ > 1 ) { frame( aa ); } return false; }
void osgEarth::Util::AutoClipPlaneHandler::setAutoFarPlaneClipping | ( | bool | enabled | ) | [inline] |
Whether to automatically set the far clip to the horizon. default=true.
Definition at line 49 of file AutoClipPlaneHandler.
{ _autoFarPlaneClipping = enabled; }
bool osgEarth::Util::AutoClipPlaneHandler::_autoFarPlaneClipping [private] |
Definition at line 65 of file AutoClipPlaneHandler.
int osgEarth::Util::AutoClipPlaneHandler::_frame [private] |
Definition at line 63 of file AutoClipPlaneHandler.
bool osgEarth::Util::AutoClipPlaneHandler::_geocentric [private] |
Definition at line 62 of file AutoClipPlaneHandler.
osg::observer_ptr<osgEarth::MapNode> osgEarth::Util::AutoClipPlaneHandler::_mapNode [private] |
Definition at line 61 of file AutoClipPlaneHandler.
double osgEarth::Util::AutoClipPlaneHandler::_nfrAtDoubleRadius [private] |
Definition at line 64 of file AutoClipPlaneHandler.
double osgEarth::Util::AutoClipPlaneHandler::_nfrAtRadius [private] |
Definition at line 64 of file AutoClipPlaneHandler.
double osgEarth::Util::AutoClipPlaneHandler::_rp [private] |
Definition at line 64 of file AutoClipPlaneHandler.