Improvements to the osgProducer lib to better handle Producer's normalized

coord system.

Addition of ReadCameraConfigFile and WriteCameraConfigFile as a tempory
measure for implementing local a C++ read/write of the Producer::CameraConfig, this
will be removed once these implementations or similar have been moved to Producer.
This commit is contained in:
Robert Osfield 2003-01-18 22:07:59 +00:00
parent 13aa469628
commit 762db56a40
9 changed files with 153 additions and 230 deletions

View File

@ -4,9 +4,9 @@
#ifndef OSG_CAMERA_GROUP_H
#define OSG_CAMERA_GROUP_H
#include <vector>
#include <Producer/CameraGroup>
#include <osg/Node>
#include <osg/StateSet>
#include <osg/FrameStamp>
@ -16,37 +16,27 @@
namespace osgProducer {
class CameraGroup : public Producer::CameraGroup
class OSGPRODUCER_EXPORT CameraGroup : public Producer::CameraGroup
{
public :
typedef std::vector <osgProducer::SceneHandler *> SceneHandlerList;
CameraGroup() : Producer::CameraGroup()
{ _init(); }
CameraGroup();
CameraGroup(Producer::CameraConfig *cfg) : Producer::CameraGroup(cfg)
{ _init(); }
CameraGroup(Producer::CameraConfig *cfg);
CameraGroup(const std::string& configFile) : Producer::CameraGroup(configFile)
{ _init(); }
CameraGroup(const std::string& configFile);
virtual ~CameraGroup() {}
void setSceneData( osg::Node *scene )
{
_scene_data = scene;
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setSceneData( _scene_data );
}
}
}
osg::Node *getSceneData() { return _scene_data; }
void setSceneData( osg::Node *scene );
osg::Node *getSceneData() { return _scene_data.get(); }
const osg::Node *getSceneData() const { return _scene_data.get(); }
void setDisplaySettings( osg::DisplaySettings *ds ) { _ds = ds; }
@ -57,150 +47,53 @@ class CameraGroup : public Producer::CameraGroup
void setFrameStamp( osg::FrameStamp* fs )
{
_frameStamp = fs;
for(SceneHandlerList::iterator p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setFrameStamp( fs );
}
}
void setFrameStamp( osg::FrameStamp* fs );
osg::FrameStamp *getFrameStamp() { return _frameStamp.get(); }
const osg::FrameStamp *getFrameStamp() const { return _frameStamp.get(); }
void setGlobalStateSet( osg::StateSet *sset )
{
_global_stateset = sset;
void setGlobalStateSet( osg::StateSet *sset );
for(SceneHandlerList::iterator p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setGlobalStateSet( _global_stateset );
}
}
osg::StateSet *getGlobalStateSet() { return _global_stateset.get(); }
void setBackgroundColor( const osg::Vec4& backgroundColor )
{
_background_color = backgroundColor;
const osg::StateSet *getGlobalStateSet() const { return _global_stateset.get(); }
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setBackgroundColor( _background_color );
}
}
}
void setLODScale( float bias )
{
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setLODScale( bias );
}
}
}
void setFusionDistance( osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f)
{
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setFusionDistance( mode, value );
}
}
}
void setBackgroundColor( const osg::Vec4& backgroundColor );
osg::Vec4& getBackgroundColor() { return _background_color; }
const osg::Vec4& getBackgroundColor() const { return _background_color; }
osg::StateSet *getGlobalStateSet() { return _global_stateset; }
const osg::StateSet *getGlobalStateSet() const { return _global_stateset; }
void setLODScale( float bias );
void advance()
{
if( !_initialized ) return;
CameraGroup::advance();
}
void realize( ThreadingModel thread_model= SingleThreaded )
{
if( _initialized ) return;
if (!_ds) _ds = osg::DisplaySettings::instance();
_ds->setMaxNumberOfGraphicsContexts( _cfg->getNumberOfCameras() );
for( unsigned int i = 0; i < _cfg->getNumberOfCameras(); i++ )
{
Producer::Camera *cam = _cfg->getCamera(i);
osgProducer::SceneHandler *sh = new osgProducer::SceneHandler(_ds.get());
sh->setDefaults();
if( _global_stateset != NULL )
sh->setGlobalStateSet( _global_stateset );
if( _scene_data != NULL )
sh->setSceneData( _scene_data );
sh->setBackgroundColor( _background_color);
sh->getState()->setContextID(i);
sh->setFrameStamp( _frameStamp.get() );
_shvec.push_back( sh );
cam->setSceneHandler( sh );
}
void setFusionDistance( osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f);
/// Make all statesets the same as the first.
if( _global_stateset == NULL && _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
p = _shvec.begin();
_global_stateset = (*p)->getGlobalStateSet();
p++;
for( ; p != _shvec.end(); p++ )
(*p)->setGlobalStateSet( _global_stateset );
}
Producer::CameraGroup::realize( thread_model );
_initialized = true;
}
virtual void frame( )
{
Producer::CameraGroup::frame();
_frameStamp->setFrameNumber( _frameStamp->getFrameNumber() + 1 );
}
void advance();
private :
void realize( ThreadingModel thread_model= SingleThreaded );
osg::Node * _scene_data;
osg::StateSet * _global_stateset;
virtual void frame();
protected :
osg::ref_ptr<osg::Node> _scene_data;
osg::ref_ptr<osg::StateSet> _global_stateset;
osg::Vec4 _background_color;
SceneHandlerList _shvec;
osg::ref_ptr<osg::DisplaySettings> _ds;
bool _initialized;
osg::ref_ptr<osg::FrameStamp> _frameStamp;
void _init()
{
_scene_data = NULL;
_global_stateset = NULL;
_background_color.set( 0.2f, 0.2f, 0.4f, 1.0f );
_initialized = false;
if (!_frameStamp) _frameStamp = new osg::FrameStamp;
}
void _init();;
};
}

