|
#include <osgDB/ReadFile>
#include <osgProducer/Viewer>
#include <osgGA/GUIEventHandler>
#include <osg/DisplaySettings>
osg:isplaySettings::StereoMode stereoMode[] =
{
osg:isplaySettings:UAD_BUFFER,
osg:isplaySettings::ANAGLYPHIC,
osg:isplaySettings::HORIZONTAL_SPLIT,
osg:isplaySettings::VERTICAL_SPLIT,
osg:isplaySettings:EFT_EYE,
osg:isplaySettings::RIGHT_EYE,
osg:isplaySettings::HORIZONTAL_INTERLACE,
osg:isplaySettings::VERTICAL_INTERLACE
};
osg:isplaySettings:isplayType displayType[] =
{
osg::DisplaySettings::MONITOR,
osg::DisplaySettings:OWERWALL,
osg::DisplaySettings::REALITY_CENTER,
osg::DisplaySettings::HEAD_MOUNTED_DISPLAY
};
class CMyGuiEvent : public osgGA::GUIEventHandler
{
public:
CMyGuiEvent(osg::DisplaySettings* pds)
:_stereo(true)
,_stereoMode(0)
,_displayType(0)
,_eyeSeperation(0.05)
{
if (!_pds)
{
_pds = new osg::DisplaySettings;
}
_pds = pds;
_pds->setStereo(true);
_pds->setEyeSeparation(_eyeSeperation);
}
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us)
{
if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN)
{
switch(ea.getKey())
{
case osgGA::GUIEventAdapter::KEY_F1:
_stereo = !_stereo;
_pds->setStereo(_stereo);
break;
case osgGA::GUIEventAdapter::KEY_Left:
if (_stereoMode==0)
_stereoMode=6;
else
_stereoMode--;
_pds->setStereoMode(stereoMode[_stereoMode]);
us.requestContinuousUpdate();
break;
case osgGA::GUIEventAdapter::KEY_Right:
if (_stereoMode==6)
_stereoMode=0;
else
_stereoMode++;
_pds->setStereoMode(stereoMode[_stereoMode]);
break;
case osgGA::GUIEventAdapter::KEY_Up:
if (_displayType==3)
_displayType=0;
else
_displayType++;
_pds->setDisplayType(displayType[_displayType]);
break;
case osgGA::GUIEventAdapter::KEY_Down:
if (_displayType==0)
_displayType=3;
else
_displayType--;
_pds->setDisplayType(displayType[_displayType]);
break;
case osgGA::GUIEventAdapter::KEY_KP_Add:
_eyeSeperation += 0.01;
_pds->setEyeSeparation(_eyeSeperation);
break;
case osgGA::GUIEventAdapter::KEY_KP_Subtract:
_eyeSeperation -= 0.01;
_pds->setEyeSeparation(_eyeSeperation);
break;
default:
break;
}
return true;
}
return false;
}
private:
osg::DisplaySettings* _pds;
bool _stereo;
int _stereoMode;
int _displayType;
double _eyeSeperation;
};上面立体显示的代码,本人不是很懂,希望哪位高手能够帮忙解读一下,非常感谢! |
|