2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSGUTIL_SCENEVIEW
|
|
|
|
#define OSGUTIL_SCENEVIEW 1
|
|
|
|
|
|
|
|
#include <osg/Node>
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/StateSet>
|
2001-01-11 00:32:10 +08:00
|
|
|
#include <osg/Light>
|
2001-09-22 10:42:08 +08:00
|
|
|
#include <osg/FrameStamp>
|
2001-12-22 06:48:19 +08:00
|
|
|
#include <osg/DisplaySettings>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-04-01 00:40:44 +08:00
|
|
|
|
2002-04-11 16:24:55 +08:00
|
|
|
#include <osgUtil/CullVisitor>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osgUtil {
|
|
|
|
|
|
|
|
/**
|
2001-09-28 20:36:40 +08:00
|
|
|
* SceneView is literally a view of a scene, encapsulating the
|
2003-05-19 23:15:17 +08:00
|
|
|
* camera (modelview+projection matrices), global state, lights and the scene itself. Provides
|
2001-01-11 00:32:10 +08:00
|
|
|
* methods for setting up the view and rendering it.
|
|
|
|
*/
|
|
|
|
class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2001-09-28 20:36:40 +08:00
|
|
|
/** Construct a default scene view.*/
|
2001-12-22 06:48:19 +08:00
|
|
|
SceneView(osg::DisplaySettings* ds=NULL);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Set scene view to use default global state, light, camera
|
|
|
|
* and render visitor.
|
|
|
|
*/
|
|
|
|
void setDefaults();
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Set the data which to view. The data will typically be
|
|
|
|
* an osg::Scene but can be any osg::Node type.
|
|
|
|
*/
|
2002-07-21 09:29:11 +08:00
|
|
|
void setSceneData(osg::Node* node) { _sceneData = node; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get the scene data which to view. The data will typically be
|
|
|
|
* an osg::Scene but can be any osg::Node type.
|
|
|
|
*/
|
|
|
|
osg::Node* getSceneData() { return _sceneData.get(); }
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Get the const scene data which to view. The data will typically be
|
|
|
|
* an osg::Scene but can be any osg::Node type.
|
|
|
|
*/
|
|
|
|
const osg::Node* getSceneData() const { return _sceneData.get(); }
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Set the viewport of the scene view to use specfied osg::Viewport. */
|
|
|
|
void setViewport(osg::Viewport* viewport)
|
|
|
|
{
|
|
|
|
if (viewport) _viewport = viewport;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// ensure that _viewport is always valid.
|
2002-12-16 21:40:58 +08:00
|
|
|
_viewport = new osg::Viewport;
|
2001-09-22 10:42:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the viewport of the scene view to specified dimensions. */
|
2001-01-11 00:32:10 +08:00
|
|
|
void setViewport(int x,int y,int width,int height)
|
|
|
|
{
|
2001-09-22 10:42:08 +08:00
|
|
|
_viewport->setViewport(x,y,width,height);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
|
|
|
|
/** Get the const viewport. */
|
|
|
|
const osg::Viewport* getViewport() const { return _viewport.get(); }
|
|
|
|
|
|
|
|
/** Get the viewport. */
|
|
|
|
osg::Viewport* getViewport() { return _viewport.get(); }
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get the viewport of the scene view. */
|
|
|
|
void getViewport(int& x,int& y,int& width,int& height)
|
|
|
|
{
|
2001-09-22 10:42:08 +08:00
|
|
|
_viewport->getViewport(x,y,width,height);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-12-22 06:48:19 +08:00
|
|
|
/** Set the DisplaySettings. */
|
|
|
|
inline void setDisplaySettings(osg::DisplaySettings* vs) { _displaySettings = vs; }
|
2001-12-19 08:38:23 +08:00
|
|
|
|
2002-03-28 00:31:25 +08:00
|
|
|
/** Get the const DisplaySettings */
|
2001-12-22 06:48:19 +08:00
|
|
|
inline const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
|
2002-03-28 00:31:25 +08:00
|
|
|
|
|
|
|
/** Get the DisplaySettings */
|
|
|
|
inline osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Set the background color used in glClearColor().
|
|
|
|
Defaults to an off blue color.*/
|
|
|
|
void setBackgroundColor(const osg::Vec4& color) { _backgroundColor=color; }
|
|
|
|
/** Get the background color.*/
|
|
|
|
const osg::Vec4& getBackgroundColor() const { return _backgroundColor; }
|
|
|
|
|
2003-01-30 01:16:26 +08:00
|
|
|
void setGlobalStateSet(osg::StateSet* state) { _globalStateSet = state; }
|
|
|
|
osg::StateSet* getGlobalStateSet() { return _globalStateSet.get(); }
|
|
|
|
const osg::StateSet* getGlobalStateSet() const { return _globalStateSet.get(); }
|
|
|
|
|
|
|
|
void setLocalStateSet(osg::StateSet* state) { _localStateSet = state; }
|
|
|
|
osg::StateSet* getLocalStateSet() { return _localStateSet.get(); }
|
|
|
|
const osg::StateSet* getLocalStateSet() const { return _localStateSet.get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
enum LightingMode {
|
|
|
|
HEADLIGHT, // default
|
|
|
|
SKY_LIGHT,
|
|
|
|
NO_SCENEVIEW_LIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
void setLightingMode(LightingMode mode) { _lightingMode=mode; }
|
|
|
|
LightingMode getLightingMode() const { return _lightingMode; }
|
|
|
|
|
|
|
|
void setLight(osg::Light* light) { _light = light; }
|
2001-09-20 05:08:56 +08:00
|
|
|
osg::Light* getLight() { return _light.get(); }
|
|
|
|
const osg::Light* getLight() const { return _light.get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void setState(osg::State* state) { _state = state; }
|
|
|
|
osg::State* getState() { return _state.get(); }
|
|
|
|
const osg::State* getState() const { return _state.get(); }
|
2001-12-03 06:20:46 +08:00
|
|
|
|
2002-04-13 02:06:13 +08:00
|
|
|
|
2003-07-17 06:15:28 +08:00
|
|
|
|
2003-07-15 19:49:56 +08:00
|
|
|
/** Set the projection matrix. Can be thought of as setting the lens of a camera. */
|
2003-10-01 23:56:52 +08:00
|
|
|
inline void setProjectionMatrix(const osg::Matrixf& matrix) { _projectionMatrix.set(matrix); }
|
|
|
|
|
|
|
|
/** Set the projection matrix. Can be thought of as setting the lens of a camera. */
|
|
|
|
inline void setProjectionMatrix(const osg::Matrixd& matrix) { _projectionMatrix.set(matrix); }
|
2003-07-17 06:15:28 +08:00
|
|
|
|
|
|
|
/** Set to a orthographic projection. See OpenGL glOrtho for documentation further details.*/
|
|
|
|
void setProjectionMatrixAsOrtho(double left, double right,
|
|
|
|
double bottom, double top,
|
|
|
|
double zNear, double zFar);
|
|
|
|
|
|
|
|
/** Set to a 2D orthographic projection. See OpenGL glOrtho2D documentation for further details.*/
|
|
|
|
void setProjectionMatrixAsOrtho2D(double left, double right,
|
|
|
|
double bottom, double top);
|
|
|
|
|
|
|
|
/** Set to a perspective projection. See OpenGL glFrustum documentation for further details.*/
|
|
|
|
void setProjectionMatrixAsFrustum(double left, double right,
|
|
|
|
double bottom, double top,
|
|
|
|
double zNear, double zFar);
|
|
|
|
|
|
|
|
/** Create a symmetrical perspective projection, See OpenGL gluPerspective documentation for further details.
|
|
|
|
* Aspect ratio is defined as width/height.*/
|
|
|
|
void setProjectionMatrixAsPerspective(double fovy,double aspectRatio,
|
|
|
|
double zNear, double zFar);
|
2002-04-10 05:46:34 +08:00
|
|
|
|
2003-07-15 19:49:56 +08:00
|
|
|
/** Get the projection matrix.*/
|
2003-10-01 23:56:52 +08:00
|
|
|
osg::Matrixd& getProjectionMatrix() { return _projectionMatrix; }
|
2003-07-15 19:49:56 +08:00
|
|
|
|
|
|
|
/** Get the const projection matrix.*/
|
2003-10-01 23:56:52 +08:00
|
|
|
const osg::Matrixd& getProjectionMatrix() const { return _projectionMatrix; }
|
2003-07-15 19:49:56 +08:00
|
|
|
|
2003-07-17 06:15:28 +08:00
|
|
|
/** Get the othorgraphic settings of the orthographic projection matrix.
|
2003-09-29 21:14:34 +08:00
|
|
|
* Returns false if matrix is not an orthographic matrix, where parameter values are undefined.*/
|
|
|
|
bool getProjectionMatrixAsOrtho(double& left, double& right,
|
2003-07-17 06:15:28 +08:00
|
|
|
double& bottom, double& top,
|
|
|
|
double& zNear, double& zFar);
|
|
|
|
|
|
|
|
/** Get the frustum setting of a perspective projection matrix.
|
2003-09-29 21:14:34 +08:00
|
|
|
* Returns false if matrix is not a perspective matrix, where parameter values are undefined.*/
|
|
|
|
bool getProjectionMatrixAsFrustum(double& left, double& right,
|
2003-07-17 06:15:28 +08:00
|
|
|
double& bottom, double& top,
|
|
|
|
double& zNear, double& zFar);
|
|
|
|
|
2003-09-29 21:14:34 +08:00
|
|
|
/** Get the frustum setting of a symetric perspective projection matrix.
|
|
|
|
* Returns false if matrix is not a perspective matrix, where parameter values are undefined.
|
|
|
|
* Note, if matrix is not a symetric perspective matrix then the shear will be lost.
|
|
|
|
* Asymetric metrices occur when stereo, power walls, caves and reality center display are used.
|
|
|
|
* In these configuration one should use the AsFrustum method instead.*/
|
|
|
|
bool getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
|
|
|
|
double& zNear, double& zFar);
|
|
|
|
|
|
|
|
|
2003-07-15 19:49:56 +08:00
|
|
|
/** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */
|
2003-10-01 23:56:52 +08:00
|
|
|
inline void setViewMatrix(const osg::Matrixf& matrix) { _viewMatrix.set(matrix); }
|
|
|
|
|
|
|
|
/** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */
|
|
|
|
inline void setViewMatrix(const osg::Matrixd& matrix) { _viewMatrix.set(matrix); }
|
2003-07-17 06:15:28 +08:00
|
|
|
|
|
|
|
/** Set to the position and orientation of view matrix, using the same convention as gluLookAt. */
|
|
|
|
void setViewMatrixAsLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up);
|
|
|
|
|
2003-07-15 19:49:56 +08:00
|
|
|
|
|
|
|
/** Get the view matrix. */
|
2003-10-01 23:56:52 +08:00
|
|
|
osg::Matrixd& getViewMatrix() { return _viewMatrix; }
|
2003-07-15 19:49:56 +08:00
|
|
|
|
|
|
|
/** Get the const view matrix. */
|
2003-10-01 23:56:52 +08:00
|
|
|
const osg::Matrixd& getViewMatrix() const { return _viewMatrix; }
|
2001-12-19 08:38:23 +08:00
|
|
|
|
2003-07-17 06:15:28 +08:00
|
|
|
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
|
|
|
|
void getViewMatrixAsLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float lookDistance=1.0f);
|
|
|
|
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
void setInitVisitor(osg::NodeVisitor* av) { _initVisitor = av; }
|
|
|
|
osg::NodeVisitor* getInitVisitor() { return _initVisitor.get(); }
|
|
|
|
const osg::NodeVisitor* getInitVisitor() const { return _initVisitor.get(); }
|
|
|
|
|
2003-08-30 07:04:42 +08:00
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
void setUpdateVisitor(osg::NodeVisitor* av) { _updateVisitor = av; }
|
|
|
|
osg::NodeVisitor* getUpdateVisitor() { return _updateVisitor.get(); }
|
|
|
|
const osg::NodeVisitor* getUpdateVisitor() const { return _updateVisitor.get(); }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2003-08-30 07:04:42 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void setCullVisitor(osgUtil::CullVisitor* cv) { _cullVisitor = cv; }
|
|
|
|
osgUtil::CullVisitor* getCullVisitor() { return _cullVisitor.get(); }
|
|
|
|
const osgUtil::CullVisitor* getCullVisitor() const { return _cullVisitor.get(); }
|
|
|
|
|
2003-08-30 07:04:42 +08:00
|
|
|
void setCullVisitorLeft(osgUtil::CullVisitor* cv) { _cullVisitorLeft = cv; }
|
|
|
|
osgUtil::CullVisitor* getCullVisitorLeft() { return _cullVisitorLeft.get(); }
|
|
|
|
const osgUtil::CullVisitor* getCullVisitorLeft() const { return _cullVisitorLeft.get(); }
|
|
|
|
|
|
|
|
void setCullVisitorRight(osgUtil::CullVisitor* cv) { _cullVisitorRight = cv; }
|
|
|
|
osgUtil::CullVisitor* getCullVisitorRight() { return _cullVisitorRight.get(); }
|
|
|
|
const osgUtil::CullVisitor* getCullVisitorRight() const { return _cullVisitorRight.get(); }
|
|
|
|
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void setRenderGraph(osgUtil::RenderGraph* rg) { _rendergraph = rg; }
|
|
|
|
osgUtil::RenderGraph* getRenderGraph() { return _rendergraph.get(); }
|
|
|
|
const osgUtil::RenderGraph* getRenderGraph() const { return _rendergraph.get(); }
|
|
|
|
|
2003-08-30 07:04:42 +08:00
|
|
|
void setRenderGraphLeft(osgUtil::RenderGraph* rg) { _rendergraphLeft = rg; }
|
|
|
|
osgUtil::RenderGraph* getRenderGraphLeft() { return _rendergraphLeft.get(); }
|
|
|
|
const osgUtil::RenderGraph* getRenderGraphLeft() const { return _rendergraphLeft.get(); }
|
|
|
|
|
|
|
|
void setRenderGraphRight(osgUtil::RenderGraph* rg) { _rendergraphRight = rg; }
|
|
|
|
osgUtil::RenderGraph* getRenderGraphRight() { return _rendergraphRight.get(); }
|
|
|
|
const osgUtil::RenderGraph* getRenderGraphRight() const { return _rendergraphRight.get(); }
|
|
|
|
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void setRenderStage(osgUtil::RenderStage* rs) { _renderStage = rs; }
|
|
|
|
osgUtil::RenderStage* getRenderStage() { return _renderStage.get(); }
|
|
|
|
const osgUtil::RenderStage* getRenderStage() const { return _renderStage.get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2003-08-30 07:04:42 +08:00
|
|
|
void setRenderStageLeft(osgUtil::RenderStage* rs) { _renderStageLeft = rs; }
|
|
|
|
osgUtil::RenderStage* getRenderStageLeft() { return _renderStageLeft.get(); }
|
|
|
|
const osgUtil::RenderStage* getRenderStageLeft() const { return _renderStageLeft.get(); }
|
|
|
|
|
|
|
|
void setRenderStageRight(osgUtil::RenderStage* rs) { _renderStageRight = rs; }
|
|
|
|
osgUtil::RenderStage* getRenderStageRight() { return _renderStageRight.get(); }
|
|
|
|
const osgUtil::RenderStage* getRenderStageRight() const { return _renderStageRight.get(); }
|
|
|
|
|
2002-03-04 06:31:46 +08:00
|
|
|
|
|
|
|
void setCullMask(const osg::Node::NodeMask nm) { _cullMask = nm; }
|
2003-06-24 23:40:09 +08:00
|
|
|
osg::Node::NodeMask getCullMask() const { return _cullMask; }
|
2002-03-04 06:31:46 +08:00
|
|
|
|
|
|
|
void setCullMaskLeft(const osg::Node::NodeMask nm) { _cullMaskLeft = nm; }
|
2003-06-24 23:40:09 +08:00
|
|
|
osg::Node::NodeMask getCullMaskLeft() const { return _cullMaskLeft; }
|
2002-03-04 06:31:46 +08:00
|
|
|
|
|
|
|
void setCullMaskRight(const osg::Node::NodeMask nm) { _cullMaskRight = nm; }
|
2003-06-24 23:40:09 +08:00
|
|
|
osg::Node::NodeMask getCullMaskRight() const { return _cullMaskRight; }
|
2002-03-04 06:31:46 +08:00
|
|
|
|
2003-08-30 07:04:42 +08:00
|
|
|
|
2002-07-03 03:53:18 +08:00
|
|
|
/** Set the LOD bias for the CullVisitor to use.*/
|
2002-11-12 18:22:38 +08:00
|
|
|
void setLODScale(float bias) { _LODScale = bias; }
|
2002-07-03 03:53:18 +08:00
|
|
|
|
|
|
|
/** Get the LOD bias.*/
|
2002-11-12 18:22:38 +08:00
|
|
|
float getLODScale() const { return _LODScale; }
|
2002-07-03 03:53:18 +08:00
|
|
|
|
|
|
|
/** Set the Small Feature Culling Pixel Size.*/
|
|
|
|
void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; }
|
|
|
|
|
|
|
|
/** Get the Small Feature Culling Pixel Size.*/
|
|
|
|
float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; }
|
|
|
|
|
|
|
|
/** Set the culling mode for the CullVisitor to use.*/
|
|
|
|
void setCullingMode(osg::CullStack::CullingMode mode) { _cullingMode = mode; }
|
|
|
|
|
|
|
|
/** Returns the current CullingMode.*/
|
|
|
|
osg::CullStack::CullingMode getCullingMode() const { return _cullingMode; }
|
|
|
|
|
|
|
|
/** Set the ComputeNearFarMode for the CullVisitor to use.*/
|
|
|
|
void setComputeNearFarMode(CullVisitor::ComputeNearFarMode cnfm) { _computeNearFar=cnfm; }
|
|
|
|
|
|
|
|
/** Get the ComputeNearFarMode.*/
|
|
|
|
CullVisitor::ComputeNearFarMode getComputeNearFarMode() const { return _computeNearFar;}
|
|
|
|
|
2002-09-04 18:49:17 +08:00
|
|
|
/** FusionDistanceMode is used only when working in stereo.*/
|
|
|
|
enum FusionDistanceMode
|
|
|
|
{
|
|
|
|
/** Use fusion distance from the value set on the SceneView.*/
|
|
|
|
USE_FUSION_DISTANCE_VALUE,
|
|
|
|
/** Compute the fusion distance by multiplying the screen distance by the fusion distance value.*/
|
|
|
|
PROPORTIONAL_TO_SCREEN_DISTANCE
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Set the FusionDistanceMode and Value. Note, is used only when working in stereo.*/
|
2002-09-12 22:29:59 +08:00
|
|
|
void setFusionDistance(FusionDistanceMode mode,float value=1.0f)
|
|
|
|
{
|
|
|
|
_fusionDistanceMode = mode;
|
|
|
|
_fusionDistanceValue = value;
|
|
|
|
}
|
2002-09-04 18:49:17 +08:00
|
|
|
|
|
|
|
/** Get the FusionDistanceMode.*/
|
|
|
|
FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
|
|
|
|
|
|
|
|
/** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
|
|
|
|
float getFusionDistanceValue() const { return _fusionDistanceValue; }
|
2002-03-04 06:31:46 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
/** set whether the draw method should call renderer->prioritizeTexture.*/
|
|
|
|
void setPrioritizeTextures(bool pt) { _prioritizeTextures = pt; }
|
|
|
|
|
|
|
|
/** get whether the draw method should call renderer->prioritizeTexture.*/
|
|
|
|
bool getPrioritizeTextures() const { return _prioritizeTextures; }
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Calculate, via glUnProject, the object coordinates of a window point.
|
|
|
|
Note, current implementation requires that SceneView::draw() has been previously called
|
|
|
|
for projectWindowIntoObject to produce valid values. Consistent with OpenGL
|
|
|
|
windows coordinates are calculated relative to the bottom left of the window.
|
|
|
|
Returns true on successful projection.
|
|
|
|
*/
|
|
|
|
bool projectWindowIntoObject(const osg::Vec3& window,osg::Vec3& object) const;
|
|
|
|
|
|
|
|
/** Calculate, via glUnProject, the object coordinates of a window x,y
|
|
|
|
when projected onto the near and far planes.
|
|
|
|
Note, current implementation requires that SceneView::draw() has been previously called
|
|
|
|
for projectWindowIntoObject to produce valid values. Consistent with OpenGL
|
|
|
|
windows coordinates are calculated relative to the bottom left of the window.
|
|
|
|
Returns true on successful projection.
|
|
|
|
*/
|
|
|
|
bool projectWindowXYIntoObject(int x,int y,osg::Vec3& near_point,osg::Vec3& far_point) const;
|
|
|
|
|
|
|
|
/** Calculate, via glProject, the object coordinates of a window.
|
|
|
|
Note, current implementation requires that SceneView::draw() has been previously called
|
|
|
|
for projectWindowIntoObject to produce valid values. Consistent with OpenGL
|
|
|
|
windows coordinates are calculated relative to the bottom left of the window,
|
|
|
|
whereas as window API's normally have the top left as the origin,
|
|
|
|
so you may need to pass in (mouseX,window_height-mouseY,...).
|
|
|
|
Returns true on successful projection.
|
|
|
|
*/
|
|
|
|
bool projectObjectIntoWindow(const osg::Vec3& object,osg::Vec3& window) const;
|
|
|
|
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Set the frame stamp for the current frame.*/
|
|
|
|
inline void setFrameStamp(osg::FrameStamp* fs) { _frameStamp = fs; }
|
|
|
|
|
|
|
|
/** Set the frame stamp for the current frame.*/
|
|
|
|
inline const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
|
|
|
|
|
|
|
|
|
2003-10-01 23:56:52 +08:00
|
|
|
|
|
|
|
/** callback for overidding the default method for compute the offset projection and view matrices.*/
|
|
|
|
struct ComputeStereoMatricesCallback : public osg::Referenced
|
|
|
|
{
|
|
|
|
virtual osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const = 0;
|
|
|
|
virtual osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const = 0;
|
|
|
|
|
|
|
|
virtual osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const = 0;
|
|
|
|
virtual osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void setComputeStereoMatricesCallback(ComputeStereoMatricesCallback* callback) { _computeStereoMatricesCallback=callback; }
|
|
|
|
ComputeStereoMatricesCallback* getComputeStereoMatricesCallback(ComputeStereoMatricesCallback* callback) { return _computeStereoMatricesCallback.get(); }
|
|
|
|
const ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() const { return _computeStereoMatricesCallback.get(); }
|
|
|
|
|
|
|
|
inline osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const
|
|
|
|
{
|
|
|
|
if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeLeftEyeProjection(projection);
|
|
|
|
else return computeLeftEyeProjectionImplementation(projection);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const
|
|
|
|
{
|
|
|
|
if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeLeftEyeView(view);
|
|
|
|
else return computeLeftEyeViewImplementation(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const
|
|
|
|
{
|
|
|
|
if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeRightEyeProjection(projection);
|
|
|
|
else return computeRightEyeProjectionImplementation(projection);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const
|
|
|
|
{
|
|
|
|
if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeRightEyeView(view);
|
|
|
|
else return computeRightEyeViewImplementation(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual osg::Matrixd computeLeftEyeProjectionImplementation(const osg::Matrixd& projection) const;
|
|
|
|
virtual osg::Matrixd computeLeftEyeViewImplementation(const osg::Matrixd& view) const;
|
|
|
|
|
|
|
|
virtual osg::Matrixd computeRightEyeProjectionImplementation(const osg::Matrixd& projection) const;
|
|
|
|
virtual osg::Matrixd computeRightEyeViewImplementation(const osg::Matrixd& view) const;
|
|
|
|
|
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
/** Do init traversal of attached scene graph using Init NodeVisitor.
|
|
|
|
* The init traversal is called once for each SceneView, and should
|
|
|
|
* be used to compile display list, texture objects intialize data
|
|
|
|
* not otherwise intializaed during scene graph loading. Note, is
|
2002-12-19 23:55:40 +08:00
|
|
|
* called automatically by update&cull if it hasn't already been called
|
2001-10-21 04:26:36 +08:00
|
|
|
* elsewhere. Also init() should only ever be called within a valid
|
|
|
|
* graphics context.*/
|
|
|
|
virtual void init();
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
/** Do app traversal of attached scene graph using App NodeVisitor.*/
|
2002-12-19 23:55:40 +08:00
|
|
|
virtual void update();
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
/** Do cull traversal of attached scene graph using Cull NodeVisitor.*/
|
2001-01-11 00:32:10 +08:00
|
|
|
virtual void cull();
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
/** Do draw traversal of draw bins generated by cull traversal.*/
|
2001-01-11 00:32:10 +08:00
|
|
|
virtual void draw();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~SceneView();
|
|
|
|
|
2002-02-14 21:26:37 +08:00
|
|
|
/** Do cull traversal of attached scene graph using Cull NodeVisitor.*/
|
2003-10-01 23:56:52 +08:00
|
|
|
virtual void cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage);
|
2002-02-14 21:26:37 +08:00
|
|
|
|
2002-04-16 19:41:32 +08:00
|
|
|
const osg::Matrix computeMVPW() const;
|
|
|
|
|
2002-04-16 23:31:46 +08:00
|
|
|
void clearArea(int x,int y,int width,int height,const osg::Vec4& color);
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
osg::ref_ptr<osg::Node> _sceneData;
|
2003-01-30 01:16:26 +08:00
|
|
|
osg::ref_ptr<osg::StateSet> _globalStateSet;
|
|
|
|
osg::ref_ptr<osg::StateSet> _localStateSet;
|
2001-01-11 00:32:10 +08:00
|
|
|
osg::ref_ptr<osg::Light> _light;
|
2003-10-01 23:56:52 +08:00
|
|
|
osg::Matrixd _projectionMatrix;
|
|
|
|
osg::Matrixd _viewMatrix;
|
2001-12-22 06:48:19 +08:00
|
|
|
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
|
2001-09-20 05:08:56 +08:00
|
|
|
osg::ref_ptr<osg::State> _state;
|
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
bool _initCalled;
|
|
|
|
osg::ref_ptr<osg::NodeVisitor> _initVisitor;
|
2002-12-19 23:55:40 +08:00
|
|
|
osg::ref_ptr<osg::NodeVisitor> _updateVisitor;
|
2002-03-04 06:31:46 +08:00
|
|
|
osg::Node::NodeMask _cullMask;
|
2001-09-20 05:08:56 +08:00
|
|
|
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitor;
|
|
|
|
osg::ref_ptr<osgUtil::RenderGraph> _rendergraph;
|
|
|
|
osg::ref_ptr<osgUtil::RenderStage> _renderStage;
|
2002-02-14 21:26:37 +08:00
|
|
|
|
2003-10-01 23:56:52 +08:00
|
|
|
osg::ref_ptr<ComputeStereoMatricesCallback> _computeStereoMatricesCallback;
|
|
|
|
|
2002-03-04 06:31:46 +08:00
|
|
|
osg::Node::NodeMask _cullMaskLeft;
|
2002-02-19 07:01:09 +08:00
|
|
|
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitorLeft;
|
|
|
|
osg::ref_ptr<osgUtil::RenderGraph> _rendergraphLeft;
|
2002-02-14 21:26:37 +08:00
|
|
|
osg::ref_ptr<osgUtil::RenderStage> _renderStageLeft;
|
2002-02-19 07:01:09 +08:00
|
|
|
|
2002-03-04 06:31:46 +08:00
|
|
|
osg::Node::NodeMask _cullMaskRight;
|
2002-02-19 07:01:09 +08:00
|
|
|
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitorRight;
|
|
|
|
osg::ref_ptr<osgUtil::RenderGraph> _rendergraphRight;
|
2002-02-14 21:26:37 +08:00
|
|
|
osg::ref_ptr<osgUtil::RenderStage> _renderStageRight;
|
|
|
|
|
2002-09-04 18:49:17 +08:00
|
|
|
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
|
|
|
|
|
|
|
osg::Vec4 _backgroundColor;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-09-04 18:49:17 +08:00
|
|
|
CullVisitor::ComputeNearFarMode _computeNearFar;
|
|
|
|
osg::CullStack::CullingMode _cullingMode;
|
2002-11-12 18:22:38 +08:00
|
|
|
float _LODScale;
|
2002-09-04 18:49:17 +08:00
|
|
|
float _smallFeatureCullingPixelSize;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-09-04 18:49:17 +08:00
|
|
|
FusionDistanceMode _fusionDistanceMode;
|
|
|
|
float _fusionDistanceValue;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-09-04 18:49:17 +08:00
|
|
|
osg::ref_ptr<osg::Viewport> _viewport;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-09-04 18:49:17 +08:00
|
|
|
LightingMode _lightingMode;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-09-04 18:49:17 +08:00
|
|
|
bool _prioritizeTextures;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|