Clean up to the osgProducer lib and demo.

This commit is contained in:
Robert Osfield 2003-01-22 15:30:17 +00:00
parent 4b671e5023
commit 6fd27a4b59
12 changed files with 106 additions and 189 deletions

View File

@ -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(); }

View File

@ -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 <Producer/CameraConfig>
#include <osgProducer/Export>
#include <string>
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

View File

@ -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<osgGA::GUIEventHandler> > 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<osgGA::GUIEventHandler> > EventHandlerList;
EventHandlerList& getEventHandlerList() { return _eventHandlerList; }
unsigned int addCameraManipulator(osgGA::CameraManipulator* cm);
void selectCameraManipulator(unsigned int no);
protected :

View File

@ -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 <Producer/CameraConfig>
#include <osgProducer/Export>
#include <string>
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

View File

@ -3,23 +3,42 @@
//as published by the Free Software Foundation.
#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osgDB/FileUtils>
#include <osgGA/AnimationPathManipulator>
#include <osgProducer/Viewer>
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<std::string> filenameList;
if (argc>1) filenameList.push_back(argv[1]);
else filenameList.push_back("cow.osg");
// create the commandline args.
std::string pathfile;
std::vector<std::string> commandLine;
for(int i=1;i<argc;++i) {
if( std::string(argv[i]) == "-p" ) {
if( (i+1) >= argc ) {
std::cout << "path argument required for -p option."<<std::endl;
return 1;
}
else
pathfile = std::string(argv[++i]);
}
else
commandLine.push_back(argv[i]);
}
osg::DisplaySettings::instance()->readCommandLine(commandLine);
osgDB::readCommandLine(commandLine);
// read the scene.
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(filenameList);
osg::ref_ptr<osg::Node> 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<osgGA::AnimationPathManipulator> 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());

View File

@ -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<osgGA::AnimationPathManipulator> 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");

View File

@ -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)
{

View File

@ -3,7 +3,6 @@
//as published by the Free Software Foundation.
#include <osgProducer/CameraGroup>
#include <osgProducer/ReadCameraConfigFile>
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();
}

View File

@ -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)

View File

@ -1,46 +0,0 @@
#include <osgProducer/ReadCameraConfigFile>
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();
}

View File

@ -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<osgProducer::EventAdapter> 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<osgProducer::EventAdapter> 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("<<x<<","<<y<<") not implemented yet."<<std::endl;
}

View File

@ -1,8 +0,0 @@
#include <osgProducer/WriteCameraConfigFile>
using namespace osgProducer;
bool osgProducer::writeCameraConfigFile(const Producer::CameraConfig& cameraconfig, const std::string& filename)
{
return false;
}