Skip to content

Commit 655bd09

Browse files
Marco Bernasocchipka
Marco Bernasocchi
authored andcommitted
added tilt to gui
1 parent 0bcb334 commit 655bd09

File tree

1 file changed

+57
-114
lines changed

1 file changed

+57
-114
lines changed

src/plugins/globe/globe_plugin.cpp

+57-114
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ struct PanControlHandler : public NavigationControlHandler
118118
PanControlHandler( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip(manip), _dx(dx), _dy(dy) { }
119119
virtual void onMouseDown( Control* control, int mouseButtonMask )
120120
{
121-
OE_NOTICE << "Thank you for clicking on " << typeid(control).name() << mouseButtonMask
122-
<< std::endl;
123-
_manip->pan( _dx, _dy );
121+
_manip->pan( _dx, _dy );
124122
}
125123
private:
126124
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
@@ -163,8 +161,8 @@ void GlobePlugin::run()
163161
mRootNode->addChild( mControlCanvas );
164162
setupControls();
165163

166-
// add our controls handler
167-
viewer.addEventHandler(new ControlsHandler( manip, mQGisIface ));
164+
// add our fly-to handler
165+
viewer.addEventHandler(new FlyToExtentHandler( manip, mQGisIface ));
168166

169167
// add some stock OSG handlers:
170168
viewer.addEventHandler(new osgViewer::StatsHandler());
@@ -292,15 +290,16 @@ void GlobePlugin::setupControls()
292290
moveHControls->setHorizAlign( Control::ALIGN_CENTER );
293291
moveHControls->setPosition( 5, 35 );
294292

293+
osgEarthUtil::EarthManipulator* manip = dynamic_cast<osgEarthUtil::EarthManipulator*>(viewer.getCameraManipulator());
295294
//Move Left
296295
osg::Image* moveLeftImg = osgDB::readImageFile( imgDir + "/move-left.png" );
297296
ImageControl* moveLeft = new NavigationControl( moveLeftImg );
298-
moveLeft->addEventHandler( new MyClickHandler );
297+
moveLeft->addEventHandler( new PanControlHandler( manip, -0.05, 0 ) );
299298

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

305304
//Move Reset
306305
osg::Image* moveResetImg = osgDB::readImageFile( imgDir + "/move-reset.png" );
@@ -551,117 +550,61 @@ void GlobePlugin::copyFolder(QString sourceFolder, QString destFolder)
551550
}
552551
}
553552

