void MxCore::updateFovy( osg::Matrixd& proj ) const { if( _ortho ) { osg::notify( osg::WARN ) << "MxCore::updateFovy: Ortho is not yet implemented. TBD." << std::endl; } else { double left, right, bottom, top, near, far; proj.getFrustum( left, right, bottom, top, near, far ); const double fovBottom = atan( bottom / near ); const double fovTop = atan( top / near ); const double fovyRatio = getFovyRadians() / ( osg::absolute< double >( fovBottom ) + osg::absolute< double >( fovTop ) ); const double newBottom = tan( fovBottom * fovyRatio ) * near; const double newTop = tan( fovTop * fovyRatio ) * near; const double xScale = newTop / top; left *= xScale; right *= xScale; proj = osg::Matrixd::frustum( left, right, newBottom, newTop, near, far ); } }
void MxCore::setOrtho( bool ortho, const double viewDistance ) { _ortho = ortho; // tan (fovy/2) = a / e2c.len _orthoTop = tan( getFovyRadians() * .5 ) * viewDistance; _orthoBottom = -_orthoTop; }
void ViewingCore::fitToScreen() { _viewCenter = _scene->getBound().center(); // tan( fovy/2. ) = bs.radius / distance // Solve for distance: // distance = bs.radius / tan( fovy/2. ) _fovy = 30; float distance = _scene->getBound().radius() / tan( osg::DegreesToRadians( _fovy/2. ) ); _viewDistance = _initialViewDistance = distance; _orthoTop = tan( getFovyRadians() * 0.5 ) * _viewDistance; _orthoBottom = -_orthoTop; }