Skip to content

Commit

Permalink
added live preview of Stereo Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Bernasocchi authored and pka committed Jul 5, 2011
1 parent 0a45bff commit b740549
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 46 deletions.
49 changes: 27 additions & 22 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -51,6 +51,7 @@
using namespace osgEarth::Drivers;
using namespace osgEarthUtil::Controls2;

#define MOVE_OFFSET 0.05

//static const char * const sIdent = "$Id: plugin.cpp 9327 2008-09-14 11:18:44Z jef $";
static const QString sName = QObject::tr( "Globe" );
Expand Down Expand Up @@ -318,16 +319,15 @@ void GlobePlugin::setupControls()
moveHControls->setPosition( 5, 35 );

osgEarthUtil::EarthManipulator* manip = dynamic_cast<osgEarthUtil::EarthManipulator*>(viewer.getCameraManipulator());

//Move Left
osg::Image* moveLeftImg = osgDB::readImageFile( imgDir + "/move-left.png" );
ImageControl* moveLeft = new NavigationControl( moveLeftImg );
moveLeft->addEventHandler( new PanControlHandler( manip, -0.05, 0 ) );
moveLeft->addEventHandler( new PanControlHandler( manip, -MOVE_OFFSET, 0 ) );

//Move Right
osg::Image* moveRightImg = osgDB::readImageFile( imgDir + "/move-right.png" );
ImageControl* moveRight = new NavigationControl( moveRightImg );
moveRight->addEventHandler( new PanControlHandler( manip, 0.05, 0 ) );
moveRight->addEventHandler( new PanControlHandler( manip, MOVE_OFFSET, 0 ) );

//Move Reset
osg::Image* moveResetImg = osgDB::readImageFile( imgDir + "/move-reset.png" );
Expand All @@ -348,12 +348,12 @@ void GlobePlugin::setupControls()
//Move Up
osg::Image* moveUpImg = osgDB::readImageFile( imgDir + "/move-up.png" );
ImageControl* moveUp = new NavigationControl( moveUpImg );
moveUp->addEventHandler( new PanControlHandler( manip, 0, -0.05 ) );
moveUp->addEventHandler( new PanControlHandler( manip, 0, MOVE_OFFSET ) );

//Move Down
osg::Image* moveDownImg = osgDB::readImageFile( imgDir + "/move-down.png" );
ImageControl* moveDown = new NavigationControl( moveDownImg );
moveDown->addEventHandler( new PanControlHandler( manip, 0, 0.05 ) );
moveDown->addEventHandler( new PanControlHandler( manip, 0, -MOVE_OFFSET ) );

//add controls to moveControls group
moveHControls->addControl( moveLeft );
Expand All @@ -378,12 +378,12 @@ void GlobePlugin::setupControls()
//Rotate CCW
osg::Image* rotateCCWImg = osgDB::readImageFile( imgDir + "/rotate-ccw.png" );
ImageControl* rotateCCW = new NavigationControl( rotateCCWImg );
rotateCCW->addEventHandler( new RotateControlHandler( manip, 0.05, 0) );
rotateCCW->addEventHandler( new RotateControlHandler( manip, MOVE_OFFSET, 0) );

//Rotate CW
osg::Image* rotateCWImg = osgDB::readImageFile( imgDir + "/rotate-cw.png" );
ImageControl* rotateCW = new NavigationControl( rotateCWImg );
rotateCW->addEventHandler( new RotateControlHandler( manip, -0.05 , 0 ) );
rotateCW->addEventHandler( new RotateControlHandler( manip, -MOVE_OFFSET , 0 ) );

//Rotate Reset
osg::Image* rotateResetImg = osgDB::readImageFile( imgDir + "/rotate-reset.png" );
Expand Down Expand Up @@ -411,12 +411,12 @@ void GlobePlugin::setupControls()
//tilt Up
osg::Image* tiltUpImg = osgDB::readImageFile( imgDir + "/tilt-up.png" );
ImageControl* tiltUp = new NavigationControl( tiltUpImg );
tiltUp->addEventHandler( new RotateControlHandler( manip, 0, 0.05 ) );
tiltUp->addEventHandler( new RotateControlHandler( manip, 0, MOVE_OFFSET ) );

//tilt Down
osg::Image* tiltDownImg = osgDB::readImageFile( imgDir + "/tilt-down.png" );
ImageControl* tiltDown = new NavigationControl( tiltDownImg );
tiltDown->addEventHandler( new RotateControlHandler( manip, 0, -0.05 ) );
tiltDown->addEventHandler( new RotateControlHandler( manip, 0, -MOVE_OFFSET ) );

