[osg-users] Camera position not resetting

Mario Valle mvalle at cscs.ch
Tue Sep 25 19:49:51 PDT 2007


I create and display an empty scene and later add my model to it.
It works, but the camera position is not reset after adding the model, 
so half of it lies outside the screen. Pressing space obviously reset 
the camera position and all my model appears on the screen.

What I'm doing is:
    sceneRoot = new osg::Group;
    viewer->setSceneData(sceneRoot.get());
    ... and later after some GUI selection ...
    osg::ref_ptr<osg::Group> myscene = new osg::Group;
    ... fill myscene ...
    sceneRoot->addChild(scene.get());

I tried various combination of dirtyBound() and computeBound() on 
sceneRoot and myscene without success.

Also trying to explicitly set the camera position as below seems to have 
no effect: for example I change the eye position but the scene
looks always the same.
    const osg::BoundingSphere& boundingSphere= scene->getBound();
    osg::Vec3 eye = boundingSphere._center+osg::Vec3(0.0f, -3.5f * 
boundingSphere._radius, 0.0f);
    osg::Vec3 center = boundingSphere._center;
    osg::Vec3 up = osg::Vec3(0.0f, 0.0f, 1.0f);
    viewer->getCamera()->setViewMatrixAsLookAt(eye, center, up);

The only thing that makes a difference is to move the 
viewer->setSceneData(sceneRoot.get()); statement after my model load,
but this does not works if I want an empty scene that is later filled.

The application is derived from osgviewerWX on WinXP with osg 2.1.9
Thanks for your suggestions!
                                                 mario

-- 
Ing. Mario Valle
Visualization Group                              | http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)      | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82




More information about the osg-users mailing list