|
本帖最后由 xingshujun 于 2013-8-29 19:38 编辑
我用的是trackingball漫游器,想对osg库进行扩展。实现一系列立体,如红蓝,左右,上下等。
下面是displaysettings.cpp的源代码中的一部分,用于设置右眼视图的projection和view矩阵,其中projection左乘一个错切矩阵,view矩阵乘以一个水平方向平移矩阵。- osg::Matrixd DisplaySettings::computeRightEyeProjectionImplementation(const osg::Matrixd& projection) const
- {
- double iod = getEyeSeparation();
- double sd = getScreenDistance();
- double scale_x = 1.0;
- double scale_y = 1.0;
- if (getSplitStereoAutoAdjustAspectRatio())
- {
- switch(getStereoMode())
- {
- case(HORIZONTAL_SPLIT):
- scale_x = 2.0;
- break;
- case(VERTICAL_SPLIT):
- scale_y = 2.0;
- break;
- default:
- break;
- }
- }
- if (getDisplayType()==HEAD_MOUNTED_DISPLAY)
- {
- // head mounted display has the same projection matrix for left and right eyes.
- return osg::Matrixd::scale(scale_x,scale_y,1.0) *
- projection;
- }
- else
- {
- // all other display types assume working like a projected power wall
- // need to shjear projection matrix to account for asymetric frustum due to eye offset.
- return osg::Matrixd(1.0,0.0,0.0,0.0,
- 0.0,1.0,0.0,0.0,
- -iod/(2.0*sd),0.0,1.0,0.0,
- 0.0,0.0,0.0,1.0) *
- osg::Matrixd::scale(scale_x,scale_y,1.0) *
- projection;
- }
- }
- osg::Matrixd DisplaySettings::computeRightEyeViewImplementation(const osg::Matrixd& view, double eyeSeperationScale) const
- {
- double iod = getEyeSeparation();
- double es = 0.5*iod*eyeSeperationScale;
- return view *
- osg::Matrixd(1.0,0.0,0.0,0.0,
- 0.0,1.0,0.0,0.0,
- 0.0,0.0,1.0,0.0,
- -es,0.0,0.0,1.0);
- }
复制代码 为什么在垂直方向上projection左乘一个错切矩阵,在view上右乘一个平移矩阵。人站于地面屏幕前,就得不到下面的立体效果 |
-
|