Hi all!

I have two cameras and I want to see the same level of detail in camera 
2 as in camera 1, no matter how far away the cameras are from any 
objects containing LOD/PagedLOD nodes.

I'm inheriting from osgUtil::Cullvisitor. My class specialization knows 
the position of camera 1 in world space.
I am overriding osgUtil::CullVisitor::getDistanceToEyePoint(const 
osg::Vec3& pos, bool withLODScale).
The idea is to compute the position pos in world space and then compute 
the distance to the position of camera 1 and return this value instead.

Here's my code:

class UTIL_LODOverridableCullVisitor : public osgUtil::CullVisitor
{
public:
    UTIL_LODOverridableCullVisitor()
    {
        m_override = false;
    }
    void enable_override(const osg::Vec3& cam_pos_world)
    {
        m_cam_pos_world = cam_pos_world;
        m_override = true;
    }
    void disable_override()
    {
        m_override = false;
    }
    inline virtual float getDistanceToEyePoint(const osg::Vec3& pos, 
bool withLODScale) const
    {
        if(m_override) {
            osg::Vec3d pos_world = ???; // here I failed terribly :-(
            if(withLODScale)
                return (pos_world-m_cam_pos_world).length()*getLODScale();
            else
                return (pos_world-m_cam_pos_world).length();
        } else {
            return osgUtil::CullVisitor::getDistanceToEyePoint(pos, 
withLODScale);
        }
    }
private:
    bool m_override;
    osg::Vec3d m_cam_pos_world;
};

enable_override() is called just before the cullvisitor enters the node 
of camera 2
disable_override() is called just after, so the override-code is only 
executed for nodes that are viewed by camera 2.

How can i compute the position of the node in world space?
Or is there a more elegant way to do this?

Many thanks,
    helb

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to