[SOLVED] EarthManipulator :: Lock :: Map, Viewpoint, Camera?

classic Classic list List threaded Threaded
12 messages Options
kefir kefir
Reply | Threaded
Open this post in threaded view
|

[SOLVED] EarthManipulator :: Lock :: Map, Viewpoint, Camera?

This post was updated on .
Greetings!

Googling and reading examples gave me nothing so far (but I keep digging) - maybe someone here has an idea about how to lock map manipulations without completely rewriting EarthManipulator class...

I want to create feature editing mouse tools, like dragging and such... And of course while I do this I want map to stay put. To lock viewpoint or disable EarthManipulator...

I've tried simple (and totally unsafe as it seems) viewer->setCameraManipulator(nullptr) and it kinda does the job except I have not been successful in restoring the functionality afterwards.

Solution (big thanks to Tension and gwaldron):

//Following code disables map panning:
earthManipulator->getSettings()->bindMouse(EarthManipulator::ACTION_NULL, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON);

//Following code re-enables map panning:
earthManipulator->getSettings()->bindMouse(EarthManipulator::ACTION_PAN, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON);


More information on key and mouse bindings is available here!
Since ACTION_EARTH_DRAG is commented in the linked file, the proper way to re-enable panning is to use EarthManipulator::ACTION_PAN rather then EarthManipulator::ACTION_EARTH_DRAG when binding.
kefir kefir
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

Apparently holding down SHIFT key locks viewpoint (does what I need). But due to OSG's terrible forum search engine I was unable to find how to emulate key presses...
Tension Tension
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

This post was updated on .
In reply to this post by kefir
You can try something like this for each binding that you want to disable:

manip->getSettings()->bindMouseDoubleClick( EarthManipulator::ACTION_NULL, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON);

For example, this line disables LMB double-click handling.
If you want to disable all bindings, you can construct new empty settings and apply it to EarthManipulator.

But since settings class doesn't provide methods for getting actions for corresponding bindings (at least I could not find how), you can't return binding to his previous state (if you want it, after you done with your task). But you can try to save a copy of whole settings object and apply it with applySettings method later.


gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

In reply to this post by kefir
kefir,
Setting the Viewer's camera manipulator to NULL is the right way to disable the manipulator. Can you elaborate on the trouble you are having restoring the functionality?
Glenn Waldron / Pelican Mapping
kefir kefir
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

In reply to this post by Tension
Thanks, mate!

Your example code works a treat, but... code like this:
earthManipulator->getSettings()->bindMouseClick(EarthManipulator::ACTION_NULL, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON);

Which is far more crucial to my case doesn't seem to do anything. Maybe I also should 'unbind' dragging or something?
Tension Tension
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

I think it's bindMouse method for dragging.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

You can consult this code to see how all the default bindings are configured.

ACTION_PAN controls the mouse panning.
Glenn Waldron / Pelican Mapping
kefir kefir
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

This post was updated on .
In reply to this post by gwaldron
gwaldron wrote
Setting the Viewer's camera manipulator to NULL is the right way to disable the manipulator.
That's good news as it makes everything easier.

gwaldron wrote
Can you elaborate on the trouble you are having restoring the functionality?

Sure. I have this code for changing mouse tools inside a custom Qt widget that is class OSGEMapWidget : public osgQt::GLWidget

void OSGEMapWidget::setActiveMouseTool(OSGEMouseTool mt)
{
mouseTool = mt;
    switch (mouseTool)
    {
      case OSGEMouseTool::DEFAULT:
      setCursor(QCursor(Qt::ArrowCursor));
      viewer->setCameraManipulator(earthManipulator);
      break;
      case OSGEMouseTool::INFO:
      setCursor(QCursor(Qt::WhatsThisCursor));
      viewer->setCameraManipulator(nullptr);
      break;
      case OSGEMouseTool::MOVE:
      setCursor(QCursor(Qt::OpenHandCursor));
      viewer->setCameraManipulator(nullptr);
      break;
      case OSGEMouseTool::PLACE:
      setCursor(QCursor(Qt::UpArrowCursor));
      viewer->setCameraManipulator(nullptr);
      break;
    }
}


Half of the times app crashes just after selecting different mouse tool, and every time after changing it to default.
I'm now installing CDB to get crash stack... And here's the stack, crash line is in bold

