Programmatically setting the initial viewpoint

classic Classic list List threaded Threaded
8 messages Options
MarkL MarkL
Reply | Threaded
Open this post in threaded view
|

Programmatically setting the initial viewpoint

I am attempting to programatically set the initial viewpoint of my map scene.  I configure the camera manipulator as follows:

        EarthManipulator* pManip = new EarthManipulator(arguments);
        osgEarth::Config c;
        c.add("x", -71.0);
        c.add("y", 43.0);
        c.add("z", 0.0);
        c.add("heading", 0);
        c.add("pitch", -90.0);
        pManip->setViewpoint( Viewpoint(c), 100000.0);
        widget.getOsgViewer()->setCameraManipulator( pManip);

Although there are no error messages, this appears to have no effect; when the map comes up I am at the default viewpoint.

Any insights?

Thanks,
Mark
Mark
MarkL MarkL
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically setting the initial viewpoint

I made the following corrections; this now corresponds to the settings for the viewpoint I had defined in the .earth file, which gave me the desired view when I selected it.

        EarthManipulator* pManip = new EarthManipulator(arguments);
        osgEarth::Config c;
        c.add("x", -71.0);
        c.add("y", 43.0);
        c.add("z", 100000.0);
        c.add("heading", 0);
        c.add("pitch", -90.0);
        pManip->setViewpoint( Viewpoint(c), 0.0);
        widget.getOsgViewer()->setCameraManipulator( pManip);

Unfortunately, still no effect; I am at the default viewpoint.
Mark
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically setting the initial viewpoint

Mark,
Refer to the osgearth_city example, which sets a viewpoint after installing the manipulator and before starting the frame loop.

Also, avoid using Config directly -- use the API whenever possible.

Hope this helps!
Glenn Waldron / Pelican Mapping
MarkL MarkL
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically setting the initial viewpoint

Hi Glenn,

Will do.

I appreciate the rapid response!

Many thanks,
Mark
Mark
MarkL MarkL
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically setting the initial viewpoint

In reply to this post by gwaldron
Hi Glenn,

Unfortunately that didn't work.

I should have mentioned that this is a Qt5 app.  Are you aware of any Qt considerations that would affect the viewpoint settings in osgEarth?

Thanks,
Mark
Mark
MarkL MarkL
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically setting the initial viewpoint

In reply to this post by gwaldron
Incidentally, when I built and executed the osgearth_city example, the scene came up in the default view (full globe); it did not come up in the viewpoint.
Mark
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically setting the initial viewpoint

I am not.

Does it work in the city demo? Or are you saying the technique didn't work in your app.
Glenn Waldron / Pelican Mapping
MarkL MarkL
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically setting the initial viewpoint

In reply to this post by MarkL
Calling the setHomeViewpoint function instead of setViewpoint fixed the problem.
Mark