Updates to osgProducer, moving the implementation of CameraGroup and

SceneHandler into the source directory.
This commit is contained in:
Robert Osfield
2003-01-20 08:58:32 +00:00
parent 08456ecf70
commit c325de6865
4 changed files with 220 additions and 2 deletions

View File

@@ -163,6 +163,10 @@ int main( int argc, char **argv )
init_event->adaptFrame(0.0);
keyswitchManipulator->getCurrentCameraManipulator()->home(*init_event,actionAdapter);
double previous_time_since_start = 0.0f;
int number_frames_since_last_print = 0;
int number_of_frame_samples = 10;
bool printOutFrameStats=true;
while( !done )
{
// syncronize to screen refresh.
@@ -173,6 +177,16 @@ int main( int argc, char **argv )
frameStamp->setFrameNumber(frameNumber);
frameStamp->setReferenceTime(time_since_start);
if (printOutFrameStats)
{
if (number_frames_since_last_print==number_of_frame_samples)
{
cout << "frame rate = "<< (double)number_of_frame_samples/(time_since_start-previous_time_since_start)<<endl;
previous_time_since_start = time_since_start;
number_frames_since_last_print = 0;
} else ++number_frames_since_last_print;
}
// get the event since the last frame.
osgProducer::KeyboardMouseCallback::EventQueue queue;
kbmcb.getEventQueue(queue);

View File

@@ -0,0 +1,159 @@
//Open Producer - Copyright (C) 2002 Don Burns
//Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
//as published by the Free Software Foundation.
#include <osgProducer/CameraGroup>
#include <osgProducer/ReadCameraConfigFile>
using namespace osgProducer;
CameraGroup::CameraGroup() : Producer::CameraGroup()
{
_init();
}
CameraGroup::CameraGroup(Producer::CameraConfig *cfg): Producer::CameraGroup(cfg)
{
_init();
}
CameraGroup::CameraGroup(const std::string& configFile) : Producer::CameraGroup(readCameraConfigFile(configFile))
{
_init();
}
void CameraGroup::_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 CameraGroup::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.get() );
}
}
}
void CameraGroup::setFrameStamp( osg::FrameStamp* fs )
{
_frameStamp = fs;
for(SceneHandlerList::iterator p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setFrameStamp( fs );
}
}
void CameraGroup::setGlobalStateSet( osg::StateSet *sset )
{
_global_stateset = sset;
for(SceneHandlerList::iterator p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setGlobalStateSet( _global_stateset.get() );
}
}
void CameraGroup::setBackgroundColor( const osg::Vec4& backgroundColor )
{
_background_color = backgroundColor;
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setBackgroundColor( _background_color );
}
}
}
void CameraGroup::setLODScale( float bias )
{
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setLODScale( bias );
}
}
}
void CameraGroup::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 CameraGroup::advance()
{
if( !_initialized ) return;
CameraGroup::advance();
}
void CameraGroup::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.get() );
if( _scene_data != NULL )
sh->setSceneData( _scene_data.get() );
sh->setBackgroundColor( _background_color);
sh->getState()->setContextID(i);
sh->setFrameStamp( _frameStamp.get() );
_shvec.push_back( sh );
cam->setSceneHandler( sh );
}
/// 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.get() );
}
Producer::CameraGroup::realize( thread_model );
_initialized = true;
}
void CameraGroup::frame()
{
Producer::CameraGroup::frame();
_frameStamp->setFrameNumber( _frameStamp->getFrameNumber() + 1 );
}

View File

@@ -3,7 +3,8 @@
using namespace osgProducer;
Producer::CameraConfig* osgProducer::readCameraConfigFile(const std::string& filename)
Producer::CameraConfig* buildConfig()
{
Producer::RenderSurface *rs1 = new Producer::RenderSurface;
rs1->setScreenNum(0);
@@ -39,4 +40,7 @@ Producer::CameraConfig* osgProducer::readCameraConfigFile(const std::string& fil
return cfg;
}
Producer::CameraConfig* osgProducer::readCameraConfigFile(const std::string& filename)
{
return buildConfig();
}

View File

@@ -0,0 +1,41 @@
//Open Producer - Copyright (C) 2002 Don Burns
//Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
//as published by the Free Software Foundation.
#include <osgProducer/SceneHandler>
using namespace osgUtil;
using namespace osgProducer;
SceneHandler::SceneHandler( osg::DisplaySettings *ds = NULL) :
osgUtil::SceneView(ds)
{
mm = new osg::RefMatrix;
pm = new osg::RefMatrix;
}
void SceneHandler::cull(Producer::Camera &cam)
{
pm->set(cam.getProjectionMatrix());
mm->set(cam.getPositionAndAttitudeMatrix());
setProjectionMatrix( pm.get() );
setModelViewMatrix( mm.get() );
int x, y;
unsigned int w, h;
cam.getProjectionRect( x, y, w, h );
setViewport( x, y, w, h );
SceneView::cull();
}
void SceneHandler::draw(Producer::Camera &)
{
SceneView::draw();
}
void SceneHandler::setContextID( int id )
{
getState()->setContextID( id );
}