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>
|
2007-05-08 06:07:23 +08:00
|
|
|
#include <osg/Light>
|
2009-01-27 21:23:20 +08:00
|
|
|
#include <osg/Stats>
|
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
|
|
|
*/
|
2007-09-30 00:46:08 +08:00
|
|
|
class OSG_EXPORT View : public virtual osg::Object
|
2006-09-19 04:54:48 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
View();
|
|
|
|
|
2007-02-26 04:05:23 +08:00
|
|
|
View(const osg::View& view, const osg::CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_Object(osg,View);
|
2007-09-21 23:34:25 +08:00
|
|
|
|
|
|
|
/** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */
|
|
|
|
virtual void take(View& rhs);
|
2007-01-20 03:53:23 +08:00
|
|
|
|
2009-01-27 21:23:20 +08:00
|
|
|
|
|
|
|
/** Set the Stats object used for collect various frame related timing and scene graph stats.*/
|
|
|
|
void setStats(osg::Stats* stats) { _stats = stats; }
|
|
|
|
|
|
|
|
/** Get the Viewers Stats object.*/
|
|
|
|
osg::Stats* getStats() { return _stats.get(); }
|
|
|
|
|
|
|
|
/** Get the Viewers Stats object.*/
|
|
|
|
const osg::Stats* getStats() const { return _stats.get(); }
|
|
|
|
|
|
|
|
|
2007-05-08 06:07:23 +08:00
|
|
|
/** Options for controlling the global lighting used for the view.*/
|
|
|
|
enum LightingMode
|
|
|
|
{
|
|
|
|
NO_LIGHT,
|
|
|
|
HEADLIGHT,
|
|
|
|
SKY_LIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Set the global lighting to use for this view.
|
|
|
|
* Defaults to headlight. */
|
|
|
|
void setLightingMode(LightingMode lightingMode);
|
|
|
|
|
|
|
|
/** Get the global lighting used for this view.*/
|
|
|
|
LightingMode getLightingMode() const { return _lightingMode; }
|
|
|
|
|
|
|
|
/** Get the global light.*/
|
|
|
|
void setLight(osg::Light* light) { _light = light; }
|
|
|
|
|
|
|
|
/** Get the global lighting if assigned.*/
|
|
|
|
osg::Light* getLight() { return _light.get(); }
|
|
|
|
|
|
|
|
/** Get the const global lighting if assigned.*/
|
|
|
|
const osg::Light* getLight() const { return _light.get(); }
|
2007-01-20 03:53:23 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** Set the master camera of the view. */
|
2007-01-22 02:24:54 +08:00
|
|
|
void setCamera(osg::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
|
|
|
|
2007-12-12 00:34:37 +08:00
|
|
|
/** Set the frame stamp of the view. */
|
|
|
|
void setFrameStamp(osg::FrameStamp* fs) { _frameStamp = fs; }
|
|
|
|
|
|
|
|
/** Get the frame stamp of the view. */
|
|
|
|
osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
|
|
|
|
|
|
|
|
/** Get the frame stamp of the view. */
|
|
|
|
const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
|
|
|
|
|
2011-03-01 22:48: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.*/
|
2011-03-15 21:30:27 +08:00
|
|
|
struct OSG_EXPORT Slave
|
2006-09-19 04:54:48 +08:00
|
|
|
{
|
2007-02-23 19:53:45 +08:00
|
|
|
Slave(bool useMastersSceneData=true):
|
|
|
|
_useMastersSceneData(useMastersSceneData) {}
|
|
|
|
|
|
|
|
Slave(osg::Camera* camera, const osg::Matrixd& projectionOffset, const osg::Matrixd& viewOffset, bool useMastersSceneData=true):
|
|
|
|
_camera(camera),
|
|
|
|
_projectionOffset(projectionOffset),
|
|
|
|
_viewOffset(viewOffset),
|
|
|
|
_useMastersSceneData(useMastersSceneData) {}
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
Slave(const Slave& rhs) :
|
2007-02-23 19:53:45 +08:00
|
|
|
_camera(rhs._camera),
|
|
|
|
_projectionOffset(rhs._projectionOffset),
|
|
|
|
_viewOffset(rhs._viewOffset),
|
2011-03-01 22:48:48 +08:00
|
|
|
_useMastersSceneData(rhs._useMastersSceneData),
|
|
|
|
_updateSlaveCallback(rhs._updateSlaveCallback) {}
|
2006-09-19 04:54:48 +08:00
|
|
|
|
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;
|
2007-02-23 19:53:45 +08:00
|
|
|
_useMastersSceneData = rhs._useMastersSceneData;
|
2011-03-01 22:48:48 +08:00
|
|
|
_updateSlaveCallback = rhs._updateSlaveCallback;
|
2006-09-19 04:54:48 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-03-01 22:48:48 +08:00
|
|
|
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;
|
2006-09-19 04:54:48 +08:00
|
|
|
};
|
|
|
|
|
2007-02-23 19:53:45 +08:00
|
|
|
bool addSlave(osg::Camera* camera, bool useMastersSceneData=true) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity(), useMastersSceneData); }
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2008-07-17 21:51:14 +08:00
|
|
|
bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset, bool useMastersSceneData=true);
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
bool removeSlave(unsigned int pos);
|
2007-09-22 03:43:06 +08:00
|
|
|
|
2009-01-30 18:55:28 +08:00
|
|
|
unsigned int getNumSlaves() const { return static_cast<unsigned int>(_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-09-22 03:43:06 +08:00
|
|
|
|
2008-07-17 21:51:14 +08:00
|
|
|
unsigned int findSlaveIndexForCamera(osg::Camera* camera) const;
|
2007-09-22 03:43:06 +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-09-22 03:43:06 +08:00
|
|
|
|
2006-09-19 04:54:48 +08:00
|
|
|
protected :
|
2007-09-22 03:43:06 +08:00
|
|
|
|
2006-09-19 04:54:48 +08:00
|
|
|
virtual ~View();
|
2007-09-22 03:43:06 +08:00
|
|
|
|
2007-08-03 22:50:58 +08:00
|
|
|
virtual osg::GraphicsOperation* createRenderer(osg::Camera*) { return 0; }
|
2007-08-02 19:02:47 +08:00
|
|
|
|
2009-01-27 21:23:20 +08:00
|
|
|
osg::ref_ptr<osg::Stats> _stats;
|
|
|
|
|
2007-12-12 00:34:37 +08:00
|
|
|
LightingMode _lightingMode;
|
|
|
|
osg::ref_ptr<osg::Light> _light;
|
2007-05-08 06:07:23 +08:00
|
|
|
|
2007-12-12 00:34:37 +08:00
|
|
|
osg::ref_ptr<osg::Camera> _camera;
|
2006-09-19 04:54:48 +08:00
|
|
|
|
2007-12-12 00:34:37 +08:00
|
|
|
typedef std::vector<Slave> Slaves;
|
|
|
|
Slaves _slaves;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
2006-09-19 04:54:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|