2006-11-27 22:52:07 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osgViewer/Scene>
|
2007-01-10 18:09:05 +08:00
|
|
|
#include <osgGA/EventVisitor>
|
2006-11-27 22:52:07 +08:00
|
|
|
|
|
|
|
using namespace osgViewer;
|
|
|
|
|
|
|
|
Scene::Scene():
|
|
|
|
_firstFrame(true)
|
|
|
|
{
|
|
|
|
_frameStamp = new osg::FrameStamp;
|
|
|
|
_frameStamp->setFrameNumber(0);
|
|
|
|
_frameStamp->setReferenceTime(0);
|
|
|
|
|
|
|
|
_updateVisitor = new osgUtil::UpdateVisitor;
|
2006-12-22 00:56:20 +08:00
|
|
|
_updateVisitor->setFrameStamp(_frameStamp.get());
|
2006-11-27 22:52:07 +08:00
|
|
|
|
|
|
|
setDatabasePager(new osgDB::DatabasePager);
|
|
|
|
}
|
|
|
|
|
|
|
|
Scene::~Scene()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-01-15 22:46:16 +08:00
|
|
|
void Scene::setFrameStamp(osg::FrameStamp* frameStamp)
|
|
|
|
{
|
|
|
|
_frameStamp = frameStamp;
|
|
|
|
_updateVisitor->setFrameStamp(_frameStamp.get());
|
|
|
|
}
|
|
|
|
|
2007-01-09 06:54:02 +08:00
|
|
|
void Scene::init()
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"Scene::init() not implementated yet."<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
void Scene::setSceneData(osg::Node* node)
|
|
|
|
{
|
|
|
|
_sceneData = node;
|
|
|
|
|
|
|
|
if (_databasePager.valid())
|
|
|
|
{
|
|
|
|
// register any PagedLOD that need to be tracked in the scene graph
|
|
|
|
_databasePager->registerPagedLODs(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node* Scene::getSceneData()
|
|
|
|
{
|
|
|
|
return _sceneData.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const osg::Node* Scene::getSceneData() const
|
|
|
|
{
|
|
|
|
return _sceneData.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::setDatabasePager(osgDB::DatabasePager* dp)
|
|
|
|
{
|
|
|
|
_databasePager = dp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::frameAdvance()
|
|
|
|
{
|
2006-12-23 01:46:21 +08:00
|
|
|
// double previousTime = _frameStamp->getReferenceTime();
|
|
|
|
|
2006-12-27 01:38:47 +08:00
|
|
|
_frameStamp->setReferenceTime(osg::Timer::instance()->time_s());
|
2006-11-27 22:52:07 +08:00
|
|
|
_frameStamp->setFrameNumber(_frameStamp->getFrameNumber()+1);
|
2006-12-23 01:46:21 +08:00
|
|
|
|
|
|
|
// osg::notify(osg::NOTICE)<<"Frame rate = "<<1.0/(_frameStamp->getReferenceTime()-previousTime)<<std::endl;
|
2006-11-27 22:52:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::frameUpdateTraversal()
|
|
|
|
{
|
2006-12-22 00:56:20 +08:00
|
|
|
if (!getSceneData()) return;
|
|
|
|
|
2007-01-15 17:30:48 +08:00
|
|
|
_updateVisitor->setTraversalNumber(_frameStamp->getFrameNumber());
|
|
|
|
|
2006-12-22 00:56:20 +08:00
|
|
|
getSceneData()->accept(*_updateVisitor);
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
if (_databasePager.valid())
|
|
|
|
{
|
|
|
|
// syncronize changes required by the DatabasePager thread to the scene graph
|
|
|
|
_databasePager->updateSceneGraph(_frameStamp->getReferenceTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-22 00:56:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|