From 372ca1d227ff32c4a90b6c3fa1c1e6ef366c71b9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 23 Feb 2003 17:01:05 +0000 Subject: [PATCH] Ported osgstereoimage to use osgProducer, added it to the examples directory. Added a osgProducer::CameraGroup::getSceneHanderList() methods. --- Make/makedirdefs | 3 +- examples/osgstereoimage/Makefile.inst | 15 +++ examples/osgstereoimage/osgstereoimage.cpp | 146 +++++++++++++++++++++ include/osgProducer/CameraGroup | 9 +- 4 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 examples/osgstereoimage/Makefile.inst create mode 100644 examples/osgstereoimage/osgstereoimage.cpp diff --git a/Make/makedirdefs b/Make/makedirdefs index 0c4a39de2..337245ecf 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -77,9 +77,10 @@ PLUGIN_DIRS += tiff EXAMPLE_DIRS = \ osgcameragroup\ + osgviewer\ osgconv\ osgtext\ - osgviewer\ + osgstereoimage\ ################################################################ diff --git a/examples/osgstereoimage/Makefile.inst b/examples/osgstereoimage/Makefile.inst new file mode 100644 index 000000000..13faa93c2 --- /dev/null +++ b/examples/osgstereoimage/Makefile.inst @@ -0,0 +1,15 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgstereoimage.cpp\ + +LIBS += -losgProducer -lProducer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osgstereoimage + +CXXFLAGS += $(PRODUCER_INCLUDE_DIR) +LDFLAGS += $(PRODUCER_LIB_DIR) + + +include $(TOPDIR)/Make/makerules diff --git a/examples/osgstereoimage/osgstereoimage.cpp b/examples/osgstereoimage/osgstereoimage.cpp new file mode 100644 index 000000000..a195cb01b --- /dev/null +++ b/examples/osgstereoimage/osgstereoimage.cpp @@ -0,0 +1,146 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include +#include +#include + + + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + + +int main( int argc, char **argv ) +{ + + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); + + // set up the usage document, in case we need to print out how to use this program. + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] image_file_left_eye image_file_right_eye"); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + + // construct the viewer. + osgProducer::Viewer viewer(arguments); + + // set up the value with sensible default event handlers. + viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); + + // get details on keyboard and mouse bindings used by the viewer. + viewer.getUsage(*arguments.getApplicationUsage()); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } + + // extract the filenames from the arguments list. + std::string fileLeft,fileRight; + for(int pos=1;poss()+imageRight->s())*0.5f; + float average_t = (imageLeft->t()+imageRight->t())*0.5f; + + osg::Geode* geodeLeft = osg::createGeodeForImage(imageLeft,average_s,average_t); + geodeLeft->setNodeMask(0x01); + + osg::Geode* geodeRight = osg::createGeodeForImage(imageRight,average_s,average_t); + geodeRight->setNodeMask(0x02); + + osg::ref_ptr rootNode = new osg::Group; + rootNode->addChild(geodeLeft); + rootNode->addChild(geodeRight); + + // set the scene to render + viewer.setSceneData(rootNode.get()); + + // create the windows and run the threads. + viewer.realize(Producer::CameraGroup::ThreadPerCamera); + + // set all the sceneview's up so that their left and right add cull masks are set up. + for(osgProducer::CameraGroup::SceneHandlerList::iterator itr=viewer.getSceneHandlerList().begin(); + itr!=viewer.getSceneHandlerList().end(); + ++itr) + { + osgUtil::SceneView* sceneview = *itr; + sceneview->setCullMask(0xffffffff); + sceneview->setCullMaskLeft(0x00000001); + sceneview->setCullMaskRight(0x00000002); + } + + + while( !viewer.done() ) + { + // wait for all cull and draw threads to complete. + viewer.sync(); + + // update the scene by traversing it with the the update visitor which will + // call all node update callbacks and animations. + viewer.update(); + + // fire off the cull and draw traversals of the scene. + viewer.frame(); + + } + + return 0; +} + diff --git a/include/osgProducer/CameraGroup b/include/osgProducer/CameraGroup index 2b515c80e..53056ca62 100644 --- a/include/osgProducer/CameraGroup +++ b/include/osgProducer/CameraGroup @@ -31,8 +31,6 @@ class OSGPRODUCER_EXPORT CameraGroup : public Producer::CameraGroup { public : - typedef std::vector SceneHandlerList; - CameraGroup(); CameraGroup(Producer::CameraConfig *cfg); @@ -44,6 +42,13 @@ class OSGPRODUCER_EXPORT CameraGroup : public Producer::CameraGroup virtual ~CameraGroup() {} + typedef std::vector SceneHandlerList; + + + SceneHandlerList& getSceneHandlerList() { return _shvec;} + + const SceneHandlerList& getSceneHandlerList() const { return _shvec;} + void setSceneData( osg::Node *scene );