Skip to content

Commit

Permalink
fix Globe.getHeight function
Browse files Browse the repository at this point in the history
better handling of under ellipsoid surface terrain
  • Loading branch information
duvifn committed Nov 7, 2016
1 parent ead79f4 commit 9f7d911
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 10 additions & 1 deletion Source/Scene/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,16 @@ define([
var cartesian = ellipsoid.cartographicToCartesian(cartographic, scratchGetHeightCartesian);

var ray = scratchGetHeightRay;
Cartesian3.normalize(cartesian, ray.direction);
var surfaceNormal = ellipsoid.geodeticSurfaceNormal(cartesian, ray.direction);

// compute origin point, to account for a case where the terrain is under ellipsoid surface
var minimumHeight = Math.min(defaultValue(tile.data.minimumHeight, 0.0), 0.0);

// take into account the position height
minimumHeight -= cartographic.height;

var minimumHeightVector = Cartesian3.multiplyByScalar(surfaceNormal, minimumHeight - 1.0, scratchGetHeightIntersection);
Cartesian3.add(cartesian, minimumHeightVector, ray.origin);

var intersection = tile.data.pick(ray, undefined, undefined, false, scratchGetHeightIntersection);
if (!defined(intersection)) {
Expand Down
12 changes: 9 additions & 3 deletions Source/Scene/QuadtreePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,15 @@ define([

if (mode === SceneMode.SCENE3D) {
var surfaceNormal = ellipsoid.geodeticSurfaceNormal(data.position, scratchRay.direction);
// subtract by earth minor axis radius, to account for a case where the terrain is under ellipsoid surface - is that OK or should I use lower value (maybe -11500.0 which appears some lines bellow)?
var radiusLengthVector = Cartesian3.multiplyByScalar(surfaceNormal, ellipsoid.minimumRadius, scratchPosition);
Cartesian3.subtract(data.position, radiusLengthVector, scratchRay.origin);

// compute origin point, to account for a case where the terrain is under ellipsoid surface
var minimumHeight = Math.min(defaultValue(tile.data.minimumHeight, 0.0), 0.0);

// take into account the position height
minimumHeight -= data.positionCartographic.height;

var minimumHeightVector = Cartesian3.multiplyByScalar(surfaceNormal, minimumHeight - 1.0, scratchPosition);
Cartesian3.add(data.position, minimumHeightVector, scratchRay.origin);
} else {
Cartographic.clone(data.positionCartographic, scratchCartographic);

Expand Down

0 comments on commit 9f7d911

Please sign in to comment.