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:
@@ -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);
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user