Further work on improving stereo support in the OSG.

Renamed the osg::VisualsSettings to osg::DisplaySettings, and
osgUtil::VisualsRequirementsVisitor to osgUtil::DisplayRequirementsVisitor.

Added support for OSG_SCREEN_HEIGHT into osg::DisplaySettings, and added
a DisplaySettings* to the constructors of osg::SceneView and osg::Camera.
This commit is contained in:
Robert Osfield
2001-12-21 22:48:19 +00:00
parent 734be18471
commit 19c99dc94c
18 changed files with 212 additions and 150 deletions

View File

@@ -301,7 +301,7 @@ SOURCE=..\..\src\osg\Viewport.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\VisualsSettings.cpp
SOURCE=..\..\src\osg\DisplaySettings.cpp
# End Source File
# End Group
# Begin Group "Header Files"
@@ -581,7 +581,7 @@ SOURCE=..\..\include\osg\Viewport
# End Source File
# Begin Source File
SOURCE=..\..\include\osg\VisualsSettings
SOURCE=..\..\include\osg\DisplaySettings
# End Source File
# End Group
# Begin Group "Resource Files"

View File

@@ -201,7 +201,7 @@ SOURCE=..\..\src\osgUtil\Version.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgUtil\VisualsRequirementsVisitor.cpp
SOURCE=..\..\src\osgUtil\DisplayRequirementsVisitor.cpp
# End Source File
# End Group
# Begin Group "Header Files"
@@ -333,7 +333,7 @@ SOURCE=..\..\Include\osgUtil\Version
# End Source File
# Begin Source File
SOURCE=..\..\Include\osgUtil\VisualsRequirementsVisitor
SOURCE=..\..\Include\osgUtil\DisplayRequirementsVisitor
# End Source File
# End Group
# Begin Group "Resource Files"

View File

@@ -11,6 +11,7 @@
#include <osg/Quat>
#include <osg/ClippingVolume>
#include <osg/Viewport>
#include <osg/DisplaySettings>
namespace osg {
@@ -24,7 +25,8 @@ class SG_EXPORT Camera: public osg::Referenced
public:
Camera();
Camera(DisplaySettings* ds=NULL);
Camera(const Camera&);
Camera& operator=(const Camera&);
virtual ~Camera();
@@ -275,26 +277,26 @@ class SG_EXPORT Camera: public osg::Referenced
PROPORTIONAL_TO_SCREEN_DISTANCE
};
/** Set the fusion distance function which in use to calculate the
/** Set the mode of the fusion distance function which in use to calculate the
* fusion distance used in stereo rendering. Default value is
* PROPORTIONAL_TO_LOOK_DISTANCE, 1.0f.*/
void setFusionDistanceFunction(FusionDistanceMode mode, float ratio=1.0f)
{
_fusionDistanceMode = mode;
_fusionDistanceRatio = ratio;
_dirty = true;
}
* PROPORTIONAL_TO_LOOK_DISTANCE. Use in conjunction with setFusionDistanceRatio(float).*/
void setFusionDistanceMode(FusionDistanceMode mode) { _fusionDistanceMode = mode; _dirty = true; }
/** Get the fusion distance function.*/
void getFusionDistanceFunction(FusionDistanceMode& mode, float& ratio)
{
mode = _fusionDistanceMode;
ratio = _fusionDistanceRatio;
}
/** Get the mode of the fusion distance function.*/
FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
/** Set the ratio of the fusion distance function which in use to calculate the
* fusion distance used in stereo rendering. Default value is 1.0f
* Use in conjunction with setFusionDistanceMode(..).*/
void setFusionDistanceRatio(float ratio) { _fusionDistanceRatio = ratio; _dirty = true; }
/** Get the ratio of the fusion distance function.*/
float getFusionDistanceRatio() const { return _fusionDistanceRatio; }
/** Calculate and return the fusion distance, using the FusionDistanceFunction.*/
const float getFusionDistance() const;
/** Set the physical distance between the viewers eyes and the display system.
* Note, only used when rendering in stereo.*/
void setScreenDistance(float screenDistance) { _screenDistance = screenDistance; _dirty = true; }

View File

