Moved the managing of frame stamp from osgProducer::Viewer into

osgProducer::OsgCamaraGroup.

Added setting of trackball in osgcameragroup so its starts in the
correct place for different models.
This commit is contained in:
Robert Osfield 2003-04-17 11:14:25 +00:00
parent f759f7e69e
commit fd262554ac
6 changed files with 28 additions and 25 deletions

View File

@ -146,8 +146,13 @@ int main( int argc, char **argv )
// set the scene to render // set the scene to render
cg.setSceneData(loadedModel.get()); cg.setSceneData(loadedModel.get());
const osg::BoundingSphere& bs = loadedModel->getBound();
Producer::Trackball tb; Producer::Trackball tb;
tb.setOrientation( Producer::Trackball::Z_UP ); tb.setOrientation( Producer::Trackball::Z_UP );
tb.setDistance(bs.radius()*3.0f);
tb.translate(-bs.center().x(),-bs.center().y(),-bs.center().z());
// create the windows and run the threads. // create the windows and run the threads.
cg.realize(); cg.realize();

View File

@ -152,6 +152,8 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
const osg::Matrix getViewMatrix() const; const osg::Matrix getViewMatrix() const;
virtual void sync();
/** Dispatch the cull and draw for each of the Camera's for this frame.*/ /** Dispatch the cull and draw for each of the Camera's for this frame.*/
virtual void frame(); virtual void frame();
@ -180,6 +182,10 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
osg::ref_ptr<osg::DisplaySettings> _ds; osg::ref_ptr<osg::DisplaySettings> _ds;
bool _initialized; bool _initialized;
unsigned int _frameNumber;
osg::Timer _timer;
osg::Timer_t _start_tick;
osg::ref_ptr<osg::FrameStamp> _frameStamp; osg::ref_ptr<osg::FrameStamp> _frameStamp;
void _init(); void _init();

View File

@ -83,8 +83,6 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
virtual bool realize(); virtual bool realize();
virtual void sync();
virtual void update(); virtual void update();
/** Dispatch the cull and draw for each of the Camera's for this frame.*/ /** Dispatch the cull and draw for each of the Camera's for this frame.*/
@ -143,10 +141,6 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
bool _done; bool _done;
unsigned int _frameNumber;
osg::Timer _timer;
osg::Timer_t _start_tick;
osgProducer::KeyboardMouseCallback* _kbmcb; osgProducer::KeyboardMouseCallback* _kbmcb;
EventHandlerList _eventHandlerList; EventHandlerList _eventHandlerList;

View File

@ -19,8 +19,8 @@ osgwindows glider.osg
echo osgviewer --stereo cessna.osg echo osgviewer --stereo cessna.osg
osgviewer --stereo cessna.osg osgviewer --stereo cessna.osg
echo osgviewer cessnafire.osg echo osgcameragroup cessnafire.osg
osgviewer cessnafire.osg osgcameragroup cessnafire.osg
echo osgviewer spaceship.osg echo osgviewer spaceship.osg
osgviewer spaceship.osg osgviewer spaceship.osg

View File

@ -126,6 +126,10 @@ void OsgCameraGroup::_init()
_initialized = false; _initialized = false;
// set up the time and frame counter.
_frameNumber = 0;
_start_tick = _timer.tick();
if (!_frameStamp) _frameStamp = new osg::FrameStamp; if (!_frameStamp) _frameStamp = new osg::FrameStamp;
// set up the maximum number of graphics contexts, before loading the scene graph // set up the maximum number of graphics contexts, before loading the scene graph
@ -133,6 +137,7 @@ void OsgCameraGroup::_init()
osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts( getNumberOfCameras() ); osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts( getNumberOfCameras() );
_applicationUsage = osg::ApplicationUsage::instance(); _applicationUsage = osg::ApplicationUsage::instance();
} }
void OsgCameraGroup::setSceneData( osg::Node *scene ) void OsgCameraGroup::setSceneData( osg::Node *scene )
@ -404,12 +409,21 @@ const osg::Matrix OsgCameraGroup::getViewMatrix() const
return matrix; return matrix;
} }
void OsgCameraGroup::sync()
{
CameraGroup::sync();
// set the frame stamp for the new frame.
double time_since_start = _timer.delta_s(_start_tick,_timer.tick());
_frameStamp->setFrameNumber(_frameNumber++);
_frameStamp->setReferenceTime(time_since_start);
}
void OsgCameraGroup::frame() void OsgCameraGroup::frame()
{ {
osg::Node* node = getTopMostSceneData(); osg::Node* node = getTopMostSceneData();
if (node) node->getBound(); if (node) node->getBound();
CameraGroup::frame(); CameraGroup::frame();
_frameStamp->setFrameNumber( _frameStamp->getFrameNumber() + 1 );
} }

View File

@ -125,7 +125,6 @@ private:
// //
Viewer::Viewer(): Viewer::Viewer():
_done(0), _done(0),
_frameNumber(0),
_kbmcb(0), _kbmcb(0),
_recordingAnimationPath(false) _recordingAnimationPath(false)
{ {
@ -134,7 +133,6 @@ Viewer::Viewer():
Viewer::Viewer(Producer::CameraConfig *cfg): Viewer::Viewer(Producer::CameraConfig *cfg):
OsgCameraGroup(cfg), OsgCameraGroup(cfg),
_done(false), _done(false),
_frameNumber(0),
_kbmcb(0), _kbmcb(0),
_recordingAnimationPath(false) _recordingAnimationPath(false)
{ {
@ -143,7 +141,6 @@ Viewer::Viewer(Producer::CameraConfig *cfg):
Viewer::Viewer(const std::string& configFile): Viewer::Viewer(const std::string& configFile):
OsgCameraGroup(configFile), OsgCameraGroup(configFile),
_done(false), _done(false),
_frameNumber(0),
_kbmcb(0), _kbmcb(0),
_recordingAnimationPath(false) _recordingAnimationPath(false)
{ {
@ -152,7 +149,6 @@ Viewer::Viewer(const std::string& configFile):
Viewer::Viewer(osg::ArgumentParser& arguments): Viewer::Viewer(osg::ArgumentParser& arguments):
OsgCameraGroup(arguments), OsgCameraGroup(arguments),
_done(false), _done(false),
_frameNumber(0),
_kbmcb(0), _kbmcb(0),
_recordingAnimationPath(false) _recordingAnimationPath(false)
{ {
@ -187,9 +183,6 @@ void Viewer::setUpViewer(unsigned int options)
(new Producer::KeyboardMouse(ia)) : (new Producer::KeyboardMouse(ia)) :
(new Producer::KeyboardMouse(getCamera(0)->getRenderSurface())); (new Producer::KeyboardMouse(getCamera(0)->getRenderSurface()));
// set up the time and frame counter.
_frameNumber = 0;
_start_tick = _timer.tick();
// set the keyboard mouse callback to catch the events from the windows. // set the keyboard mouse callback to catch the events from the windows.
if (!_kbmcb) if (!_kbmcb)
@ -338,15 +331,6 @@ bool Viewer::realize()
return _realized; return _realized;
} }
void Viewer::sync()
{
OsgCameraGroup::sync();
// set the frame stamp for the new frame.
double time_since_start = _timer.delta_s(_start_tick,_timer.tick());
_frameStamp->setFrameNumber(_frameNumber++);
_frameStamp->setReferenceTime(time_since_start);
}
void Viewer::update() void Viewer::update()
{ {