[osg-users] Moving from Producer to osgViewer

Robert Osfield robert.osfield at gmail.com
Fri Jul 25 12:13:05 PDT 2008


Hi Bruno,

osgViewer != osgProducer, but pretty well all of Producer
functionality is available + much new functionality and flexibility.
Naming has changed to better reflect OpenGL naming conventions -
something that the core OSG has always done, Producer diverged from
this occassionally.

FYI:
>
> //ISSUE #6: setLensAutoAspect() equivalent not found in
> //osg::Camera
> camera_obj->setLensAutoAspect(true);

        enum ProjectionResizePolicy
        {
            FIXED, /** Keep the projection matrix fixed, despite
window resizes.*/
            HORIZONTAL, /** Adjust the HORIZOTNAL field of view on
window resizes.*/
            VERTICAL /** Adjust the VERTICAL field of view on window resizes.*/
        };

        /** Set the policy used to determine if and how the projection
matrix should be adjusted on window resizes. */
        inline void setProjectionResizePolicy(ProjectionResizePolicy
policy) { _projectionResizePolicy = policy; }


> //ISSUE #8: osg::Camera::setProjectionMatrix() was
> //the closest method found
> camera_obj->setOffset( matrix.ptr() );

Producer::Camear::setLens is roughly equivilant to
osg::Camera::setProjectMatrix*().

osg::Camera doesn't not embed the master/slave projection matrix
offset, so there is no setOffset() method.

Instead the osg::View "has a" master Camera, and a optional list of
slave Camera, and the addSlave method provides the mechnism for
specifying the view and projection matrix offsets for the slaves.

> //ISSUE #9: no equivalent method for setSceneDecorator() was found
> viewer_obj->setSceneDecorator( hud );

Please have a look at the osghud example, and in particular think
about the code segment that uses a Viewer slave Camera to do the hud.
You can also add a hud Camera directly to the GraphicsWindow if you so
wished.

So rather no equivalant, there is actually far better replacements...

> //ISSUE #10: no equivalent method for setViewByMatrix() was found
> viewer_obj->setViewByMatrix( Producer::Matrix( matrixd.ptr() ) );

viewer->getCamera()->setViewMatrix()...

osgViewer::Viewer "has a" Camera, rather than osgProducer::Viewer
which "is a" Camera.


> //ISSUE #11: no equivalent method for update() was found
> viewer_obj->update();
>
> //ISSUE #12: no equivalent method for frame() was found
> camera_obj->frame( false );

viewer.frame();

Which can be broken down into phases - updateTraversal(),
eventTraversal(), and renderingTraversals()


> //ISSUE #14: equivalent class of SceneHandlerList not found
> for(SceneHandlerList::iterator itr = viewer_obj->_shvec.begin();
> itr != viewer_obj->_shvec.end(); ++itr)
> {
>        osgDB::Registry::instance()->getOrCreateDatabasePager()->
>        setCompileGLObjectsForContextID(
>        (*itr)->getSceneView()->getState()->getContextID(), false );
> }

This type of code is totally redundant in osgViewer, just remove it
form your code.

Please spend some time getting to know osgViewer, rather than just
trying to map osgProducer::Viewer to osgViewer::Viewer.  Lots of
things that were really hacky in osgProducer::Viewer are much cleaner
and more flexible in osgViewer, but you'll need to get out of the
osgProducer::Viewer/Producer mind set.

Robert.



More information about the osg-users mailing list