@@ -2,8 +2,8 @@
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_VISUALSSETTINGS
#define OSG_VISUALSSETTINGS 1
#ifndef OSG_DisplaySettings
#define OSG_DisplaySettings 1
#include <osg/Referenced>
@@ -12,33 +12,33 @@
namespace osg {
/** VisualsSettings class for encapsulating what visuals are required and
/** DisplaySettings class for encapsulating what visuals are required and
* have been set up, and the status of stereo viewing.*/
class SG_EXPORT VisualsSettings : public osg::Referenced
class SG_EXPORT DisplaySettings : public osg::Referenced
{
public:
VisualsSettings()
DisplaySettings()
{
setDefaults();
readEnvironmentalVariables();
}
VisualsSettings(std::vector<std::string>& commandLine)
DisplaySettings(std::vector<std::string>& commandLine)
{
setDefaults();
readEnvironmentalVariables();
readCommandLine(commandLine);
}
VisualsSettings(const VisualsSettings& vs);
DisplaySettings(const DisplaySettings& vs);
virtual ~VisualsSettings();
virtual ~DisplaySettings();
VisualsSettings& operator = (const VisualsSettings& vs);
DisplaySettings& operator = (const DisplaySettings& vs);
void merge(const VisualsSettings& vs);
void merge(const DisplaySettings& vs);
void setDefaults();
@@ -70,6 +70,9 @@ class SG_EXPORT VisualsSettings : public osg::Referenced
const float getScreenDistance() const { return _screenDistance; }
void setScreenHeight(const float height) { _screenHeight = height; }
const float getScreenHeight() const { return _screenHeight; }
void setDoubleBuffer(const bool flag) { _doubleBuffer = flag; }
const bool getDoubleBuffer() const { return _doubleBuffer; }
@@ -94,12 +97,13 @@ class SG_EXPORT VisualsSettings : public osg::Referenced
protected:
void copy(const VisualsSettings& vs);
void copy(const DisplaySettings& vs);
bool _stereo;
StereoMode _stereoMode;
float _eyeSeperation;
float _screenDistance;
float _screenHeight;
bool _doubleBuffer;
bool _RGB;

View File

@@ -11,7 +11,7 @@
#include <osg/FrameStamp>
#include <osg/Camera>
#include <osg/VisualsSettings>
#include <osg/DisplaySettings>
#include <vector>
#include <map>
@@ -108,20 +108,20 @@ class SG_EXPORT State : public Referenced
/** Get the camera */
inline const Camera* getCamera() const { return _camera.get(); }
/** Set the VisualsSettings. Note, nothing is applied, the visual settings are just used
/** Set the DisplaySettings. Note, nothing is applied, the visual settings are just used
* used in the State object to pass the current visual settings to Drawables
* during rendering. */
inline void setVisualsSettings(VisualsSettings* vs) { _visualsSettings = vs; }
inline void setDisplaySettings(DisplaySettings* vs) { _displaySettings = vs; }
/** Get the VisualsSettings */
inline const VisualsSettings* getVisualsSettings() const { return _visualsSettings.get(); }
/** Get the DisplaySettings */
inline const DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
private:
unsigned int _contextID;
ref_ptr<FrameStamp> _frameStamp;
ref_ptr<Camera> _camera;
ref_ptr<VisualsSettings> _visualsSettings;
ref_ptr<DisplaySettings> _displaySettings;
typedef std::vector<StateAttribute::GLModeValue> ValueVec;

View File

@@ -9,7 +9,7 @@
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/Timer>
#include <osg/VisualsSettings>
#include <osg/DisplaySettings>
#include <osgUtil/GUIEventAdapter>
#include <osgUtil/CameraManipulator>
@@ -178,7 +178,7 @@ class OSGGLUT_EXPORT Viewer : public osgUtil::GUIActionAdapter
osg::ref_ptr<osg::FrameStamp> _frameStamp;
osg::ref_ptr<osg::VisualsSettings> _visualsSettings;
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
};

View File

@@ -2,12 +2,12 @@
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSGUTIL_VISUALSREQUIREMENTSVISITOR
#define OSGUTIL_VISUALSREQUIREMENTSVISITOR 1
#ifndef OSGUTIL_DISPLAYEQUIREMENTSVISITOR
#define OSGUTIL_DISPLAYREQUIREMENTSVISITOR 1
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/VisualsSettings>
#include <osg/DisplaySettings>
#include <osgUtil/Export>
@@ -18,21 +18,21 @@ namespace osgUtil {
* applications to set up there windows with the correct visuals. Have a look at
* src/osgGLUT/Viewer.cpp's Viewer::open() method for an example how to use it.
*/
class OSGUTIL_EXPORT VisualsRequirementsVisitor : public osg::NodeVisitor
class OSGUTIL_EXPORT DisplayRequirementsVisitor : public osg::NodeVisitor
{
public:
/** Default to traversing all children, and reqiresDoubleBuffer,
* requiresRGB and requiresDepthBuffer to true and with
* alpha and stencil off.*/
VisualsRequirementsVisitor();
DisplayRequirementsVisitor();
/** Set the VisualsSettings. */
inline void setVisualsSettings(osg::VisualsSettings* vs) { _vs = vs; }
/** Set the DisplaySettings. */
inline void setDisplaySettings(osg::DisplaySettings* ds) { _ds = ds; }
/** Get the VisualsSettings */
inline const osg::VisualsSettings* getVisualsSettings() const { return _vs.get(); }
/** Get the DisplaySettings */
inline const osg::DisplaySettings* getDisplaySettings() const { return _ds.get(); }
virtual void applyStateSet(osg::StateSet& stateset);
@@ -44,7 +44,7 @@ class OSGUTIL_EXPORT VisualsRequirementsVisitor : public osg::NodeVisitor
protected:
osg::ref_ptr<osg::VisualsSettings> _vs;
osg::ref_ptr<osg::DisplaySettings> _ds;
};

View File

@@ -10,7 +10,7 @@
#include <osg/Light>
#include <osg/Camera>
#include <osg/FrameStamp>
#include <osg/VisualsSettings>
#include <osg/DisplaySettings>
#include <osgUtil/CullVisitor>
@@ -26,7 +26,7 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
public:
/** Construct a default scene view.*/
SceneView();
SceneView(osg::DisplaySettings* ds=NULL);
/** Set scene view to use default global state, light, camera
* and render visitor.
@@ -77,11 +77,11 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
_viewport->getViewport(x,y,width,height);
}
/** Set the VisualsSettings. */
inline void setVisualsSettings(osg::VisualsSettings* vs) { _visualsSettings = vs; }
/** Set the DisplaySettings. */
inline void setDisplaySettings(osg::DisplaySettings* vs) { _displaySettings = vs; }
/** Get the VisualsSettings */
inline const osg::VisualsSettings* getVisualsSettings() const { return _visualsSettings.get(); }
/** Get the DisplaySettings */
inline const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
/** Set the background color used in glClearColor().
@@ -218,7 +218,7 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
osg::ref_ptr<osg::StateSet> _globalState;
osg::ref_ptr<osg::Light> _light;
osg::ref_ptr<osg::Camera> _camera;
osg::ref_ptr<osg::VisualsSettings> _visualsSettings;
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
osg::ref_ptr<osg::State> _state;
bool _initCalled;

View File

@@ -6,16 +6,20 @@
using namespace osg;
#define DEG2RAD(x) ((x)*M_PI/180.0)
#define RAD2DEG(x) ((x)*180.0/M_PI)
Camera::Camera()
Camera::Camera(DisplaySettings* ds)
{
_adjustAspectRatioMode = ADJUST_HORIZONTAL;
// projection details.
setPerspective(45.0,1.0,1.0,1000.0);
float fovy = 45.0f;
if (ds)
{
fovy = 2.0f*RadiansToDegrees(atan(ds->getScreenHeight()*0.5/ds->getScreenDistance()));
}
setPerspective(fovy,1.0,1.0,1000.0);
// look at details.
_lookAtType =USE_HOME_POSITON;
@@ -30,7 +34,10 @@ Camera::Camera()
_useEyeOffset = false;
_eyeOffset.set(0.0f,0.0f,0.0f);
_screenDistance = 1.0f;
if (ds) _screenDistance = ds->getScreenDistance();
else _screenDistance = 0.33f;
_fusionDistanceMode = PROPORTIONAL_TO_LOOK_DISTANCE;
_fusionDistanceRatio = 1.0f;
}
@@ -172,7 +179,7 @@ void Camera::setPerspective(const double fovy,const double aspectRatio,
// subsequent changes in zNear do not affect them.
// calculate the appropriate left, right etc.
double tan_fovy = tan(DEG2RAD(fovy*0.5));
double tan_fovy = tan(DegreesToRadians(fovy*0.5));
_right = tan_fovy * aspectRatio;
_left = -_right;
_top = tan_fovy;
@@ -195,8 +202,8 @@ void Camera::setFOV(const double fovx,const double fovy,
// subsequent changes in zNear do not affect them.
// calculate the appropriate left, right etc.
double tan_fovx = tan(DEG2RAD(fovx*0.5));
double tan_fovy = tan(DEG2RAD(fovy*0.5));
double tan_fovx = tan(DegreesToRadians(fovx*0.5));
double tan_fovy = tan(DegreesToRadians(fovy*0.5));
_right = tan_fovx;
_left = -_right;
_top = tan_fovy;
@@ -304,7 +311,7 @@ const double Camera::calc_fovy() const
{
// note, _right & _left are prescaled by znear so
// no need to account for it.
return RAD2DEG(atan(_top)-atan(_bottom));
return RadiansToDegrees(atan(_top)-atan(_bottom));
}
@@ -315,7 +322,7 @@ const double Camera::calc_fovx() const
{
// note, _right & _left are prescaled by znear so
// no need to account for it.
return RAD2DEG(atan(_right)-atan(_left));
return RadiansToDegrees(atan(_right)-atan(_left));
}

View File

@@ -1,30 +1,31 @@
#include <osg/VisualsSettings>
#include <osg/DisplaySettings>
#include <algorithm>
using namespace osg;
VisualsSettings::VisualsSettings(const VisualsSettings& vs):Referenced()
DisplaySettings::DisplaySettings(const DisplaySettings& vs):Referenced()
{
copy(vs);
}
VisualsSettings::~VisualsSettings()
DisplaySettings::~DisplaySettings()
{
}
VisualsSettings& VisualsSettings::operator = (const VisualsSettings& vs)
DisplaySettings& DisplaySettings::operator = (const DisplaySettings& vs)
{
if (this==&vs) return *this;
copy(vs);
return *this;
}
void VisualsSettings::copy(const VisualsSettings& vs)
void DisplaySettings::copy(const DisplaySettings& vs)
{
_stereoMode = vs._stereoMode;
_eyeSeperation = vs._eyeSeperation;
_screenDistance = vs._screenDistance;
_screenHeight = vs._screenHeight;
_doubleBuffer = vs._doubleBuffer;
_RGB = vs._RGB;
@@ -33,7 +34,7 @@ void VisualsSettings::copy(const VisualsSettings& vs)
_minimumNumberStencilBits = vs._minimumNumberStencilBits;
}
void VisualsSettings::merge(const VisualsSettings& vs)
void DisplaySettings::merge(const DisplaySettings& vs)
{
if (_stereo || vs._stereo) _stereo = true;
@@ -47,12 +48,13 @@ void VisualsSettings::merge(const VisualsSettings& vs)
if (vs._minimumNumberStencilBits>_minimumNumberStencilBits) _minimumNumberStencilBits = vs._minimumNumberStencilBits;
}
void VisualsSettings::setDefaults()
void DisplaySettings::setDefaults()
{
_stereo = false;
_stereoMode = ANAGLYPHIC;
_eyeSeperation = 0.05f;
_screenDistance = 1.0f;
_screenDistance = 0.5f;
_screenHeight = 0.26f;
_doubleBuffer = true;
_RGB = true;
@@ -61,7 +63,7 @@ void VisualsSettings::setDefaults()
_minimumNumberStencilBits = 0;
}
void VisualsSettings::readEnvironmentalVariables()
void DisplaySettings::readEnvironmentalVariables()
{
char *ptr;
if( (ptr = getenv("OSG_STEREO_MODE")) )
@@ -109,9 +111,14 @@ void VisualsSettings::readEnvironmentalVariables()
{
_screenDistance = atof(ptr);
}
if( (ptr = getenv("OSG_SCREEN_HEIGHT")) )
{
_screenHeight = atof(ptr);
}
}
void VisualsSettings::readCommandLine(std::vector<std::string>& commandLine)
void DisplaySettings::readCommandLine(std::vector<std::string>& commandLine)
{
bool found = true;

View File

@@ -12,6 +12,7 @@ C++FILES = \
ColorMatrix.cpp \
CullFace.cpp\
Depth.cpp \
DisplaySettings.cpp\
Drawable.cpp\
EarthSky.cpp\
Fog.cpp\
@@ -54,7 +55,6 @@ C++FILES = \
Transparency.cpp\
Version.cpp\
Viewport.cpp\
VisualsSettings.cpp\
TARGET_BASENAME = osg
@@ -74,6 +74,7 @@ TARGET_INCLUDE_FILES = \
osg/ColorMatrix\
osg/CullFace\
osg/Depth\
osg/VisualsSettings\
osg/Drawable\
osg/EarthSky\
osg/Export\
@@ -127,7 +128,6 @@ TARGET_INCLUDE_FILES = \
osg/Vec4\
osg/Version\
osg/Viewport\
osg/VisualsSettings\
osg/mem_ptr\
osg/ref_ptr\

View File

@@ -34,7 +34,7 @@
#include <osgUtil/DisplayListVisitor>
#include <osgUtil/SmoothingVisitor>
#include <osgUtil/TriStripVisitor>
#include <osgUtil/VisualsRequirementsVisitor>
#include <osgUtil/DisplayRequirementsVisitor>
#include <osgUtil/TrackballManipulator>
#include <osgUtil/FlightManipulator>
@@ -128,7 +128,7 @@ Viewer::Viewer()
_frameStamp = new osg::FrameStamp;
_visualsSettings = new osg::VisualsSettings;
_displaySettings = new osg::DisplaySettings;
}
@@ -139,7 +139,7 @@ Viewer::~Viewer()
/** read the command line string list, removing any matched control sequences.*/
void Viewer::readCommandLine(std::vector<std::string>& commandLine)
{
_visualsSettings->readCommandLine(commandLine);
_displaySettings->readCommandLine(commandLine);
}
/**
@@ -207,21 +207,21 @@ bool Viewer::open()
// osg::notify(osg::INFO) << "Handled reshape "<< std::endl;
}
const osg::VisualsSettings* vs = sceneView->getVisualsSettings();
const osg::DisplaySettings* vs = sceneView->getDisplaySettings();
if (vs)
{
_visualsSettings->merge(*vs);
_displaySettings->merge(*vs);
}
else
{
// one does not already exist so attach the viewers visualsSettins to the SceneView
sceneView->setVisualsSettings(_visualsSettings.get());
sceneView->setDisplaySettings(_displaySettings.get());
}
}
if (_visualsSettings->getStereo() &&
_visualsSettings->getStereoMode()==osg::VisualsSettings::QUAD_BUFFER) needQuadBufferStereo = true;
if (_displaySettings->getStereo() &&
_displaySettings->getStereoMode()==osg::DisplaySettings::QUAD_BUFFER) needQuadBufferStereo = true;
//glutInit( &argc, argv ); // I moved this into main to avoid passing
// argc and argv to the Viewer
@@ -230,21 +230,21 @@ bool Viewer::open()
// traverse the scene graphs gathering the requirements of the OpenGL buffers.
osgUtil::VisualsRequirementsVisitor vrv;
vrv.setVisualsSettings(_visualsSettings.get());
osgUtil::DisplayRequirementsVisitor drv;
drv.setDisplaySettings(_displaySettings.get());
for(itr=_viewportList.begin();
itr!=_viewportList.end();
++itr)
{
Node* node = itr->sceneView->getSceneData();
if (node) node->accept(vrv);
if (node) node->accept(drv);
}
// set up each render stage to clear the appropriate buffers.
GLbitfield clear_mask=0;
if (_visualsSettings->getRGB()) clear_mask |= GL_COLOR_BUFFER_BIT;
if (_visualsSettings->getDepthBuffer()) clear_mask |= GL_DEPTH_BUFFER_BIT;
if (_visualsSettings->getStencilBuffer()) clear_mask |= GL_STENCIL_BUFFER_BIT;
if (_displaySettings->getRGB()) clear_mask |= GL_COLOR_BUFFER_BIT;
if (_displaySettings->getDepthBuffer()) clear_mask |= GL_DEPTH_BUFFER_BIT;
if (_displaySettings->getStencilBuffer()) clear_mask |= GL_STENCIL_BUFFER_BIT;
for(itr=_viewportList.begin();
itr!=_viewportList.end();
@@ -257,12 +257,12 @@ bool Viewer::open()
// set the GLUT display mode bit mask up to handle it.
unsigned int displayMode=0;
if (_visualsSettings->getDoubleBuffer()) displayMode |= GLUT_DOUBLE;
if (_displaySettings->getDoubleBuffer()) displayMode |= GLUT_DOUBLE;
else displayMode |= GLUT_SINGLE;
if (_visualsSettings->getRGB()) displayMode |= GLUT_RGB;
if (_visualsSettings->getDepthBuffer()) displayMode |= GLUT_DEPTH;
if (_visualsSettings->getAlphaBuffer()) displayMode |= GLUT_ALPHA;
if (_visualsSettings->getStencilBuffer()) displayMode |= GLUT_STENCIL;
if (_displaySettings->getRGB()) displayMode |= GLUT_RGB;
if (_displaySettings->getDepthBuffer()) displayMode |= GLUT_DEPTH;
if (_displaySettings->getAlphaBuffer()) displayMode |= GLUT_ALPHA;
if (_displaySettings->getStencilBuffer()) displayMode |= GLUT_STENCIL;
if (needQuadBufferStereo) displayMode |= GLUT_STEREO;
// and we'll add in multisample so that on systems like Onyx's can
@@ -1319,7 +1319,7 @@ void Viewer::addViewport(osgUtil::SceneView* sv,
void Viewer::addViewport(osg::Node* rootnode,
float x, float y, float width, float height)
{
osgUtil::SceneView *sceneView = new osgUtil::SceneView;
osgUtil::SceneView *sceneView = new osgUtil::SceneView(_displaySettings.get());
sceneView->setDefaults();
sceneView->setSceneData(rootnode);

View File

@@ -8,19 +8,19 @@
#include <osg/GeoSet>
#include <osgUtil/VisualsRequirementsVisitor>
#include <osgUtil/DisplayRequirementsVisitor>
using namespace osg;
using namespace osgUtil;
VisualsRequirementsVisitor::VisualsRequirementsVisitor()
DisplayRequirementsVisitor::DisplayRequirementsVisitor()
{
setTraversalMode(NodeVisitor::TRAVERSE_ALL_CHILDREN);
}
void VisualsRequirementsVisitor::applyStateSet(StateSet& stateset)
void DisplayRequirementsVisitor::applyStateSet(StateSet& stateset)
{
if (!_vs) _vs = new osg::VisualsSettings;
if (!_ds) _ds = new osg::DisplaySettings;
unsigned int min = 0; // assume stencil not needed by this stateset.
@@ -34,14 +34,14 @@ void VisualsRequirementsVisitor::applyStateSet(StateSet& stateset)
min = 1; // number stencil bits we need at least.
}
if (min>_vs->getMinimumNumStencilBits())
if (min>_ds->getMinimumNumStencilBits())
{
// only update if new minimum exceeds previous minimum.
_vs->setMinimumNumStencilBits(min);
_ds->setMinimumNumStencilBits(min);
}
}
void VisualsRequirementsVisitor::apply(Node& node)
void DisplayRequirementsVisitor::apply(Node& node)
{
osg::StateSet* stateset = node.getStateSet();
if (stateset) applyStateSet(*stateset);
@@ -49,7 +49,7 @@ void VisualsRequirementsVisitor::apply(Node& node)
traverse(node);
}
void VisualsRequirementsVisitor::apply(Geode& geode)
void DisplayRequirementsVisitor::apply(Geode& geode)
{
osg::StateSet* geode_stateset = geode.getStateSet();
if (geode_stateset) applyStateSet(*geode_stateset);
@@ -61,15 +61,15 @@ void VisualsRequirementsVisitor::apply(Geode& geode)
}
}
void VisualsRequirementsVisitor::apply(Impostor& impostor)
void DisplayRequirementsVisitor::apply(Impostor& impostor)
{
if (!_vs) _vs = new osg::VisualsSettings;
if (!_ds) _ds = new osg::DisplaySettings;
unsigned int min = 1; // number alpha bits we need at least.
if (min>_vs->getMinimumNumAlphaBits())
if (min>_ds->getMinimumNumAlphaBits())
{
// only update if new minimum exceeds previous minimum.
_vs->setMinimumNumAlphaBits(min);
_ds->setMinimumNumAlphaBits(min);
}
apply((Node&)impostor);

View File

@@ -266,38 +266,38 @@ bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
addMouseEvent(ea);
us.requestContinuousUpdate(true);
if (calcMovement()) us.requestRedraw();
return true;
}
return true;
case(GUIEventAdapter::RELEASE):
{
addMouseEvent(ea);
us.requestContinuousUpdate(true);
if (calcMovement()) us.requestRedraw();
return true;
}
return true;
case(GUIEventAdapter::DRAG):
{
addMouseEvent(ea);
us.requestContinuousUpdate(true);
if (calcMovement()) us.requestRedraw();
return true;
}
return true;
case(GUIEventAdapter::MOVE):
{
addMouseEvent(ea);
us.requestContinuousUpdate(true);
if (calcMovement()) us.requestRedraw();
return true;
}
return true;
case(GUIEventAdapter::KEYBOARD):
{
if (ea.getKey()==' ')
{
flushMouseEventStack();
@@ -316,18 +316,33 @@ bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
_speedMode = USE_MOUSE_BUTTONS_FOR_SPEED;
return true;
}
else if (ea.getKey()=='+')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f);
return true;
}
else if (ea.getKey()=='-')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f);
return true;
}
return false;
}
case(GUIEventAdapter::FRAME):
{
addMouseEvent(ea);
if (calcMovement()) us.requestRedraw();
return true;
}
case(GUIEventAdapter::RESIZE):
{
init(ea,us);
us.requestRedraw();
return true;
}
return true;
default:
return false;
}
@@ -350,11 +365,11 @@ void DriveManipulator::addMouseEvent(const GUIEventAdapter& ea)
bool DriveManipulator::calcMovement()
{
_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE);
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
_camera->setFusionDistanceFunction(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE,1.0f);
float dt = _ga_t0->time()-_ga_t1->time();
if (dt<0.0f)

View File

@@ -85,27 +85,27 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
addMouseEvent(ea);
us.requestContinuousUpdate(true);
if (calcMovement()) us.requestRedraw();
return true;
}
return true;
case(GUIEventAdapter::RELEASE):
{
addMouseEvent(ea);
us.requestContinuousUpdate(true);
if (calcMovement()) us.requestRedraw();
return true;
}
return true;
case(GUIEventAdapter::DRAG):
{
addMouseEvent(ea);
us.requestContinuousUpdate(true);
if (calcMovement()) us.requestRedraw();
return true;
}
return true;
case(GUIEventAdapter::MOVE):
{
@@ -113,8 +113,8 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestContinuousUpdate(true);
if (calcMovement()) us.requestRedraw();
return true;
}
return true;
case(GUIEventAdapter::KEYBOARD):
if (ea.getKey()==' ')
@@ -125,17 +125,28 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestContinuousUpdate(false);
return true;
}
else if (ea.getKey()=='+')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f);
return true;
}
else if (ea.getKey()=='-')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f);
return true;
}
return false;
case(GUIEventAdapter::FRAME):
addMouseEvent(ea);
if (calcMovement()) us.requestRedraw();
return true;
case(GUIEventAdapter::RESIZE):
{
init(ea,us);
us.requestRedraw();
}
return true;
return true;
default:
return false;
}
@@ -158,10 +169,11 @@ void FlightManipulator::addMouseEvent(const GUIEventAdapter& ea)
bool FlightManipulator::calcMovement()
{
_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE);
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
_camera->setFusionDistanceFunction(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE,1.0f);
float dt = _ga_t0->time()-_ga_t1->time();

View File

@@ -7,6 +7,7 @@ C++FILES = \
CullVisitor.cpp\
CullViewState.cpp\
DisplayListVisitor.cpp\
DisplayRequirementsVisitor.cpp\
DepthSortedBin.cpp\
DriveManipulator.cpp\
FlightManipulator.cpp\
@@ -29,7 +30,6 @@ C++FILES = \
TransformCallback.cpp\
TriStripVisitor.cpp\
Version.cpp\
VisualsRequirementsVisitor.cpp\
TARGET_BASENAME = osgUtil
@@ -48,6 +48,7 @@ TARGET_INCLUDE_FILES = \
osgUtil/CullViewState\
osgUtil/DepthSortedBin\
osgUtil/DisplayListVisitor\
osgUtil/DisplayRequirementsVisitor\
osgUtil/DriveManipulator\
osgUtil/Export\
osgUtil/FlightManipulator\
@@ -72,7 +73,6 @@ TARGET_INCLUDE_FILES = \
osgUtil/TransformCallback\
osgUtil/TriStripVisitor\
osgUtil/Version\
osgUtil/VisualsRequirementsVisitor\
C++FLAGS += -I ../../include

View File

@@ -13,8 +13,10 @@
using namespace osg;
using namespace osgUtil;
SceneView::SceneView()
SceneView::SceneView(DisplaySettings* ds)
{
_displaySettings = ds;
_calc_nearfar = true;
_backgroundColor.set(0.2f, 0.2f, 0.4f, 1.0f);
@@ -52,7 +54,7 @@ void SceneView::setDefaults()
_state = new State;
_camera = new Camera;
_camera = new Camera(_displaySettings.get());
_rendergraph = new RenderGraph;
_renderStage = new RenderStage;
@@ -282,7 +284,7 @@ void SceneView::draw()
_state->reset();
_state->setFrameStamp(_frameStamp.get());
_state->setVisualsSettings(_visualsSettings.get());
_state->setDisplaySettings(_displaySettings.get());
// note, to support multi-pipe systems the deletion of OpenGL display list
// and texture objects is deferred until the OpenGL context is the correct
@@ -294,19 +296,19 @@ void SceneView::draw()
RenderLeaf* previous = NULL;
if (_visualsSettings.valid() && _visualsSettings->getStereo())
if (_displaySettings.valid() && _displaySettings->getStereo())
{
_camera->setScreenDistance(_visualsSettings->getScreenDistance());
_camera->setScreenDistance(_displaySettings->getScreenDistance());
switch(_visualsSettings->getStereoMode())
switch(_displaySettings->getStereoMode())
{
case(osg::VisualsSettings::QUAD_BUFFER):
case(osg::DisplaySettings::QUAD_BUFFER):
{
osg::ref_ptr<osg::Camera> left_camera = new osg::Camera(*_camera);
osg::ref_ptr<osg::Camera> right_camera = new osg::Camera(*_camera);
float iod = _visualsSettings->getEyeSeperation();
float iod = _displaySettings->getEyeSeperation();
left_camera->adjustEyeOffsetForStereo(osg::Vec3(-iod*0.5,0.0f,0.0f));
right_camera->adjustEyeOffsetForStereo(osg::Vec3(iod*0.5,0.0f,0.0f));
@@ -322,12 +324,12 @@ void SceneView::draw()
_renderStage->draw(*_state,previous);
}
break;
case(osg::VisualsSettings::ANAGLYPHIC):
case(osg::DisplaySettings::ANAGLYPHIC):
{
osg::ref_ptr<osg::Camera> left_camera = new osg::Camera(*_camera);
osg::ref_ptr<osg::Camera> right_camera = new osg::Camera(*_camera);
float iod = _visualsSettings->getEyeSeperation();
float iod = _displaySettings->getEyeSeperation();
left_camera->adjustEyeOffsetForStereo(osg::Vec3(-iod*0.5,0.0f,0.0f));
right_camera->adjustEyeOffsetForStereo(osg::Vec3(iod*0.5,0.0f,0.0f));

View File

@@ -72,8 +72,9 @@ bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us
if (calcMovement()) us.requestRedraw();
us.requestContinuousUpdate(false);
_thrown = false;
return true;
}
return true;
case(GUIEventAdapter::RELEASE):
{
if (ea.getButtonMask()==0)
@@ -106,20 +107,23 @@ bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us
us.requestContinuousUpdate(false);
_thrown = false;
}
return true;
}
return true;
case(GUIEventAdapter::DRAG):
{
addMouseEvent(ea);
if (calcMovement()) us.requestRedraw();
us.requestContinuousUpdate(false);
_thrown = false;
return true;
}
return true;
case(GUIEventAdapter::MOVE):
{
return false;
}
return false;
case(GUIEventAdapter::KEYBOARD):
if (ea.getKey()==' ')
{
@@ -129,6 +133,15 @@ bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us
us.requestRedraw();
us.requestContinuousUpdate(false);
return true;
} else if (ea.getKey()=='+')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f);
return true;
}
else if (ea.getKey()=='-')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f);
return true;
}
return false;
case(GUIEventAdapter::FRAME):
@@ -175,7 +188,7 @@ void TrackballManipulator::addMouseEvent(const GUIEventAdapter& ea)
bool TrackballManipulator::calcMovement()
{
_camera->setFusionDistanceFunction(osg::Camera::PROPORTIONAL_TO_LOOK_DISTANCE,1.0f);
_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_LOOK_DISTANCE);
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;