View File

@ -0,0 +1,23 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#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

@ -10,54 +10,25 @@
#include <osgUtil/SceneView>
#include <osg/Matrix>
#include <iostream>
namespace osgProducer {
class SceneHandler : public Producer::Camera::SceneHandler, public osgUtil::SceneView
class OSGPRODUCER_EXPORT SceneHandler : public Producer::Camera::SceneHandler, public osgUtil::SceneView
{
public :
SceneHandler( osg::DisplaySettings *ds = NULL) : osgUtil::SceneView(ds)
{
mm = new osg::RefMatrix;
pm = new osg::RefMatrix;
}
SceneHandler( osg::DisplaySettings *ds = NULL);
void cull(Producer::Camera &cam)
{
pm->set(cam.getProjectionMatrix());
mm->set(cam.getPositionAndAttitudeMatrix());
setProjectionMatrix( pm.get() );
setModelViewMatrix( mm.get() );
void cull(Producer::Camera &cam);
int x, y;
unsigned int w, h;
cam.getProjectionRect( x, y, w, h );
void draw(Producer::Camera &);
setViewport( x, y, w, h );
#ifdef _windows_is_non_standard
SceneView::cull();
#else
osgUtil::SceneView::cull();
#endif
}
void draw(Producer::Camera &)
{
#ifdef _windows_is_non_standard
SceneView::draw();
#else
osgUtil::SceneView::draw();
#endif
}
void setContextID( int id )
{
getState()->setContextID( id );
}
void setContextID( int id );
private:
protected:
virtual ~SceneHandler() {}
osg::ref_ptr<osg::RefMatrix> mm;
osg::ref_ptr<osg::RefMatrix> pm;
};

View File

@ -0,0 +1,23 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#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

@ -32,41 +32,6 @@
#include <list>
static Producer::CameraConfig *BuildConfig(void)
{
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(0.0,0.5,0.0,1.0));
ia->addInputRectangle( rs2, Producer::InputRectangle(0.5,1.0,0.0,1.0));
cfg->setInputArea(ia);
return cfg;
}
int main( int argc, char **argv )
{
@ -76,7 +41,8 @@ int main( int argc, char **argv )
threadingModel = Producer::CameraGroup::ThreadPerCamera;
// configuration file.
std::string configFile; // configFile = "twoWindows.cfg"
std::string configFile;
//configFile = "twoWindows.cfg";
// set up the database files to read.
std::vector<std::string> filenameList;
@ -86,22 +52,10 @@ int main( int argc, char **argv )
// create the camera group.
osgProducer::CameraGroup *cg = 0;
#define USE_BUILD_CONFIG
#ifdef USE_BUILD_CONFIG
Producer::CameraConfig *cfg = BuildConfig();
cg = new osgProducer::CameraGroup(cfg);
#else
cg = configFile.empty() ?
osgProducer::CameraGroup *cg = configFile.empty() ?
(new osgProducer::CameraGroup()):
(new osgProducer::CameraGroup(configFile));
#endif
// 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( cg->getNumberOfCameras() );

View File

@ -14,6 +14,11 @@ int EventAdapter::_s_Ymax = 1024;
int EventAdapter::_s_mx = 0;
int EventAdapter::_s_my = 0;
static float s_xOffset=1.0f;
static float s_xScale=0.5f;
static float s_yOffset=1.0f;
static float s_yScale=0.5f;
EventAdapter::EventAdapter()
{
_eventType = NONE; // adaptor does not encapsulate any events.
@ -93,8 +98,8 @@ void EventAdapter::adaptButtonPress(double time,float x, float y, unsigned int b
break;
}
_s_mx = (int)(x*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (int)(y*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
_s_mx = (int)((x+s_xOffset)*s_xScale*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (int)((y+s_yOffset)*s_yScale*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
copyStaticVariables();
}
@ -125,8 +130,8 @@ void EventAdapter::adaptButtonRelease(double time,float x, float y, unsigned int
break;
}
_s_mx = (int)(x*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (int)(y*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
_s_mx = (int)((x+s_xOffset)*s_xScale*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (int)((y+s_yOffset)*s_yScale*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
copyStaticVariables();
}
@ -140,8 +145,8 @@ void EventAdapter::adaptMouseMotion(double time, float x, float y)
MOVE;
_time = time;
_s_mx = (int)(x*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (int)(y*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
_s_mx = (int)((x+s_xOffset)*s_xScale*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
_s_my = (int)((y+s_yOffset)*s_yScale*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
copyStaticVariables();
}

View File

@ -2,8 +2,12 @@ TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
CameraGroup.cpp\
EventAdapter.cpp\
KeyboardMouseCallback.cpp\
SceneHandler.cpp\
ReadCameraConfigFile.cpp\
WriteCameraConfigFile.cpp\
LIBS += -lProducer $(GL_LIBS) -losgGA -losgUtil -losgDB -losg $(OTHER_LIBS)
DEF += -DOSGPRODUCER_LIBRARY

View File

@ -0,0 +1,42 @@
#include <osgProducer/ReadCameraConfigFile>
using namespace osgProducer;
Producer::CameraConfig* osgProducer::readCameraConfigFile(const std::string& filename)
{
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;
}

View File

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