getWorldCoordsUnderMouse and altitude

classic Classic list List threaded Threaded
3 messages Options
Tension Tension
Reply | Threaded
Open this post in threaded view
|

getWorldCoordsUnderMouse and altitude

Hi!

Is it possible to always return 0 as altitude of resulted GeoPoint, constructed from world coordinates from getWorldCoordsUnderMouse method if there is no elevation data under mouse?

My example:

if (mapNode->getTerrain()->getWorldCoordsUnderMouse(view, ea.getX(), ea.getY(), world)) {
    osgEarth::GeoPoint geoPoint;
    geoPoint.fromWorld(mapNode->getMapSRS(), world);
    ...
}

So in this case, if i have no elevation layers under my mouse, resulted altitude from geoPoint can vary (close to 0 if my camera is close to earth surface, but can be like -3000m if my camera is far from surface). I like to always display something like 0.0 if there is no elevation data under my mouse, not depending on camera altitude. Can i somehow achieve this?

osgEarth 3.1 + osg 3.6.5

Thanks.
2LR 2LR
Reply | Threaded
Open this post in threaded view
|

Re: getWorldCoordsUnderMouse and altitude

I'd suggest taking a look at the TerrainGUI class for inspiration, in particular, the "draw(...)" method in that class. The TerrainGUI class is found in the "src/osgEarth/ImGui" folder.

The altitude (or z) returned in your call does include elevation (if present) which is based on what is in the scenegraph at the time the query is made. This will change though as you zoom in and out and detail is paged in and out which explains the variation you're seeing in the altitude returned.

If you need to check for actual elevation under the mouse, take a look at the "_sample.get().elevation().getValue()" in the "draw(...)" method to get this information. You should be able to use that to know when to set your altitude = 0.0 if "NO_DATA_VALUE" is returned (i.e. no elevation is present).

HTH

-S

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

Re: getWorldCoordsUnderMouse and altitude

In reply to this post by Tension
Tension,

The method getWorldCoordsUnderMouse intersects the actual triangles being used to approximate the earth's surface; that is why you are seeing those negative values; they occur somewhere in the middle of a large triangle connecting "real" points.

One alternative is to call MapNode::getGeoPointUnderMouse() instead, an then calling toWorld() on the result.
Glenn Waldron / Pelican Mapping