2006-09-19 04:54:48 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSG_VIEW
|
|
|
|
#define OSG_VIEW 1
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
#include <osg/Camera>
|
2006-09-19 04:54:48 +08:00
|
|
|
|
|
|
|
#include <OpenThreads/Mutex>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** View - maintains a master camera view and a list of slave cameras that are relative to this master camera.
|
|
|
|
* Note, if no slave cameras are attached to the view then the master camera does both the control and implementation of the rendering of the scene,
|
|
|
|
* but if slave cameras are present then the master controls the view onto the scene, while the slaves implement the rendering of the scene.
|
2006-09-19 04:54:48 +08:00
|
|
|
*/
|
2006-11-29 22:21:59 +08:00
|
|
|
class OSG_EXPORT View : public virtual osg::Referenced
|
2006-09-19 04:54:48 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
|
|
|
|
View();
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** Set the master camera of the view. */
|
|
|
|
void setCamera(osg::Camera* camera) { _camera = camera; }
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** Get the master camera of the view. */
|
|
|
|
osg::Camera* getCamera() { return _camera.get(); }
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** Get the const master camera of the view. */
|
|
|
|
const osg::Camera* getCamera() const { return _camera.get(); }
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** Slave allows one to up a camera that follows the master with a local offset to the project and view matrices.*/
|
|
|
|
struct Slave
|
2006-09-19 04:54:48 +08:00
|
|
|
{
|
2006-11-27 22:52:07 +08:00
|
|
|
Slave() {}
|
|
|
|
Slave(osg::Camera* camera, const osg::Matrixd& projectionOffset, const osg::Matrixd& viewOffset):
|
2006-09-19 04:54:48 +08:00
|
|
|
_camera(camera), _projectionOffset(projectionOffset), _viewOffset(viewOffset) {}
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
Slave(const Slave& rhs) :
|
2006-09-19 04:54:48 +08:00
|
|
|
_camera(rhs._camera), _projectionOffset(rhs._projectionOffset), _viewOffset(rhs._viewOffset) {}
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
Slave& operator = (const Slave& rhs)
|
2006-09-19 04:54:48 +08:00
|
|
|
{
|
|
|
|
_camera = rhs._camera;
|
|
|
|
_projectionOffset = rhs._projectionOffset;
|
|
|
|
_viewOffset = rhs._viewOffset;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::ref_ptr<osg::Camera> _camera;
|
2007-01-02 02:20:10 +08:00
|
|
|
osg::Matrixd _projectionOffset;
|
|
|
|
osg::Matrixd _viewOffset;
|
2006-09-19 04:54:48 +08:00
|
|
|
};
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
bool addSlave(osg::Camera* camera) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity()); }
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffse);
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
bool removeSlave(unsigned int pos);
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
unsigned int getNumSlaves() const { return _slaves.size(); }
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
Slave& getSlave(unsigned int pos) { return _slaves[pos]; }
|
|
|
|
const Slave& getSlave(unsigned int pos) const { return _slaves[pos]; }
|
2007-01-02 02:20:10 +08:00
|
|
|
|
|
|
|
Slave* findSlaveForCamera(osg::Camera* camera);
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
void updateSlaves();
|
2007-01-02 02:20:10 +08:00
|
|
|
|
|
|
|
void updateSlave(unsigned int i);
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2006-09-19 04:54:48 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~View();
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::ref_ptr<osg::Camera> _camera;
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
typedef std::vector<Slave> Slaves;
|
|
|
|
Slaves _slaves;
|
2006-09-19 04:54:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|