@@ -275,6 +275,32 @@ struct PanControlHandler : public NavigationControlHandler
275
275
double _dy;
276
276
};
277
277
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
+
278
304
void GlobePlugin::setupControls ()
279
305
{
280
306
@@ -292,6 +318,7 @@ void GlobePlugin::setupControls()
292
318
moveHControls->setPosition ( 5 , 35 );
293
319
294
320
osgEarthUtil::EarthManipulator* manip = dynamic_cast <osgEarthUtil::EarthManipulator*>(viewer.getCameraManipulator ());
321
+
295
322
// Move Left
296
323
osg::Image* moveLeftImg = osgDB::readImageFile ( imgDir + " /move-left.png" );
297
324
ImageControl* moveLeft = new NavigationControl ( moveLeftImg );
@@ -321,12 +348,12 @@ void GlobePlugin::setupControls()
321
348
// Move Up
322
349
osg::Image* moveUpImg = osgDB::readImageFile ( imgDir + " /move-up.png" );
323
350
ImageControl* moveUp = new NavigationControl ( moveUpImg );
324
- moveUp->addEventHandler ( new PanControlHandler ( manip, 0 , 0.05 ) );
351
+ moveUp->addEventHandler ( new PanControlHandler ( manip, 0 , - 0.05 ) );
325
352
326
353
// Move Down
327
354
osg::Image* moveDownImg = osgDB::readImageFile ( imgDir + " /move-down.png" );
328
355
ImageControl* moveDown = new NavigationControl ( moveDownImg );
329
- moveDown->addEventHandler ( new PanControlHandler ( manip, 0 , - 0.05 ) );
356
+ moveDown->addEventHandler ( new PanControlHandler ( manip, 0 , 0.05 ) );
330
357
331
358
// add controls to moveControls group
332
359
moveHControls->addControl ( moveLeft );
@@ -350,18 +377,18 @@ void GlobePlugin::setupControls()
350
377
351
378
// Rotate CCW
352
379
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 ) );
355
382
356
383
// Rotate CW
357
384
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 ) );
360
387
361
388
// Rotate Reset
362
389
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 ) );
365
392
366
393
// add controls to moveControls group
367
394
rotateControls->addControl ( rotateCCW );
@@ -383,13 +410,13 @@ void GlobePlugin::setupControls()
383
410
384
411
// tilt Up
385
412
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 ) );
388
415
389
416
// tilt Down
390
417
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 ) );
393
420
394
421
// add controls to tiltControls group
395
422
tiltControls->addControl ( tiltUp );
@@ -410,18 +437,18 @@ void GlobePlugin::setupControls()
410
437
411
438
// Zoom In
412
439
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 ) );
415
442
416
443
// Zoom Out
417
444
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 ) );
420
447
421
448
// Zoom Reset
422
449
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 ) );
425
452
426
453
// add controls to zoomControls group
427
454
zoomControls->addControl ( zoomIn );
@@ -644,51 +671,51 @@ bool KeyboardControlHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GU
644
671
// move map
645
672
if (ea.getKey () == ' 4' )
646
673
{
647
- _manip->pan ( -0.1 , 0 );
674
+ _manip->pan ( -0.05 , 0 );
648
675
}
649
676
if (ea.getKey () == ' 6' )
650
677
{
651
- _manip->pan ( 0.1 , 0 );
678
+ _manip->pan ( 0.05 , 0 );
652
679
}
653
680
if (ea.getKey () == ' 2' )
654
681
{
655
- _manip->pan ( 0 , 0.1 );
682
+ _manip->pan ( 0 , 0.05 );
656
683
}
657
684
if (ea.getKey () == ' 8' )
658
685
{
659
- _manip->pan ( 0 , -0.1 );
686
+ _manip->pan ( 0 , -0.05 );
660
687
}
661
688
// rotate
662
689
if (ea.getKey () == ' /' )
663
690
{
664
- _manip->rotate ( 1 *deg , 0 );
691
+ _manip->rotate ( 0.05 , 0 );
665
692
}
666
693
if (ea.getKey () == ' *' )
667
694
{
668
- _manip->rotate ( -1 *deg , 0 );
695
+ _manip->rotate ( -0.05 , 0 );
669
696
}
670
697
// tilt
671
698
if ( ea.getKey () == ' 9' )
672
699
{
673
- _manip->rotate ( 0 , 1 *deg );
700
+ _manip->rotate ( 0 , 0.05 );
674
701
}
675
702
if (ea.getKey () == ' 3' )
676
703
{
677
- _manip->rotate ( 0 , -1 *deg );
704
+ _manip->rotate ( 0 , -0.05 );
678
705
}
679
706
// zoom
680
707
if (ea.getKey () == ' -' )
681
708
{
682
- _manip->zoom ( 0 , 0.1 );
709
+ _manip->zoom ( 0 , 0.05 );
683
710
}
684
711
if (ea.getKey () == ' +' )
685
712
{
686
- _manip->zoom ( 0 , -0.1 );
713
+ _manip->zoom ( 0 , -0.05 );
687
714
}
688
715
// reset
689
716
if (ea.getKey () == ' 5' )
690
717
{
691
- // _manip->zoom( 0, 1 );
718
+ // _manip->zoom( 0, 0 );
692
719
}
693
720
break ;
694
721
}
0 commit comments