osgEarth 2.1.1
Public Member Functions | Public Attributes

anonymous_namespace{SkyNode.cpp}::OverrideNearFarValuesCallback Struct Reference

List of all members.

Public Member Functions

 OverrideNearFarValuesCallback (double radius)
virtual void drawImplementation (osg::RenderInfo &renderInfo, const osg::Drawable *drawable) const

Public Attributes

double _radius

Detailed Description

Definition at line 81 of file SkyNode.cpp.


Constructor & Destructor Documentation

anonymous_namespace{SkyNode.cpp}::OverrideNearFarValuesCallback::OverrideNearFarValuesCallback ( double  radius) [inline]

Definition at line 83 of file SkyNode.cpp.

            : _radius(radius) {}

Member Function Documentation

virtual void anonymous_namespace{SkyNode.cpp}::OverrideNearFarValuesCallback::drawImplementation ( osg::RenderInfo &  renderInfo,
const osg::Drawable *  drawable 
) const [inline, virtual]

Definition at line 86 of file SkyNode.cpp.

        {
            osg::Camera* currentCamera = renderInfo.getCurrentCamera();
            if (currentCamera)
            {
                // Get the current camera position.
                osg::Vec3 eye, center, up;
                renderInfo.getCurrentCamera()->getViewMatrixAsLookAt( eye, center, up);

                // Get the max distance we need the far plane to be at,
                // which is the distance between the eye and the origin
                // plus the distant from the origin to the object (star sphere
                // radius, sun distance etc), and then some.
                double distance = eye.length() + _radius*2;

                // Save old values.
                osg::ref_ptr<osg::RefMatrixd> oldProjectionMatrix = new osg::RefMatrix;
                oldProjectionMatrix->set( renderInfo.getState()->getProjectionMatrix());

                // Get the individual values
                double left, right, bottom, top, zNear, zFar;
                oldProjectionMatrix->getFrustum( left, right, bottom, top, zNear, zFar);

                // Build a new projection matrix with a modified far plane
                osg::ref_ptr<osg::RefMatrixd> projectionMatrix = new osg::RefMatrix;
                //projectionMatrix->makeFrustum( left, right, bottom, top, zNear, distance);
                //OE_INFO << "zNear=" << zNear << ", zFar=" << zFar << std::endl;
                projectionMatrix->makeFrustum( left, right, bottom, top, zNear, distance );
                renderInfo.getState()->applyProjectionMatrix( projectionMatrix.get());

                // Draw the drawable
                drawable->drawImplementation(renderInfo);

                // Reset the far plane to the old value.
                renderInfo.getState()->applyProjectionMatrix( oldProjectionMatrix.get() );
            }
            else
            {
                drawable->drawImplementation(renderInfo);
            }
        }

Member Data Documentation

double anonymous_namespace{SkyNode.cpp}::OverrideNearFarValuesCallback::_radius

Definition at line 129 of file SkyNode.cpp.


The documentation for this struct was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines