Added support for scaling the projection in vertical and horizontal split stereo

modes.
This commit is contained in:
Robert Osfield
2003-05-27 11:03:49 +00:00
parent 4a804ebf32
commit b444cc1ab3
4 changed files with 51 additions and 16 deletions

View File

@@ -111,6 +111,9 @@ class SG_EXPORT DisplaySettings : public osg::Referenced
void setSplitStereoVerticalSeparation(int s) { _splitStereoVerticalSeparation = s; }
int getSplitStereoVerticalSeparation() const { return _splitStereoVerticalSeparation; }
void setSplitStereoAutoAjustAspectRatio(bool flag) { _splitStereoAutoAdjustAspectRatio=flag; }
bool getSplitStereoAutoAjustAspectRatio() const { return _splitStereoAutoAdjustAspectRatio; }
void setScreenHeight(float height) { _screenHeight = height; }
float getScreenHeight() const { return _screenHeight; }
@@ -158,6 +161,7 @@ class SG_EXPORT DisplaySettings : public osg::Referenced
int _splitStereoHorizontalSeparation;
SplitStereoVerticalEyeMapping _splitStereoVerticalEyeMapping;
int _splitStereoVerticalSeparation;
bool _splitStereoAutoAdjustAspectRatio;
bool _doubleBuffer;
bool _RGB;

View File

@@ -47,6 +47,7 @@ void ApplicationUsage::addKeyboardMouseBinding(const std::string& option,const s
void ApplicationUsage::getFormatedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput)
{
unsigned int maxNumCharsInOptions = 0;
ApplicationUsage::UsageMap::const_iterator citr;
for(citr=um.begin();
@@ -58,7 +59,6 @@ void ApplicationUsage::getFormatedString(std::string& str, const UsageMap& um,un
unsigned int fullWidth = widthOfOutput;
unsigned int optionPos = 2;
unsigned int optionWidth = maxNumCharsInOptions;
unsigned int explanationPos = 2+maxNumCharsInOptions+2;
unsigned int explanationWidth = fullWidth-explanationPos;
@@ -69,7 +69,7 @@ void ApplicationUsage::getFormatedString(std::string& str, const UsageMap& um,un
++citr)
{
line.assign(fullWidth,' ');
line.replace(optionPos,optionWidth,citr->first);
line.replace(optionPos,citr->first.length(),citr->first);
const std::string& explanation = citr->second;
std::string::size_type pos = 0;
@@ -90,6 +90,7 @@ void ApplicationUsage::getFormatedString(std::string& str, const UsageMap& um,un
std::string::size_type width = minimum((std::string::size_type)(explanation.length()-pos),(std::string::size_type)(explanationWidth-offset));
std::string::size_type slashn_pos = explanation.find('\n',pos);
unsigned int extraSkip = 0;
bool concatinated = false;
if (slashn_pos!=std::string::npos)
@@ -123,13 +124,15 @@ void ApplicationUsage::getFormatedString(std::string& str, const UsageMap& um,un
concatinated = true;
}
}
line.replace(explanationPos+offset,explanationWidth, explanation, pos, width);
if (concatinated) { str += line; str += "-\n"; }
else { str += line; str += "\n"; }
// move to the next line of output.
line.assign(fullWidth,' ');
pos += width+extraSkip;

View File

@@ -55,6 +55,8 @@ void DisplaySettings::copy(const DisplaySettings& vs)
_splitStereoVerticalEyeMapping = vs._splitStereoVerticalEyeMapping;
_splitStereoVerticalSeparation = vs._splitStereoVerticalSeparation;
_splitStereoAutoAdjustAspectRatio = vs._splitStereoAutoAdjustAspectRatio;
_doubleBuffer = vs._doubleBuffer;
_RGB = vs._RGB;
@@ -93,6 +95,8 @@ void DisplaySettings::setDefaults()
_splitStereoVerticalEyeMapping = LEFT_EYE_TOP_VIEWPORT;
_splitStereoVerticalSeparation = 0;
_splitStereoAutoAdjustAspectRatio = true;
_doubleBuffer = true;
_RGB = true;
_depthBuffer = true;
@@ -110,6 +114,7 @@ static ApplicationUsageProxy DisplaySetting_e4(ApplicationUsage::ENVIRONMENTAL_V
static ApplicationUsageProxy DisplaySetting_e5(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING <mode>","LEFT_EYE_LEFT_VIEWPORT | LEFT_EYE_RIGHT_VIEWPORT");
static ApplicationUsageProxy DisplaySetting_e8(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION <float>","number of pixels between viewports");
static ApplicationUsageProxy DisplaySetting_e9(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING <mode>","LEFT_EYE_TOP_VIEWPORT | LEFT_EYE_BOTTOM_VIEWPORT");
static ApplicationUsageProxy DisplaySetting_e10(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO <mode>","OFF | ON Default to ON to compenstate for the compression of the aspect ratio when viewing in split screen stereo. Note, if you are setting fovx and fovy explicityly OFF should be used.");
static ApplicationUsageProxy DisplaySetting_e11(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_SEPARATION <float>","number of pixels between viewports");
static ApplicationUsageProxy DisplaySetting_e12(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS <int>","maximum number of graphics contexts to be used with applications.");
@@ -208,6 +213,19 @@ void DisplaySettings::readEnvironmentalVariables()
_splitStereoVerticalEyeMapping = LEFT_EYE_BOTTOM_VIEWPORT;
}
}
if( (ptr = getenv("OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO")) != 0)
{
if (strcmp(ptr,"OFF")==0)
{
_stereo = false;
}
else
if (strcmp(ptr,"ON")==0)
{
_stereo = true;
}
}
if( (ptr = getenv("OSG_SPLIT_STEREO_VERTICAL_SEPARATION")) != 0)
{

View File

@@ -297,11 +297,33 @@ void SceneView::cull()
if (!_renderStageRight.valid()) _renderStageRight = dynamic_cast<RenderStage*>(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL));
osg::Matrix projection_scale;
if (_displaySettings->getSplitStereoAutoAjustAspectRatio())
{
switch(_displaySettings->getStereoMode())
{
case(osg::DisplaySettings::HORIZONTAL_SPLIT):
projection_scale.makeScale(2.0f,1.0f,1.0f);
break;
case(osg::DisplaySettings::VERTICAL_SPLIT):
projection_scale.makeScale(1.0f,2.0f,1.0f);
break;
default:
break;
}
}
// set up the left eye.
osg::ref_ptr<osg::RefMatrix> projectionLeft = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
projection_scale*
(*projection));
@@ -321,6 +343,7 @@ void SceneView::cull()
0.0f,1.0f,0.0f,0.0f,
-iod/(2.0f*sd),0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f)*
projection_scale*
(*projection));
osg::ref_ptr<osg::RefMatrix> modelviewRight = new osg::RefMatrix( (*modelview) *
@@ -329,19 +352,6 @@ void SceneView::cull()
0.0f,0.0f,1.0f,0.0f,
-es,0.0f,0.0f,1.0f));
switch(_displaySettings->getStereoMode())
{
case(osg::DisplaySettings::HORIZONTAL_SPLIT):
(*projectionLeft).postMult(osg::Matrix::scale(2.0f,1.0f,1.0f));
(*projectionRight).postMult(osg::Matrix::scale(2.0f,1.0f,1.0f));
break;
case(osg::DisplaySettings::VERTICAL_SPLIT):
(*projectionLeft).postMult(osg::Matrix::scale(1.0f,2.0f,1.0f));
(*projectionRight).postMult(osg::Matrix::scale(1.0f,2.0f,1.0f));
break;
default:
break;
}
_cullVisitorRight->setTraversalMask(_cullMaskRight);