Hi All,

I have now checked a working osgViewer::CompositeViewer, while not
100% complete, its along way along the route.  To test it I have
modified the osgmultiplecameras example to use CompositeViewer.

So what is CompositeViewer all about?  The idea behind it is making it
easier to support multiple scene graphs, multiple views and multiple
windows in your applications.  This type of functionality was missing
from osgProducer::Viewer which only supported a single view/single
scene graph (osgProducer::Viewer and osgViewer::Viewer are equivilant
in this way).

So how do you use CompositeViewer?  The basic idea is to create the
viewer, then one by one create and set up the views that you want to
have in the viewer.  These views (osgViewer::View objects) has as
scene graph, master camera that defines its view, and support for
event handlers including a camera manipulator.  Each view also has
optional slave cameras, just as the osgViewer::Viewer(which is derved
from osgViewer::View).  The views may share scene graphs, as well as
graphics windows.

The osgmultiplecameras example now has a couple of different options
for setting up different views.  So try out:


 // option 1
 // ones one view & window on screen 0, second view & window on screen 1
 osgmultiplecamaras -1 cow.osg

 // option 2
 // ones one view across all available screens
 osgmultiplecamaras -2 cow.osg

 // option 3 (also fallback when other options are selected)
 //  with three views (see below code segment)
 osgmultiplecamaras -3 cow.osg

Now due to the fact that CompositeView can can handle any number of
views, you can compose all these view setups into a single viewer :

 osgmultiplecameras -1 -2 -3 cow.osg

Also note that camera manipulators all work independently, and
keyboard focus automatically follows the mouse, except when dragging -
so if you the mouse is dragged out of one cameras viewport it keeps
focus till you release the key (this even works across screens).

In option -1 and -3 the bottom left view has a StateSet manipulator
assigned to it so you can toggle wireframe with 'w' etc.  Also in
option -1 and -2 the bottom right view has a custom PickHandler that
allows you to point and click on the model to pick it, using
osgFX::Scribe to high light it.

This all works mutli-threaded too ;-)

A cvs update will get all this functionality... but right now Win32
users will need to wait to play... GraphicsWindowWin32 should be along
soon though so please be patient.

Cheers,
Robert.

--

The below example code is copy and pasted from osgmultiplecameras:


   // construct the viewer.
   osgViewer::CompositeViewer viewer;

       osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
       traits->x = 100;
       traits->y = 100;
       traits->width = 1000;
       traits->height = 800;
       traits->windowDecoration = true;
       traits->doubleBuffer = true;
       traits->sharedContext = 0;

       osg::ref_ptr<osg::GraphicsContext> gc =
osg::GraphicsContext::createGraphicsContext(traits.get());
       if (gc.valid())
       {
           osg::notify(osg::INFO)<<"  GraphicsWindow has been created
successfully."<<std::endl;

           // need to ensure that the window is cleared make sure
that the complete window is set the correct colour
           // rather than just the parts of the window that are under
the camera's viewports
           gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
           gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       }
       else
       {
           osg::notify(osg::NOTICE)<<"  GraphicsWindow has not been
created successfully."<<std::endl;
       }

       // view one
       {
           osgViewer::View* view = new osgViewer::View;
           viewer.addView(view);

           view->setSceneData(scene.get());
           view->getCamera()->setViewport(new osg::Viewport(0,0,
traits->width/2, traits->height/2));
           view->getCamera()->setGraphicsContext(gc.get());
           view->setCameraManipulator(new osgGA::TrackballManipulator);

           // add the state manipulator
           osg::ref_ptr<osgGA::StateSetManipulator>
statesetManipulator = new osgGA::StateSetManipulator;
           
statesetManipulator->setStateSet(view->getCamera()->getOrCreateStateSet());

           view->addEventHandler( statesetManipulator.get() );
       }

       // view two
       {
           osgViewer::View* view = new osgViewer::View;
           viewer.addView(view);

           view->setSceneData(scene.get());
           view->getCamera()->setViewport(new
osg::Viewport(traits->width/2,0, traits->width/2, traits->height/2));
           view->getCamera()->setGraphicsContext(gc.get());
           view->setCameraManipulator(new osgGA::TrackballManipulator);

           // add the handler for doing the picking
           view->addEventHandler(new PickHandler());

       }

       // view three
       {
           osgViewer::View* view = new osgViewer::View;
           viewer.addView(view);

           view->setSceneData(osgDB::readNodeFile("cessnafire.osg"));

           view->getCamera()->setProjectionMatrixAsPerspective(30.0,
double(traits->width) / double(traits->height/2), 1.0, 1000.0);
           view->getCamera()->setViewport(new osg::Viewport(0,
traits->height/2, traits->width, traits->height/2));
           view->getCamera()->setGraphicsContext(gc.get());
           view->setCameraManipulator(new osgGA::TrackballManipulator);
       }


   // run the viewer's main frame loop
   return viewer.run();
_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to