//add controls to tiltControls group
tiltControls->addControl( tiltUp );
Expand All @@ -438,12 +438,12 @@ void GlobePlugin::setupControls()
//Zoom In
osg::Image* zoomInImg = osgDB::readImageFile( imgDir + "/zoom-in.png" );
ImageControl* zoomIn = new NavigationControl( zoomInImg );
zoomIn->addEventHandler( new ZoomControlHandler( manip, 0, -0.05 ) );
zoomIn->addEventHandler( new ZoomControlHandler( manip, 0, -MOVE_OFFSET ) );

//Zoom Out
osg::Image* zoomOutImg = osgDB::readImageFile( imgDir + "/zoom-out.png" );
ImageControl* zoomOut = new NavigationControl( zoomOutImg );
zoomOut->addEventHandler( new ZoomControlHandler( manip, 0, 0.05 ) );
zoomOut->addEventHandler( new ZoomControlHandler( manip, 0, MOVE_OFFSET ) );

//Zoom Reset
osg::Image* zoomResetImg = osgDB::readImageFile( imgDir + "/zoom-reset.png" );
Expand Down Expand Up @@ -578,6 +578,8 @@ void GlobePlugin::copyFolder(QString sourceFolder, QString destFolder)
}
}

// ----------

bool FlyToExtentHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '1' )
Expand All @@ -589,7 +591,10 @@ bool FlyToExtentHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIAct
return false;
}

bool NavigationControl::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx )
// ----------

bool
NavigationControl::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx )
{
switch ( ea.getEventType() )
{
Expand Down Expand Up @@ -671,46 +676,46 @@ bool KeyboardControlHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GU
//move map
if (ea.getKey() == '4' )
{
_manip->pan( -0.05, 0 );
_manip->pan( -MOVE_OFFSET, 0 );
}
if (ea.getKey() == '6' )
{
_manip->pan( 0.05, 0 );
_manip->pan( MOVE_OFFSET, 0 );
}
if (ea.getKey() == '2' )
{
_manip->pan( 0, 0.05 );
_manip->pan( 0, MOVE_OFFSET );
}
if (ea.getKey() == '8' )
{
_manip->pan( 0, -0.05 );
_manip->pan( 0, -MOVE_OFFSET );
}
//rotate
if (ea.getKey() == '/' )
{
_manip->rotate( 0.05, 0 );
_manip->rotate( MOVE_OFFSET, 0 );
}
if (ea.getKey() == '*' )
{
_manip->rotate( -0.05, 0 );
_manip->rotate( -MOVE_OFFSET, 0 );
}
//tilt
if ( ea.getKey() == '9' )
{
_manip->rotate( 0, 0.05 );
_manip->rotate( 0, MOVE_OFFSET );
}
if (ea.getKey() == '3' )
{
_manip->rotate( 0, -0.05 );
_manip->rotate( 0, -MOVE_OFFSET );
}
//zoom
if (ea.getKey() == '-' )
{
_manip->zoom( 0, 0.05 );
_manip->zoom( 0, MOVE_OFFSET );
}
if (ea.getKey() == '+' )
{
_manip->zoom( 0, -0.05 );
_manip->zoom( 0, -MOVE_OFFSET );
}
//reset
if (ea.getKey() == '5' )
Expand Down
42 changes: 22 additions & 20 deletions src/plugins/globe/globe_plugin.h
Expand Up @@ -138,26 +138,28 @@ class KeyboardControlHandler : public osgGA::GUIEventHandler
QgisInterface *mQGisIface;
};

namespace osgEarthUtil { namespace Controls2
{
class NavigationControlHandler : public ControlEventHandler
{
public:
virtual void onMouseDown( class Control* control, int mouseButtonMask ) { }
};

class NavigationControl : public ImageControl
{
public:
NavigationControl( osg::Image* image = 0L ) : ImageControl( image ), _mouse_down_event( NULL ) {}

protected:
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx );

private:
osg::ref_ptr<const osgGA::GUIEventAdapter> _mouse_down_event;
};
}
namespace osgEarthUtil
{
namespace Controls2
{
class NavigationControlHandler : public ControlEventHandler
{
public:
virtual void onMouseDown( class Control* control, int mouseButtonMask ) { }
};

class NavigationControl : public ImageControl
{
public:
NavigationControl( osg::Image* image = 0L ) : ImageControl( image ), _mouse_down_event( NULL ) {}

protected:
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx );

private:
osg::ref_ptr<const osgGA::GUIEventAdapter> _mouse_down_event;
};
}
}

