@ -19,6 +19,7 @@
# include <string>
# include <string>
# include <components/debug/debuglog.hpp>
# include <components/debug/debuglog.hpp>
# include <components/misc/constants.hpp>
# include <components/sceneutil/statesetupdater.hpp>
# include <components/sceneutil/statesetupdater.hpp>
# include <components/sceneutil/visitor.hpp>
# include <components/sceneutil/visitor.hpp>
@ -69,7 +70,6 @@ namespace Stereo
void applyLeft ( osg : : StateSet * stateset , osgUtil : : CullVisitor * nv ) override
void applyLeft ( osg : : StateSet * stateset , osgUtil : : CullVisitor * nv ) override
{
{
osg : : Matrix dummy ;
auto * uProjectionMatrix = stateset - > getUniform ( " projectionMatrix " ) ;
auto * uProjectionMatrix = stateset - > getUniform ( " projectionMatrix " ) ;
if ( uProjectionMatrix )
if ( uProjectionMatrix )
uProjectionMatrix - > set ( mManager - > computeEyeViewOffset ( 0 ) * mManager - > computeEyeProjection ( 0 , SceneUtil : : AutoDepth : : isReversed ( ) ) ) ;
uProjectionMatrix - > set ( mManager - > computeEyeViewOffset ( 0 ) * mManager - > computeEyeProjection ( 0 , SceneUtil : : AutoDepth : : isReversed ( ) ) ) ;
@ -77,7 +77,6 @@ namespace Stereo
void applyRight ( osg : : StateSet * stateset , osgUtil : : CullVisitor * nv ) override
void applyRight ( osg : : StateSet * stateset , osgUtil : : CullVisitor * nv ) override
{
{
osg : : Matrix dummy ;
auto * uProjectionMatrix = stateset - > getUniform ( " projectionMatrix " ) ;
auto * uProjectionMatrix = stateset - > getUniform ( " projectionMatrix " ) ;
if ( uProjectionMatrix )
if ( uProjectionMatrix )
uProjectionMatrix - > set ( mManager - > computeEyeViewOffset ( 1 ) * mManager - > computeEyeProjection ( 1 , SceneUtil : : AutoDepth : : isReversed ( ) ) ) ;
uProjectionMatrix - > set ( mManager - > computeEyeViewOffset ( 1 ) * mManager - > computeEyeProjection ( 1 , SceneUtil : : AutoDepth : : isReversed ( ) ) ) ;
@ -135,7 +134,7 @@ namespace Stereo
: mViewer ( viewer )
: mViewer ( viewer )
, mMainCamera ( mViewer - > getCamera ( ) )
, mMainCamera ( mViewer - > getCamera ( ) )
, mUpdateCallback ( new StereoUpdateCallback ( this ) )
, mUpdateCallback ( new StereoUpdateCallback ( this ) )
, mMasterProjectionMatrix ( osg : : Matrix : : identity ( ) )
, mMasterProjectionMatrix ( osg : : Matrix d : : identity ( ) )
, mEyeResolutionOverriden ( false )
, mEyeResolutionOverriden ( false )
, mEyeResolutionOverride ( 0 , 0 )
, mEyeResolutionOverride ( 0 , 0 )
, mFrustumManager ( nullptr )
, mFrustumManager ( nullptr )
@ -322,7 +321,6 @@ namespace Stereo
near_ = Settings : : Manager : : getFloat ( " near clip " , " Camera " ) ;
near_ = Settings : : Manager : : getFloat ( " near clip " , " Camera " ) ;
far_ = Settings : : Manager : : getFloat ( " viewing distance " , " Camera " ) ;
far_ = Settings : : Manager : : getFloat ( " viewing distance " , " Camera " ) ;
auto projectionMatrix = mMainCamera - > getProjectionMatrix ( ) ;
if ( mUpdateViewCallback )
if ( mUpdateViewCallback )
{
{
@ -342,15 +340,25 @@ namespace Stereo
masterView . fov . angleUp = std : : max ( mView [ 0 ] . fov . angleUp , mView [ 1 ] . fov . angleUp ) ;
masterView . fov . angleUp = std : : max ( mView [ 0 ] . fov . angleUp , mView [ 1 ] . fov . angleUp ) ;
masterView . fov . angleLeft = std : : min ( mView [ 0 ] . fov . angleLeft , mView [ 1 ] . fov . angleLeft ) ;
masterView . fov . angleLeft = std : : min ( mView [ 0 ] . fov . angleLeft , mView [ 1 ] . fov . angleLeft ) ;
masterView . fov . angleRight = std : : max ( mView [ 0 ] . fov . angleRight , mView [ 1 ] . fov . angleRight ) ;
masterView . fov . angleRight = std : : max ( mView [ 0 ] . fov . angleRight , mView [ 1 ] . fov . angleRight ) ;
projectionMatrix = masterView . perspectiveMatrix ( near_ , far_ , false ) ;
auto projectionMatrix = masterView . perspectiveMatrix ( near_ , far_ , false ) ;
mMainCamera - > setProjectionMatrix ( projectionMatrix ) ;
mMainCamera - > setProjectionMatrix ( projectionMatrix ) ;
}
}
else
else
{
{
auto * ds = osg : : DisplaySettings : : instance ( ) . get ( ) ;
auto * ds = osg : : DisplaySettings : : instance ( ) . get ( ) ;
auto viewMatrix = mMainCamera - > getViewMatrix ( ) ;
auto viewMatrix = mMainCamera - > getViewMatrix ( ) ;
mViewOffsetMatrix [ 0 ] = osg : : Matrix : : inverse ( viewMatrix ) * ds - > computeLeftEyeViewImplementation ( viewMatrix ) ;
auto projectionMatrix = mMainCamera - > getProjectionMatrix ( ) ;
mViewOffsetMatrix [ 1 ] = osg : : Matrix : : inverse ( viewMatrix ) * ds - > computeRightEyeViewImplementation ( viewMatrix ) ;
auto s = ds - > getEyeSeparation ( ) * Constants : : UnitsPerMeter ;
mViewOffsetMatrix [ 0 ] = 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 ,
s , 0.0 , 0.0 , 1.0 ) ;
mViewOffsetMatrix [ 1 ] = 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 ,
- s , 0.0 , 0.0 , 1.0 ) ;
mProjectionMatrix [ 0 ] = ds - > computeLeftEyeProjectionImplementation ( projectionMatrix ) ;
mProjectionMatrix [ 0 ] = ds - > computeLeftEyeProjectionImplementation ( projectionMatrix ) ;
mProjectionMatrix [ 1 ] = ds - > computeRightEyeProjectionImplementation ( projectionMatrix ) ;
mProjectionMatrix [ 1 ] = ds - > computeRightEyeProjectionImplementation ( projectionMatrix ) ;
if ( SceneUtil : : AutoDepth : : isReversed ( ) )
if ( SceneUtil : : AutoDepth : : isReversed ( ) )