osgEarth!osgEarth::Util::EarthManipulator::getViewpoint:
0x7ffa0c916620 push rbp
0x7ffa0c916622 <+ 2> push rsi
0x7ffa0c916623 <+ 3> push rdi
0x7ffa0c916624 <+ 4> push r14
0x7ffa0c916626 <+ 6> push r15
0x7ffa0c916628 <+ 8> lea rbp,[rsp-50h]
0x7ffa0c91662d <+ 13> sub rsp,150h
0x7ffa0c916634 <+ 20> mov qword ptr [rsp+38h],0FFFFFFFFFFFFFFFEh
0x7ffa0c91663d <+ 29> mov qword ptr [rsp+190h],rbx
0x7ffa0c916645 <+ 37> mov rax,qword ptr
[osgEarth!osgEarth::AnnotationSettings::_occlusionCullingMaxAltitude+0x670 (00007ffa`0cd86ad8)] 0x7ffa0c91664c <+ 44> xor rax,rsp
0x7ffa0c91664f <+ 47> mov qword ptr [rbp+48h],rax
0x7ffa0c916653 <+ 51> mov rdi,rdx
0x7ffa0c916656 <+ 54> mov rsi,rcx
0x7ffa0c916659 <+ 57> mov qword ptr [rsp+40h],rdx
0x7ffa0c91665e <+ 62> mov dword ptr [rsp+20h],0
0x7ffa0c916666 <+ 70> mov rcx,rdx
0x7ffa0c916669 <+ 73> call osgEarth!osgEarth::Viewpoint::Viewpoint (00007ffa`0c8caaf0)
0x7ffa0c91666e <+ 78> mov dword ptr [rsp+20h],1
0x7ffa0c916676 <+ 86> movzx ecx,byte ptr [rsi+1338h]
0x7ffa0c91667d <+ 93> test cl,cl
0x7ffa0c91667f <+ 95> je osgEarth!osgEarth::Util::EarthManipulator::getViewpoint+0x121 (00007ffa`0c916741)
0x7ffa0c916685 <+ 101> mov rax,qword ptr [rsi+1710h]
0x7ffa0c91668c <+ 108> test rax,rax
0x7ffa0c91668f <+ 111> je osgEarth!osgEarth::Util::EarthManipulator::getViewpoint+0x121 (00007ffa`0c916741)
0x7ffa0c916695 <+ 117> cmp qword ptr [rax+30h],0
0x7ffa0c91669a <+ 122> je osgEarth!osgEarth::Util::EarthManipulator::getViewpoint+0x121 (00007ffa`0c916741)
0x7ffa0c9166a0 <+ 128> cmp qword ptr [rsi+1718h],0
0x7ffa0c9166a8 <+ 136> je osgEarth!osgEarth::Util::EarthManipulator::getViewpoint+0x121 (00007ffa`0c916741)
0x7ffa0c9166ae <+ 142> lea rdx,[rsi+1340h]
0x7ffa0c9166b5 <+ 149> mov rcx,rdi
0x7ffa0c9166b8 <+ 152> call osgEarth!osgEarth::Viewpoint::operator= (00007ffa`0c8cae80)
0x7ffa0c9166bd <+ 157> lea rdx,[rsp+28h]
0x7ffa0c9166c2 <+ 162> mov rcx,rdi
0x7ffa0c9166c5 <+ 165> call osgEarth!osgEarth::Viewpoint::getNode (00007ffa`0c8cbe00)
0x7ffa0c9166ca <+ 170> mov rbx,qword ptr [rax]
0x7ffa0c9166cd <+ 173> mov rcx,qword ptr [rsp+28h]
0x7ffa0c9166d2 <+ 178> test rcx,rcx
0x7ffa0c9166d5 <+ 181> je osgEarth!osgEarth::Util::EarthManipulator::getViewpoint+0xbe (00007ffa`0c9166de)
0x7ffa0c9166d7 <+ 183> call qword ptr
[osgEarth!osgEarth::Support::Shaders::Shaders+0x8d538 (00007ffa`0caefda8)]
0x7ffa0c9166dd <+ 189> nop
0x7ffa0c9166de <+ 190> test rbx,rbx
0x7ffa0c9166e1 <+ 193> je osgEarth!osgEarth::Util::EarthManipulator::getViewpoint+0x10b (00007ffa`0c91672b)
0x7ffa0c9166e3 <+ 195> lea rdx,[rsp+28h]
0x7ffa0c9166e8 <+ 200> mov rcx,rdi
0x7ffa0c9166eb <+ 203> call osgEarth!osgEarth::Viewpoint::getNode (00007ffa`0c8cbe00) 0x7ffa0c9166f0 <+ 208> nop
0x7ffa0c9166f1 <+ 209> mov rdx,qword ptr [rax]
0x7ffa0c9166f4 <+ 212> mov rbx,qword ptr [rsi+0E0h]
0x7ffa0c9166fb <+ 219> mov byte ptr [rdi+58h],1
0x7ffa0c9166ff <+ 223> lea rcx,[rbp+30h]
0x7ffa0c916703 <+ 227> call osgEarth!osgEarth::Util::EarthManipulator::computeHomePosition+0x440 (00007ffa`0c913130)
0x7ffa0c916708 <+ 232> mov r8,rax
0x7ffa0c91670b <+ 235> lea rcx,[rdi+60h]
0x7ffa0c91670f <+ 239> mov rdx,rbx
0x7ffa0c916712 <+ 242> call osgEarth!osgEarth::GeoPoint::fromWorld (00007ffa`0c7b8e50)
0x7ffa0c916717 <+ 247> nop
0x7ffa0c916718 <+ 248> mov rcx,qword ptr [rsp+28h]
0x7ffa0c91671d <+ 253> test rcx,rcx
0x7ffa0c916720 <+ 256> je osgEarth!osgEarth::Util::EarthManipulator::getViewpoint+0x109 (00007ffa`0c916729)
0x7ffa0c916722 <+ 258> call qword ptr
[osgEarth!osgEarth::Support::Shaders::Shaders+0x8d538 (00007ffa`0caefda8)]
0x7ffa0c916728 <+ 264> nop
0x7ffa0c916729 <+ 265> jmp osgEarth!osgEarth::Util::EarthManipulator::getViewpoint+0x13c (00007ffa`0c91675c)
0x7ffa0c91672b <+ 267> mov byte ptr [rdi+58h],0
0x7ffa0c91672f <+ 271> lea rdx,[rdi+90h]
0x7ffa0c916736 <+ 278> lea rcx,[rdi+60h]
0x7ffa0c91673a <+ 282> call osgEarth!osgEarth::GeoPoint::operator= (00007ffa`0c719a70)
0x7ffa0c91673f <+ 287> jmp osgEarth!osgEarth::Util::EarthManipulator::getViewpoint+0x13c (00007ffa`0c91675c)
0x7ffa0c916741 <+ 289> mov rdx,qword ptr [rsi+0E0h]
0x7ffa0c916748 <+ 296> mov byte ptr [rdi+58h],1
0x7ffa0c91674c <+ 300> lea r8,[rsi+118h]
0x7ffa0c916753 <+ 307> lea rcx,[rdi+60h]
0x7ffa0c916757 <+ 311> call osgEarth!osgEarth::GeoPoint::fromWorld (00007ffa`0c7b8e50)
0x7ffa0c91675c <+ 316> lea rdx,[rsi+258h]
0x7ffa0c916763 <+ 323> lea r9,[rsp+30h]
0x7ffa0c916768 <+ 328> lea r8,[rsp+28h]
0x7ffa0c91676d <+ 333> mov rcx,rsi
0x7ffa0c916770 <+ 336> call osgEarth!osgEarth::Util::EarthManipulator::getEulerAngles (00007ffa`0c915d70)
0x7ffa0c916775 <+ 341> lea r14,[osgEarth!osgEarth::VideoLayer::`vftable'+0x530 (00007ffa`0cb3f8a0)]
0x7ffa0c91677c <+ 348> mov qword ptr [rbp-40h],r14
0x7ffa0c916780 <+ 352> movsd xmm0,mmword ptr [rsp+28h]
0x7ffa0c916786 <+ 358> movsd mmword ptr [rbp-38h],xmm0
0x7ffa0c91678b <+ 363> lea rax,[rbp-30h]
0x7ffa0c91678f <+ 367> mov qword ptr [rsp+28h],rax
0x7ffa0c916794 <+ 372> lea rdx,[osgEarth!osgEarth::Units::RADIANS (00007ffa`0cd9ccd0)]
kefir kefir
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

In reply to this post by Tension
Tension wrote
I think it's bindMouse method for dragging.
Yes you are right setting it like this:
earthManipulator->getSettings()->bindMouse(EarthManipulator::ACTION_NULL, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON);
Does the trick

And default functionality restores well by:
earthManipulator->getSettings()->bindMouse(EarthManipulator::ACTION_PAN, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON);
or
earthManipulator->getSettings()->bindMouse(EarthManipulator::ACTION_EARTH_DRAG, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON);

Which one is correct way to restore?
Tension Tension
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

kefir wrote
And default functionality restores well by:
earthManipulator->getSettings()->bindMouse(EarthManipulator::ACTION_PAN, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON);
or
earthManipulator->getSettings()->bindMouse(EarthManipulator::ACTION_EARTH_DRAG, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON);

Which one is correct way to restore?
ACTION_PAN is default for this binding. You can check configureDefaultSettings method in EarthManipulator sources for other defaults, as Glenn mentioned before.

I assume that getActionTypeForEvent method could help, but it's not implemented :)
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

Or even easier:

//save
EarthManipualator::Settings* save = new EarthManipulator::Settings(*manip->getSettings());

//restore
manip->applySettings(save);

[edit: function name]

Glenn Waldron / Pelican Mapping
kefir kefir
Reply | Threaded
Open this post in threaded view
|

Re: EarthManipulator :: Lock :: Map, Viewpoint, Camera?

gwaldron wrote
Or even easier:

//save
EarthManipualator::Settings* save = new EarthManipulator::Settings(*manip->getSettings());

//restore
manip->applySettings(save);

[edit: function name]
This doesn't seem to work. I save just after creating EarthManipulator and restore when needed but it just stays locked