From 6fd27a4b5960f76b7718ad4a96de7ba6c3c983a9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 22 Jan 2003 15:30:17 +0000 Subject: [PATCH] Clean up to the osgProducer lib and demo. --- include/osgGA/KeySwitchCameraManipulator | 5 ++ include/osgProducer/ReadCameraConfigFile | 32 -------- include/osgProducer/Viewer | 15 ++-- include/osgProducer/WriteCameraConfigFile | 32 -------- src/Demos/osgproducer/osgproducer_viewer.cpp | 40 ++++++++-- src/Demos/sgv/sgv.cpp | 14 +--- src/osgGA/KeySwitchCameraManipulator.cpp | 20 +++++ src/osgProducer/CameraGroup.cpp | 3 +- src/osgProducer/Makefile | 2 - src/osgProducer/ReadCameraConfigFile.cpp | 46 ------------ src/osgProducer/Viewer.cpp | 78 +++++++++----------- src/osgProducer/WriteCameraConfigFile.cpp | 8 -- 12 files changed, 106 insertions(+), 189 deletions(-) delete mode 100644 include/osgProducer/ReadCameraConfigFile delete mode 100644 include/osgProducer/WriteCameraConfigFile delete mode 100644 src/osgProducer/ReadCameraConfigFile.cpp delete mode 100644 src/osgProducer/WriteCameraConfigFile.cpp diff --git a/include/osgGA/KeySwitchCameraManipulator b/include/osgGA/KeySwitchCameraManipulator index e8324ae22..a7490e3b5 100644 --- a/include/osgGA/KeySwitchCameraManipulator +++ b/include/osgGA/KeySwitchCameraManipulator @@ -45,6 +45,11 @@ public: */ void addNumberedCameraManipulator(CameraManipulator *cm); + unsigned int getNumCameraManipualtors() const { return _manips.size(); } + + void selectCameraManipulator(unsigned int num); + + CameraManipulator* getCurrentCameraManipulator() { return _current.get(); } const CameraManipulator* getCurrentCameraManipulator() const { return _current.get(); } diff --git a/include/osgProducer/ReadCameraConfigFile b/include/osgProducer/ReadCameraConfigFile deleted file mode 100644 index e2751a973..000000000 --- a/include/osgProducer/ReadCameraConfigFile +++ /dev/null @@ -1,32 +0,0 @@ -/* -*-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. -*/ - -#ifndef OSGDB_READCAMERACONDIGFILE -#define OSGDB_READCAMERACONDIGFILE 1 - -#include - -#include - -#include - -namespace osgProducer { - -/** Read a Producer::CameraConfig from file. - * Return valid Producer::CameraConfig on success, - * return NULL on failure.*/ -extern OSGPRODUCER_EXPORT Producer::CameraConfig* readCameraConfigFile(const std::string& filename); - -} - -#endif diff --git a/include/osgProducer/Viewer b/include/osgProducer/Viewer index 94f66972c..030bf6ed9 100644 --- a/include/osgProducer/Viewer +++ b/include/osgProducer/Viewer @@ -38,14 +38,9 @@ class OSGPRODUCER_EXPORT Viewer : public CameraGroup, public osgGA::GUIActionAda Viewer(const std::string& configFile); - Viewer(int& argc, char** argv); - virtual ~Viewer() {} - bool readCommandLine(int& argc, char** argv); - - enum ViewerOptions { TRACKBALL_MANIPULATOR = 1, @@ -69,9 +64,6 @@ class OSGPRODUCER_EXPORT Viewer : public CameraGroup, public osgGA::GUIActionAda virtual void update(); - typedef std::list< osg::ref_ptr > EventHandlerList; - - EventHandlerList& getEventHandlerList() { return _eventHandlerList; } virtual void realize( ThreadingModel thread_model= SingleThreaded ); @@ -79,6 +71,13 @@ class OSGPRODUCER_EXPORT Viewer : public CameraGroup, public osgGA::GUIActionAda virtual void requestContinuousUpdate(bool) {} virtual void requestWarpPointer(int x,int y); + typedef std::list< osg::ref_ptr > EventHandlerList; + EventHandlerList& getEventHandlerList() { return _eventHandlerList; } + + unsigned int addCameraManipulator(osgGA::CameraManipulator* cm); + void selectCameraManipulator(unsigned int no); + + protected : diff --git a/include/osgProducer/WriteCameraConfigFile b/include/osgProducer/WriteCameraConfigFile deleted file mode 100644 index 36da8af5d..000000000 --- a/include/osgProducer/WriteCameraConfigFile +++ /dev/null @@ -1,32 +0,0 @@ -/* -*-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. -*/ - -#ifndef OSGDB_WRITECAMERACONDIGFILE -#define OSGDB_WRITECAMERACONDIGFILE 1 - -#include - -#include - -#include - -namespace osgProducer { - -/** Write a Producer::CameraConfig to file. - * Return true on success, - * return false on failure.*/ -extern OSGPRODUCER_EXPORT bool writeCameraConfigFile(const Producer::CameraConfig& cameraconfig, const std::string& filename); - -} - -#endif diff --git a/src/Demos/osgproducer/osgproducer_viewer.cpp b/src/Demos/osgproducer/osgproducer_viewer.cpp index ffd605dd8..82df11d95 100644 --- a/src/Demos/osgproducer/osgproducer_viewer.cpp +++ b/src/Demos/osgproducer/osgproducer_viewer.cpp @@ -3,23 +3,42 @@ //as published by the Free Software Foundation. #include + #include +#include + +#include + #include int main( int argc, char **argv ) { // create the camera group. - osgProducer::Viewer viewer(argc,argv); + osgProducer::Viewer viewer; - // set up the database files to read. - std::vector filenameList; - if (argc>1) filenameList.push_back(argv[1]); - else filenameList.push_back("cow.osg"); + // create the commandline args. + std::string pathfile; + std::vector commandLine; + for(int i=1;i= argc ) { + std::cout << "path argument required for -p option."<readCommandLine(commandLine); + osgDB::readCommandLine(commandLine); // read the scene. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(filenameList); + osg::ref_ptr loadedModel = osgDB::readNodeFiles(commandLine); if (!loadedModel) return 1; // optimize it, remove rendundent nodes and state etc. @@ -30,6 +49,15 @@ int main( int argc, char **argv ) // set up the value with sensible defaults. viewer.setUpViewer(); + if( !pathfile.empty() ) { + osg::ref_ptr apm = new osgGA::AnimationPathManipulator(pathfile); + if( apm.valid() && apm->valid() ) + { + unsigned int num = viewer.addCameraManipulator(apm.get()); + viewer.selectCameraManipulator(num); + } + } + // set the scene to render viewer.setSceneData(loadedModel.get()); diff --git a/src/Demos/sgv/sgv.cpp b/src/Demos/sgv/sgv.cpp index 3a10a38ca..e234f05ba 100644 --- a/src/Demos/sgv/sgv.cpp +++ b/src/Demos/sgv/sgv.cpp @@ -150,18 +150,12 @@ int main( int argc, char **argv ) viewer.registerCameraManipulator(new osgGA::DriveManipulator); if( !pathfile.empty() ) { - osgGA::AnimationPathManipulator *apm = new osgGA::AnimationPathManipulator(pathfile); - if( apm->valid() ) + osg::ref_ptr apm = new osgGA::AnimationPathManipulator(pathfile); + if( apm.valid() && apm->valid() ) { - //viewer.registerCameraManipulator(apm); - // selecting the animation path manipulator up front seems to disable view frustum - // in a heavy duty way that I'm do understand yet, so I'm commenting out for the - // time being. Simply pressing '4' will get you the animation path working correctly. - unsigned int no = viewer.registerCameraManipulator(apm); - viewer.selectCameraManipulator(no); + unsigned int num = viewer.registerCameraManipulator(apm.get()); + viewer.selectCameraManipulator(num); } - else - delete apm; } // osgUtil::RenderBin* depth_renderbin = osgUtil::RenderBin::getRenderBinPrototype("DepthSortedBin"); diff --git a/src/osgGA/KeySwitchCameraManipulator.cpp b/src/osgGA/KeySwitchCameraManipulator.cpp index 522d6eef4..fd3d736ff 100644 --- a/src/osgGA/KeySwitchCameraManipulator.cpp +++ b/src/osgGA/KeySwitchCameraManipulator.cpp @@ -21,6 +21,26 @@ void KeySwitchCameraManipulator::addNumberedCameraManipulator(CameraManipulator addCameraManipulator('1'+_manips.size(),"camera",cm); } +void KeySwitchCameraManipulator::selectCameraManipulator(unsigned int num) +{ + unsigned int manipNo = 0; + KeyManipMap::iterator itr; + for(itr=_manips.begin(); + manipNo!=num && itr!=_manips.end(); + ++itr,++manipNo) + { + } + + if (itr!=_manips.end()) + { + if (_current.valid()) + { + itr->second.second->setNode(_current->getNode()); + itr->second.second->setCamera(_current->getCamera()); + } + _current = itr->second.second; + } +} bool KeySwitchCameraManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) { diff --git a/src/osgProducer/CameraGroup.cpp b/src/osgProducer/CameraGroup.cpp index 98d8949fb..8206fe54c 100644 --- a/src/osgProducer/CameraGroup.cpp +++ b/src/osgProducer/CameraGroup.cpp @@ -3,7 +3,6 @@ //as published by the Free Software Foundation. #include -#include using namespace osgProducer; @@ -17,7 +16,7 @@ CameraGroup::CameraGroup(Producer::CameraConfig *cfg): Producer::CameraGroup(cfg _init(); } -CameraGroup::CameraGroup(const std::string& configFile) : Producer::CameraGroup(readCameraConfigFile(configFile)) +CameraGroup::CameraGroup(const std::string& configFile) : Producer::CameraGroup(configFile) { _init(); } diff --git a/src/osgProducer/Makefile b/src/osgProducer/Makefile index 883f5cca3..62422aeca 100644 --- a/src/osgProducer/Makefile +++ b/src/osgProducer/Makefile @@ -6,8 +6,6 @@ CXXFILES =\ EventAdapter.cpp\ KeyboardMouseCallback.cpp\ SceneHandler.cpp\ - ReadCameraConfigFile.cpp\ - WriteCameraConfigFile.cpp\ Viewer.cpp\ LIBS += -lProducer $(GL_LIBS) -losgGA -losgUtil -losgDB -losg $(OTHER_LIBS) diff --git a/src/osgProducer/ReadCameraConfigFile.cpp b/src/osgProducer/ReadCameraConfigFile.cpp deleted file mode 100644 index 5274a4201..000000000 --- a/src/osgProducer/ReadCameraConfigFile.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include - - -using namespace osgProducer; - - -Producer::CameraConfig* buildConfig() -{ - Producer::RenderSurface *rs1 = new Producer::RenderSurface; - rs1->setScreenNum(0); -// rs1->useBorder(false); -// rs1->setWindowRect(0,0,640,480); - rs1->setWindowRect(10,10,620,480); - - Producer::Camera *camera1 = new Producer::Camera; - camera1->setRenderSurface(rs1); - camera1->setOffset( 1.0, 0.0 ); - - - Producer::RenderSurface *rs2 = new Producer::RenderSurface; - rs2->setScreenNum(0); -// rs2->useBorder(false); -// rs2->setWindowRect(640,0,640,480); - rs2->setWindowRect(650,10,620,480); - - Producer::Camera *camera2 = new Producer::Camera; - camera2->setRenderSurface(rs2); - camera2->setOffset( -1.0, 0.0 ); - - Producer::CameraConfig *cfg = new Producer::CameraConfig; - cfg->addCamera("Camera 1",camera1); - cfg->addCamera("Camera 2", camera2); - - Producer::InputArea *ia = new Producer::InputArea; - ia->addInputRectangle( rs1, Producer::InputRectangle(-1.0,0.0,-1.0,1.0)); - ia->addInputRectangle( rs2, Producer::InputRectangle(0.0,1.0,-1.0,1.0)); - - cfg->setInputArea(ia); - - return cfg; -} - -Producer::CameraConfig* osgProducer::readCameraConfigFile(const std::string& filename) -{ - return buildConfig(); -} diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 7ddbc340b..dd7da4979 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -20,39 +20,18 @@ Viewer::Viewer(): Viewer::Viewer(Producer::CameraConfig *cfg): CameraGroup(cfg), - _done(0), + _done(false), _frameNumber(0), _kbmcb(0) { - _done = false; } Viewer::Viewer(const std::string& configFile): CameraGroup(configFile), - _done(0), + _done(false), _frameNumber(0), _kbmcb(0) { - _done = false; -} - -Viewer::Viewer(int& argc, char** argv): - _done(0), - _frameNumber(0), - _kbmcb(0) -{ - _done = false; - - readCommandLine(argc,argv); - // set up the maximum number of graphics contexts, before loading the scene graph - // to ensure that texture objects and display buffers are configured to the correct size. - osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts( getNumberOfCameras() ); -} - - -bool Viewer::readCommandLine(int&, char**) -{ - return false; } void Viewer::setUpViewer(Viewer::ViewerOptions options) @@ -113,24 +92,9 @@ void Viewer::setUpViewer(Viewer::ViewerOptions options) // create a camera to use with the manipulators. _old_style_osg_camera = new osg::Camera; - if (options&(TRACKBALL_MANIPULATOR|FLIGHT_MANIPULATOR|DRIVE_MANIPULATOR)) - { - - _keyswitchManipulator = new osgGA::KeySwitchCameraManipulator; - if (options&TRACKBALL_MANIPULATOR) _keyswitchManipulator->addNumberedCameraManipulator(new osgGA::TrackballManipulator); - if (options&FLIGHT_MANIPULATOR) _keyswitchManipulator->addNumberedCameraManipulator(new osgGA::FlightManipulator); - if (options&DRIVE_MANIPULATOR) _keyswitchManipulator->addNumberedCameraManipulator(new osgGA::DriveManipulator); - - _keyswitchManipulator->setCamera(_old_style_osg_camera.get()); - _keyswitchManipulator->setNode(getSceneDecorator()); - - _eventHandlerList.push_back(_keyswitchManipulator.get()); - - osg::ref_ptr init_event = new osgProducer::EventAdapter; - init_event->adaptFrame(0.0); - _keyswitchManipulator->getCurrentCameraManipulator()->home(*init_event,*this); - - } + if (options&TRACKBALL_MANIPULATOR) addCameraManipulator(new osgGA::TrackballManipulator); + if (options&FLIGHT_MANIPULATOR) addCameraManipulator(new osgGA::FlightManipulator); + if (options&DRIVE_MANIPULATOR) addCameraManipulator(new osgGA::DriveManipulator); if (options&STATE_MANIPULATOR) { @@ -141,13 +105,34 @@ void Viewer::setUpViewer(Viewer::ViewerOptions options) } +unsigned int Viewer::addCameraManipulator(osgGA::CameraManipulator* cm) +{ + if (!cm) return 0xfffff; + + // create a key switch manipulator if one doesn't already exist. + if (!_keyswitchManipulator) + { + _keyswitchManipulator = new osgGA::KeySwitchCameraManipulator; + _eventHandlerList.push_back(_keyswitchManipulator.get()); + } + + unsigned int num = _keyswitchManipulator->getNumCameraManipualtors(); + _keyswitchManipulator->addNumberedCameraManipulator(cm); + + return num; +} + + void Viewer::realize( ThreadingModel thread_model) { - if (_keyswitchManipulator.valid()) + if (_keyswitchManipulator.valid() && _keyswitchManipulator->getCurrentCameraManipulator()) { osg::ref_ptr init_event = new osgProducer::EventAdapter; init_event->adaptFrame(0.0); - _keyswitchManipulator->getCurrentCameraManipulator()->home(*init_event,*this); + + _keyswitchManipulator->setCamera(_old_style_osg_camera.get()); + _keyswitchManipulator->setNode(getSceneDecorator()); + _keyswitchManipulator->home(*init_event,*this); } CameraGroup::realize( thread_model ); @@ -198,7 +183,14 @@ void Viewer::update() if (_old_style_osg_camera.valid()) setView(_old_style_osg_camera->getModelViewMatrix().ptr()); } +void Viewer::selectCameraManipulator(unsigned int no) +{ + if (_keyswitchManipulator.valid()) _keyswitchManipulator->selectCameraManipulator(no); +} + void Viewer::requestWarpPointer(int x,int y) { osg::notify(osg::WARN) << "Warning: requestWarpPointer("< - -using namespace osgProducer; - -bool osgProducer::writeCameraConfigFile(const Producer::CameraConfig& cameraconfig, const std::string& filename) -{ - return false; -}