2001-10-04 23:12:57 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
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>
|
|
|
|
#include <osg/Camera>
|
2001-09-22 10:42:08 +08:00
|
|
|
#include <osg/FrameStamp>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +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
|
2001-01-11 00:32:10 +08:00
|
|
|
* camera, global state, lights and the scene itself. Provides
|
|
|
|
* 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-01-11 00:32:10 +08:00
|
|
|
SceneView();
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void setSceneData(osg::Node* node) { _sceneData = node; _need_compile = true;}
|
|
|
|
/** 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.
|
|
|
|
_viewport = new osg::Viewport;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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-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; }
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void setGlobalState(osg::StateSet* state) { _globalState = state; }
|
|
|
|
osg::StateSet* getGlobalState() { return _globalState.get(); }
|
|
|
|
const osg::StateSet* getGlobalState() const { return _globalState.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
|
|
|
|
|
|
|
void setCamera(osg::Camera* camera) { _camera = camera; }
|
2001-09-20 05:08:56 +08:00
|
|
|
osg::Camera* getCamera() { return _camera.get(); }
|
|
|
|
const osg::Camera* getCamera() const { return _camera.get(); }
|
|
|
|
|
|
|
|
void setState(osg::State* state) { _state = state; }
|
|
|
|
osg::State* getState() { return _state.get(); }
|
|
|
|
const osg::State* getState() const { return _state.get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
void setAppVisitor(osg::NodeVisitor* av) { _appVisitor = av; }
|
|
|
|
osg::NodeVisitor* getAppVisitor() { return _appVisitor.get(); }
|
|
|
|
const osg::NodeVisitor* getAppVisitor() const { return _appVisitor.get(); }
|
|
|
|
|
|
|
|
void setCullVisitor(osgUtil::CullVisitor* cv) { _cullVisitor = cv; }
|
|
|
|
osgUtil::CullVisitor* getCullVisitor() { return _cullVisitor.get(); }
|
|
|
|
const osgUtil::CullVisitor* getCullVisitor() const { return _cullVisitor.get(); }
|
|
|
|
|
|
|
|
void setRenderGraph(osgUtil::RenderGraph* rg) { _rendergraph = rg; }
|
|
|
|
osgUtil::RenderGraph* getRenderGraph() { return _rendergraph.get(); }
|
|
|
|
const osgUtil::RenderGraph* getRenderGraph() const { return _rendergraph.get(); }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
void setLODBias(float bias) { _lodBias = bias; }
|
|
|
|
float getLODBias() const { return _lodBias; }
|
|
|
|
|
|
|
|
/** Set to true if you want SceneView to automatically calculate values
|
|
|
|
for the near/far clipping planes, each frame, set false to use camera's
|
|
|
|
internal near and far planes. Default value is true.
|
|
|
|
*/
|
|
|
|
void setCalcNearFar(bool calc) { _calc_nearfar = calc; }
|
2001-09-28 20:36:40 +08:00
|
|
|
/** return true if SceneView automatically calculates near and
|
2001-01-11 00:32:10 +08:00
|
|
|
far clipping planes for each frame.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
bool getCalcNearFar() const { return _calc_nearfar; }
|
|
|
|
|
|
|
|
/** 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(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** do app traversal of attached scene graph using App NodeVisitor.*/
|
|
|
|
virtual void app();
|
|
|
|
|
|
|
|
/** do cull traversal of attached scene graph using App CullVisitor.*/
|
2001-01-11 00:32:10 +08:00
|
|
|
virtual void cull();
|
2001-09-20 05:08:56 +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();
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Node> _sceneData;
|
2001-09-20 05:08:56 +08:00
|
|
|
osg::ref_ptr<osg::StateSet> _globalState;
|
2001-01-11 00:32:10 +08:00
|
|
|
osg::ref_ptr<osg::Light> _light;
|
|
|
|
osg::ref_ptr<osg::Camera> _camera;
|
2001-09-20 05:08:56 +08:00
|
|
|
osg::ref_ptr<osg::State> _state;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::NodeVisitor> _appVisitor;
|
|
|
|
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitor;
|
|
|
|
osg::ref_ptr<osgUtil::RenderGraph> _rendergraph;
|
|
|
|
osg::ref_ptr<osgUtil::RenderStage> _renderStage;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
bool _need_compile;
|
|
|
|
bool _calc_nearfar;
|
|
|
|
|
|
|
|
osg::Vec4 _backgroundColor;
|
|
|
|
|
|
|
|
double _near_plane;
|
|
|
|
double _far_plane;
|
|
|
|
|
|
|
|
float _lodBias;
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
osg::ref_ptr<osg::Viewport> _viewport;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
LightingMode _lightingMode;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
bool _prioritizeTextures;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|