#endif // QGS_GLOBE_PLUGIN_H
59 changes: 56 additions & 3 deletions src/plugins/globe/globe_plugin_dialog.cpp
Expand Up @@ -166,6 +166,8 @@ void QgsGlobePluginDialog::on_buttonBox_accepted()

void QgsGlobePluginDialog::on_buttonBox_rejected()
{
loadStereoConfig();
setStereoConfig();
reject();
}

Expand All @@ -183,6 +185,53 @@ void QgsGlobePluginDialog::on_resetDefaults_clicked()
splitStereoVerticalEyeMapping->setCurrentIndex( 0 );
}

void QgsGlobePluginDialog::on_comboStereoMode_currentIndexChanged(QString value)
{
setStereoMode();
}

void QgsGlobePluginDialog::on_eyeSeparation_valueChanged(double value)
{
osg::DisplaySettings::instance()->setEyeSeparation( value );
}

void QgsGlobePluginDialog::on_screenDistance_valueChanged(double value)
{
osg::DisplaySettings::instance()->setScreenDistance( value );
}

void QgsGlobePluginDialog::on_screenWidth_valueChanged(double value)
{
osg::DisplaySettings::instance()->setScreenWidth( value );
}

void QgsGlobePluginDialog::on_screenHeight_valueChanged(double value)
{
osg::DisplaySettings::instance()->setScreenHeight( value );
}

void QgsGlobePluginDialog::on_splitStereoHorizontalSeparation_valueChanged(int value)
{
osg::DisplaySettings::instance()->setSplitStereoHorizontalSeparation( value );
}

void QgsGlobePluginDialog::on_splitStereoVerticalSeparation_valueChanged(int value)
{
osg::DisplaySettings::instance()->setSplitStereoVerticalSeparation( value );
}

void QgsGlobePluginDialog::on_splitStereoHorizontalEyeMapping_currentIndexChanged(int value)
{
osg::DisplaySettings::instance()->setSplitStereoHorizontalEyeMapping(
(osg::DisplaySettings::SplitStereoHorizontalEyeMapping) value );
}

void QgsGlobePluginDialog::on_splitStereoVerticalEyeMapping_currentIndexChanged(int value)
{
osg::DisplaySettings::instance()->setSplitStereoVerticalEyeMapping(
(osg::DisplaySettings::SplitStereoVerticalEyeMapping) value );
}

void QgsGlobePluginDialog::showMessageBox( QString text )
{
QMessageBox msgBox;
Expand Down Expand Up @@ -214,9 +263,9 @@ void QgsGlobePluginDialog::loadStereoConfig()
osg::DisplaySettings::instance()->getSplitStereoVerticalEyeMapping() ).toInt() );
}

void QgsGlobePluginDialog::setStereoConfig()
void QgsGlobePluginDialog::setStereoMode()
{
//http://www.openscenegraph.org/projects/osg/wiki/Support/UserGuides/StereoSettings
//http://www.openscenegraph.org/projects/osg/wiki/Support/UserGuides/StereoSettings
//http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00181.html

QString stereoMode = comboStereoMode->currentText() ;
Expand Down Expand Up @@ -252,8 +301,12 @@ void QgsGlobePluginDialog::setStereoConfig()
msgBox.exec();
}
}

}

void QgsGlobePluginDialog::setStereoConfig()
{
//SETTING THE VALUES IN THE OEGearth instance
setStereoMode();
osg::DisplaySettings::instance()->setScreenDistance( screenDistance->value() );
osg::DisplaySettings::instance()->setScreenWidth( screenWidth->value() );
osg::DisplaySettings::instance()->setScreenHeight( screenHeight->value() );
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/globe/globe_plugin_dialog.h
Expand Up @@ -44,10 +44,23 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa
void loadStereoConfig();
//! Save settings
void saveStereoConfig();
//! Handle stereoMode
void setStereoMode();

private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();

void on_comboStereoMode_currentIndexChanged(QString value);
void on_eyeSeparation_valueChanged(double value);
void on_screenDistance_valueChanged(double value);
void on_screenWidth_valueChanged(double value);
void on_screenHeight_valueChanged(double value);
void on_splitStereoHorizontalSeparation_valueChanged(int value);
void on_splitStereoVerticalSeparation_valueChanged(int value);
void on_splitStereoHorizontalEyeMapping_currentIndexChanged(int value);
void on_splitStereoVerticalEyeMapping_currentIndexChanged(int value);

void on_resetDefaults_clicked();
};

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/globe/globe_plugin_dialog_guibase.ui
Expand Up @@ -34,7 +34,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="elevation">
<attribute name="title">
Expand Down

0 comments on commit b740549

Please sign in to comment.