Added support for an View::Slave::UpdateSlaveCallback
This commit is contained in:
parent
454e2df32b
commit
1525f3cd4e
@ -92,6 +92,7 @@ class OSG_EXPORT View : public virtual osg::Object
|
||||
/** Get the frame stamp of the view. */
|
||||
const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
|
||||
|
||||
|
||||
/** Slave allows one to up a camera that follows the master with a local offset to the project and view matrices.*/
|
||||
struct Slave
|
||||
{
|
||||
@ -108,7 +109,8 @@ class OSG_EXPORT View : public virtual osg::Object
|
||||
_camera(rhs._camera),
|
||||
_projectionOffset(rhs._projectionOffset),
|
||||
_viewOffset(rhs._viewOffset),
|
||||
_useMastersSceneData(rhs._useMastersSceneData) {}
|
||||
_useMastersSceneData(rhs._useMastersSceneData),
|
||||
_updateSlaveCallback(rhs._updateSlaveCallback) {}
|
||||
|
||||
Slave& operator = (const Slave& rhs)
|
||||
{
|
||||
@ -116,13 +118,28 @@ class OSG_EXPORT View : public virtual osg::Object
|
||||
_projectionOffset = rhs._projectionOffset;
|
||||
_viewOffset = rhs._viewOffset;
|
||||
_useMastersSceneData = rhs._useMastersSceneData;
|
||||
_updateSlaveCallback = rhs._updateSlaveCallback;
|
||||
return *this;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
osg::Matrixd _projectionOffset;
|
||||
osg::Matrixd _viewOffset;
|
||||
bool _useMastersSceneData;
|
||||
struct UpdateSlaveCallback : public virtual Referenced
|
||||
{
|
||||
virtual void updateSlave(osg::View& view, osg::View::Slave& slave) = 0;
|
||||
};
|
||||
|
||||
void updateSlave(View& view)
|
||||
{
|
||||
if (_updateSlaveCallback.valid()) _updateSlaveCallback->updateSlave(view, *this);
|
||||
else updateSlaveImplementation(view);
|
||||
}
|
||||
|
||||
virtual void updateSlaveImplementation(View& view);
|
||||
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
osg::Matrixd _projectionOffset;
|
||||
osg::Matrixd _viewOffset;
|
||||
bool _useMastersSceneData;
|
||||
osg::ref_ptr<UpdateSlaveCallback> _updateSlaveCallback;
|
||||
};
|
||||
|
||||
bool addSlave(osg::Camera* camera, bool useMastersSceneData=true) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity(), useMastersSceneData); }
|
||||
@ -142,9 +159,6 @@ class OSG_EXPORT View : public virtual osg::Object
|
||||
|
||||
void updateSlaves();
|
||||
|
||||
void updateSlave(unsigned int i);
|
||||
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~View();
|
||||
|
@ -132,7 +132,6 @@ void View::setCamera(osg::Camera* camera)
|
||||
if (_camera.valid())
|
||||
{
|
||||
_camera->setView(this);
|
||||
|
||||
_camera->setRenderer(createRenderer(camera));
|
||||
}
|
||||
}
|
||||
@ -141,23 +140,22 @@ void View::updateSlaves()
|
||||
{
|
||||
for(unsigned int i=0; i<_slaves.size(); ++i)
|
||||
{
|
||||
updateSlave(i);
|
||||
Slave& slave = _slaves[i];
|
||||
slave.updateSlave(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void View::updateSlave(unsigned int i)
|
||||
void View::Slave::updateSlaveImplementation(View& view)
|
||||
{
|
||||
if (i >= _slaves.size() || !_camera) return;
|
||||
if (!view.getCamera()) return;
|
||||
|
||||
Slave& slave = _slaves[i];
|
||||
|
||||
if (slave._camera->getReferenceFrame()==osg::Transform::RELATIVE_RF)
|
||||
if (_camera->getReferenceFrame()==osg::Transform::RELATIVE_RF)
|
||||
{
|
||||
slave._camera->setProjectionMatrix(_camera->getProjectionMatrix() * slave._projectionOffset);
|
||||
slave._camera->setViewMatrix(_camera->getViewMatrix() * slave._viewOffset);
|
||||
_camera->setProjectionMatrix(view.getCamera()->getProjectionMatrix() * _projectionOffset);
|
||||
_camera->setViewMatrix(view.getCamera()->getViewMatrix() * _viewOffset);
|
||||
}
|
||||
|
||||
slave._camera->inheritCullSettings(*_camera, slave._camera->getInheritanceMask());
|
||||
|
||||
_camera->inheritCullSettings(*(view.getCamera()), _camera->getInheritanceMask());
|
||||
}
|
||||
|
||||
bool View::addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset, bool useMastersSceneData)
|
||||
@ -183,7 +181,7 @@ bool View::addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, co
|
||||
|
||||
_slaves.push_back(Slave(camera, projectionOffset, viewOffset, useMastersSceneData));
|
||||
|
||||
updateSlave(i);
|
||||
_slaves[i].updateSlave(*this);
|
||||
|
||||
camera->setRenderer(createRenderer(camera));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user