554-
bool ControlsHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
553+
// ----------
554+
555+
bool FlyToExtentHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
555556
{
556557
float deg = 3.14159 / 180;
557-
/*
558-
osgEarthUtil::EarthManipulator::Settings* _manipSettings = _manip->getSettings();
559-
_manipSettings->bindKey(osgEarthUtil::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::KEY_Space);
560-
//install default action bindings:
561-
osgEarthUtil::EarthManipulator::ActionOptions options;
562-
563-
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_HOME, osgGA::GUIEventAdapter::KEY_Space );
564-
565-
_manipSettings->bindMouse( osgEarthUtil::EarthManipulator::ACTION_PAN, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON );
566-
567-
// zoom as you hold the right button:
568-
options.clear();
569-
options.add( osgEarthUtil::EarthManipulator::OPTION_CONTINUOUS, true );
570-
_manipSettings->bindMouse( osgEarthUtil::EarthManipulator::ACTION_ROTATE, osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON, 0L, options );
571-
572-
// zoom with the scroll wheel:
573-
_manipSettings->bindScroll( osgEarthUtil::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::SCROLL_DOWN );
574-
_manipSettings->bindScroll( osgEarthUtil::EarthManipulator::ACTION_ZOOM_OUT, osgGA::GUIEventAdapter::SCROLL_UP );
575-
576-
// pan around with arrow keys:
577-
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_PAN_LEFT, osgGA::GUIEventAdapter::KEY_Left );
578-
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_PAN_RIGHT, osgGA::GUIEventAdapter::KEY_Right );
579-
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_PAN_UP, osgGA::GUIEventAdapter::KEY_Up );
580-
_manipSettings->bindKey( osgEarthUtil::EarthManipulator::ACTION_PAN_DOWN, osgGA::GUIEventAdapter::KEY_Down );
581-
582-
// double click the left button to zoom in on a point:
583-
options.clear();
584-
options.add( osgEarthUtil::EarthManipulator::OPTION_GOTO_RANGE_FACTOR, 0.4 );
585-
_manipSettings->bindMouseDoubleClick( osgEarthUtil::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON, 0L, options );
586-
587-
// double click the right button (or CTRL-left button) to zoom out to a point
588-
options.clear();
589-
options.add( osgEarthUtil::EarthManipulator::OPTION_GOTO_RANGE_FACTOR, 2.5 );
590-
_manipSettings->bindMouseDoubleClick( osgEarthUtil::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON, 0L, options );
591-
_manipSettings->bindMouseDoubleClick( osgEarthUtil::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON, osgGA::GUIEventAdapter::MODKEY_CTRL, options );
592-
593-
_manipSettings->setThrowingEnabled( false );
594-
_manipSettings->setLockAzimuthWhilePanning( true );
595-
596-
_manip->applySettings(_manipSettings);
597-
598-
*/
599558

600-
switch(ea.getEventType())
559+
//this should be the way to implement this I think, but it segfaults...
560+
//TODO: put this in the correct place, here is ok for now to test
561+
//_manipSettings.bindKey(osgEarthUtil::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::KEY_Page_Up);
562+
//_manip->applySettings( _manipSettings );
563+
564+
565+
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '1' )
566+
601567
{
602-
case(osgGA::GUIEventAdapter::KEYDOWN):
603-
{
604-
if (ea.getKey() == '1' )
605-
{
606-
QgsPoint center = mQGisIface->mapCanvas()->extent().center();
607-
osgEarthUtil::Viewpoint viewpoint( osg::Vec3d( center.x(), center.y(), 0.0 ), 0.0, -90.0, 1e4 );
608-
_manip->setViewpoint( viewpoint, 4.0 );
609-
}
610-
//move map
611-
if (ea.getKey() == '4' )
612-
{
613-
_manip->pan( -0.1, 0 );
614-
}
615-
if (ea.getKey() == '6' )
616-
{
617-
_manip->pan( 0.1, 0 );
618-
}
619-
if (ea.getKey() == '2' )
620-
{
621-
_manip->pan( 0, 0.1 );
622-
}
623-
if (ea.getKey() == '8' )
624-
{
625-
_manip->pan( 0, -0.1 );
626-
}
627-
//rotate
628-
if (ea.getKey() == '/' )
629-
{
630-
_manip->rotate( 1*deg, 0 );
631-
}
632-
if (ea.getKey() == '*' )
633-
{
634-
_manip->rotate( -1*deg, 0 );
635-
}
636-
//tilt
637-
if ( ea.getKey() == '9' )
638-
{
639-
_manip->rotate( 0, 1*deg );
640-
}
641-
if (ea.getKey() == '3' )
642-
{
643-
_manip->rotate( 0, -1*deg );
644-
}
645-
//zoom
646-
if (ea.getKey() == '-' )
647-
{
648-
_manip->zoom( 0, 0.1 );
649-
}
650-
if (ea.getKey() == '+' )
651-
{
652-
_manip->zoom( 0, -0.1 );
653-
}
654-
//reset
655-
if (ea.getKey() == '5' )
656-
{
657-
//_manip->zoom( 0, 1 );
658-
}
659-
break;
660-
}
661-
662-
default:
663-
break;
568+
QgsPoint center = mQGisIface->mapCanvas()->extent().center();
569+
osgEarthUtil::Viewpoint viewpoint( osg::Vec3d( center.x(), center.y(), 0.0 ), 0.0, -90.0, 1e4 );
570+
_manip->setViewpoint( viewpoint, 4.0 );
664571
}
572+
573+
574+
/*if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '4' )
575+
{
576+
_manip->pan(-1,0);
577+
}
578+
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '6' )
579+
{
580+
_manip->pan(1,0);
581+
}
582+
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '8' )
583+
{
584+
_manip->pan(0,1);
585+
}
586+
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '2' )
587+
{
588+
_manip->pan(0,-1);
589+
}
590+
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '+' )
591+
{
592+
_manip->rotate(0,1*deg);
593+
}
594+
*/
595+
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '-' )
596+
{
597+
_manip->rotate(0,-1*deg);
598+
}
599+
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '/' )
600+
{
601+
_manip->rotate(1*deg,0);
602+
}
603+
if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() == '*' )
604+
{
605+
_manip->rotate(-1*deg,0);
606+
}
607+
665608
return false;
666609
}
667610

0 commit comments

Comments
 (0)