Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix billboard on terrain and Globe.getHeight #4622

Merged
merged 21 commits into from
Dec 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

@duvifn duvifn Nov 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bagnell , do you think it would be safer to use lower value instead of 0.0 in defaultValue(tile.data.minimumHeight, 0.0)?
for example -11500.0 (taken from here, wikipedia)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use -11500.0. For the lowest resolution terrain tiles, triangle vertices may be near the ellipsoid surface, but the interiors cutting through the ellipsoid will drop to around this height. Is there a reason you didn't use Cartesian3.ZERO? Did you run into precision issues in the triangle intersection test?


// 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