I'm using Cesium for quite a long time and recently I've encountered the following problem:

When I use the method in this guide-

http://analyticalgraphicsinc.github.io/cesium-google-earth-examples/examples/groundAlt.html

and the camera is tilted, such that the camera faces the horizon, sometimes the position and ground height reported by Globe.pick differs largely from the real position/height.

After some investigation it seems that the reason is the sort method of intersecting bounding spheres used in the pick method.

Since the sort function is based on the distance, tiles of low levels are sometimes prioritized over more detailed tiles, triangles from the wrong tile are selected and therefore the wrong result is returned.

So I've rewritten the code:

1)

Instead of pushing the tileData here

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Globe.js#L395

I'm pushing the tile itself(https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Globe.js#L378) to the array,

So the new line is:

sphereIntersections.push(tile)

2)

My sort function:

function createComparePickTileFunction(rayOrigin){

return function(a,b){

// see http://stackoverflow.com/questions/4576714/sort-by-two-values-prioritizing-on-one-of-them

var n = b.level-a.level;

if (n!==0){

return n;

}

var aDist = BoundingSphere.distanceSquaredTo(a.data.pickBoundingSphere, rayOrigin);

var bDist = BoundingSphere.distanceSquaredTo(b.data.pickBoundingSphere, rayOrigin);

return aDist - bDist;

}

}

Note: we can't sort only by level because it's possible that two tiles along the ray would have the same level.

This gives more accurate results but after further reading I have some other questions, before I could rely on this solution.

I'm quite new at this, so forgive me if these are noobie questions.

A) The tile level is computed using the SSE function which in turn uses the distance to tile.

I have noticed that the camera height is used in the distance calculation

(https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/GlobeSurfaceTileProvider.js#L585)

which (correct me if I'm wrong) is (almost) accurate only if the camera is above the tile, but this is not the case with tilted views. So the distance might be not accurate when the tiles are on the horizon.

If I'm right - can I be sure that tiles on a ray would have the same or lower level as we move away from the origin?

B) The previous question can be asked again given the comment in

(page 37, or 373 in the full book)

"Technically, this equation [for SSE] is only accurate for objects in the center of

the viewport. For an object at the sides, it slightly underestimates the

true screen-space error."

So, given this comment- can I be sure that tiles on a ray would have the same or lower level as we move away from the origin?

C) I can imagine a situation when two (or more) triangles in a tile (with a front face in the opposite direction of the ray) would intersect the ray.

However, currently, only the first one is returned.

(https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/GlobeSurfaceTile.js#L224)

Is this the right behavior?

Please let me know if there is an already open issue for this case.

Thanks a lot...