Skip to content

Commit 0a45bff

Browse files
Marco Bernasocchipka
Marco Bernasocchi
authored andcommitted
added GUI navigation, reset buttons still missing
1 parent 9dcb832 commit 0a45bff

File tree

1 file changed

+56
-29
lines changed

1 file changed

+56
-29
lines changed

src/plugins/globe/globe_plugin.cpp

+56-29
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,32 @@ struct PanControlHandler : public NavigationControlHandler
275275
double _dy;
276276
};
277277

278+
struct RotateControlHandler : public NavigationControlHandler
279+
{
280+
RotateControlHandler( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip(manip), _dx(dx), _dy(dy) { }
281+
virtual void onMouseDown( Control* control, int mouseButtonMask )
282+
{
283+
_manip->rotate( _dx, _dy );
284+
}
285+
private:
286+
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
287+
double _dx;
288+
double _dy;
289+
};
290+
291+
struct ZoomControlHandler : public NavigationControlHandler
292+
{
293+
ZoomControlHandler( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip(manip), _dx(dx), _dy(dy) { }
294+
virtual void onMouseDown( Control* control, int mouseButtonMask )
295+
{
296+
_manip->zoom( _dx, _dy );
297+
}
298+
private:
299+
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
300+
double _dx;
301+
double _dy;
302+
};
303+
278304
void GlobePlugin::setupControls()
279305
{
280306

@@ -292,6 +318,7 @@ void GlobePlugin::setupControls()
292318
moveHControls->setPosition( 5, 35 );
293319

294320
osgEarthUtil::EarthManipulator* manip = dynamic_cast<osgEarthUtil::EarthManipulator*>(viewer.getCameraManipulator());
321+
295322
//Move Left
296323
osg::Image* moveLeftImg = osgDB::readImageFile( imgDir + "/move-left.png" );
297324
ImageControl* moveLeft = new NavigationControl( moveLeftImg );
@@ -321,12 +348,12 @@ void GlobePlugin::setupControls()
321348
//Move Up
322349
osg::Image* moveUpImg = osgDB::readImageFile( imgDir + "/move-up.png" );
323350
ImageControl* moveUp = new NavigationControl( moveUpImg );
324-
moveUp->addEventHandler( new PanControlHandler( manip, 0, 0.05 ) );
351+
moveUp->addEventHandler( new PanControlHandler( manip, 0, -0.05 ) );
325352

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

331358
//add controls to moveControls group
332359
moveHControls->addControl( moveLeft );
@@ -350,18 +377,18 @@ void GlobePlugin::setupControls()
350377

351378
//Rotate CCW
352379
osg::Image* rotateCCWImg = osgDB::readImageFile( imgDir + "/rotate-ccw.png" );
353-
ImageControl* rotateCCW = new ImageControl( rotateCCWImg );
354-
rotateCCW->addEventHandler( new MyClickHandler );
380+
ImageControl* rotateCCW = new NavigationControl( rotateCCWImg );
381+
rotateCCW->addEventHandler( new RotateControlHandler( manip, 0.05, 0) );
355382

356383
//Rotate CW
357384
osg::Image* rotateCWImg = osgDB::readImageFile( imgDir + "/rotate-cw.png" );
358-
ImageControl* rotateCW = new ImageControl( rotateCWImg );
359-
rotateCW->addEventHandler( new MyClickHandler );
385+
ImageControl* rotateCW = new NavigationControl( rotateCWImg );
386+
rotateCW->addEventHandler( new RotateControlHandler( manip, -0.05 , 0 ) );
360387

361388
//Rotate Reset
362389
osg::Image* rotateResetImg = osgDB::readImageFile( imgDir + "/rotate-reset.png" );
363-
ImageControl* rotateReset = new ImageControl( rotateResetImg );
364-
rotateReset->addEventHandler( new MyClickHandler );
390+
ImageControl* rotateReset = new NavigationControl( rotateResetImg );
391+
rotateReset->addEventHandler( new RotateControlHandler( manip, 0, 0 ) );
365392

366393
//add controls to moveControls group
367394
rotateControls->addControl( rotateCCW );
@@ -383,13 +410,13 @@ void GlobePlugin::setupControls()
383410

384411
//tilt Up
385412
osg::Image* tiltUpImg = osgDB::readImageFile( imgDir + "/tilt-up.png" );
386-
ImageControl* tiltUp = new ImageControl( tiltUpImg );
387-
tiltUp->addEventHandler( new MyClickHandler );
413+
ImageControl* tiltUp = new NavigationControl( tiltUpImg );
414+
tiltUp->addEventHandler( new RotateControlHandler( manip, 0, 0.05 ) );
388415

389416
//tilt Down
390417
osg::Image* tiltDownImg = osgDB::readImageFile( imgDir + "/tilt-down.png" );
391-
ImageControl* tiltDown = new ImageControl( tiltDownImg );
392-
tiltDown->addEventHandler( new MyClickHandler );
418+
ImageControl* tiltDown = new NavigationControl( tiltDownImg );
419+
tiltDown->addEventHandler( new RotateControlHandler( manip, 0, -0.05 ) );
393420

394421
//add controls to tiltControls group
395422
tiltControls->addControl( tiltUp );
@@ -410,18 +437,18 @@ void GlobePlugin::setupControls()
410437

411438
//Zoom In
412439
osg::Image* zoomInImg = osgDB::readImageFile( imgDir + "/zoom-in.png" );
413-
ImageControl* zoomIn = new ImageControl( zoomInImg );
414-
zoomIn->addEventHandler( new MyClickHandler );
440+
ImageControl* zoomIn = new NavigationControl( zoomInImg );
441+
zoomIn->addEventHandler( new ZoomControlHandler( manip, 0, -0.05 ) );
415442

416443
//Zoom Out
417444
osg::Image* zoomOutImg = osgDB::readImageFile( imgDir + "/zoom-out.png" );
418-
ImageControl* zoomOut = new ImageControl( zoomOutImg );
419-
zoomOut->addEventHandler( new MyClickHandler );
445+
ImageControl* zoomOut = new NavigationControl( zoomOutImg );
446+
zoomOut->addEventHandler( new ZoomControlHandler( manip, 0, 0.05 ) );
420447

421448
//Zoom Reset
422449
osg::Image* zoomResetImg = osgDB::readImageFile( imgDir + "/zoom-reset.png" );
423-
ImageControl* zoomReset = new ImageControl( zoomResetImg );
424-
zoomReset->addEventHandler( new MyClickHandler );
450+
ImageControl* zoomReset = new NavigationControl( zoomResetImg );
451+
zoomReset->addEventHandler( new ZoomControlHandler( manip, 0, 0 ) );
425452

426453
//add controls to zoomControls group
427454
zoomControls->addControl( zoomIn );
@@ -644,51 +671,51 @@ bool KeyboardControlHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GU
644671
//move map
645672
if (ea.getKey() == '4' )
646673
{
647-
_manip->pan( -0.1, 0 );
674+
_manip->pan( -0.05, 0 );
648675
}
649676
if (ea.getKey() == '6' )
650677
{
651-
_manip->pan( 0.1, 0 );
678+
_manip->pan( 0.05, 0 );
652679
}
653680
if (ea.getKey() == '2' )
654681
{
655-
_manip->pan( 0, 0.1 );
682+
_manip->pan( 0, 0.05 );
656683
}
657684
if (ea.getKey() == '8' )
658685
{
659-
_manip->pan( 0, -0.1 );
686+
_manip->pan( 0, -0.05 );
660687
}
661688
//rotate
662689
if (ea.getKey() == '/' )
663690
{
664-
_manip->rotate( 1*deg, 0 );
691+
_manip->rotate( 0.05, 0 );
665692
}
666693
if (ea.getKey() == '*' )
667694
{
668-
_manip->rotate( -1*deg, 0 );
695+
_manip->rotate( -0.05, 0 );
669696
}
670697
//tilt
671698
if ( ea.getKey() == '9' )
672699
{
673-
_manip->rotate( 0, 1*deg );
700+
_manip->rotate( 0, 0.05 );
674701
}
675702
if (ea.getKey() == '3' )
676703
{
677-
_manip->rotate( 0, -1*deg );
704+
_manip->rotate( 0, -0.05 );
678705
}
679706
//zoom
680707
if (ea.getKey() == '-' )
681708
{
682-
_manip->zoom( 0, 0.1 );
709+
_manip->zoom( 0, 0.05 );
683710
}
684711
if (ea.getKey() == '+' )
685712
{
686-
_manip->zoom( 0, -0.1 );
713+
_manip->zoom( 0, -0.05 );
687714
}
688715
//reset
689716
if (ea.getKey() == '5' )
690717
{
691-
//_manip->zoom( 0, 1 );
718+
//_manip->zoom( 0, 0 );
692719
}
693720
break;
694721
}

0 commit comments

Comments
 (0)