Skip to content

Commit a256f7f

Browse files
committed
cartesian is computed on the ellipsoid surface
1 parent 306c276 commit a256f7f

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

Source/Scene/Globe.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,9 @@ define([
426426
}
427427

428428
var ellipsoid = this._surface._tileProvider.tilingScheme.ellipsoid;
429-
var cartesian = ellipsoid.cartographicToCartesian(cartographic, scratchGetHeightCartesian);
429+
430+
//cartesian has to be on the ellipsoid surface for `ellipsoid.geodeticSurfaceNormal`
431+
var cartesian = Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0, ellipsoid, scratchGetHeightCartesian);
430432

431433
var ray = scratchGetHeightRay;
432434
var surfaceNormal = ellipsoid.geodeticSurfaceNormal(cartesian, ray.direction);
@@ -445,7 +447,7 @@ define([
445447
} else if (Math.abs(surfaceNormal.y) > CesiumMath.EPSILON16){
446448
magnitude = cartesian.y / surfaceNormal.y;
447449
} else if (Math.abs(surfaceNormal.z) > CesiumMath.EPSILON16){ //surface normal is (0,0,1) | (0,0,-1) | (0,0,0)
448-
magnitude = cartesian.z / surfaceNormal.z;
450+
magnitude = cartesian.z / surfaceNormal.z; //we could use 'cartezian.z' but we want the correct sign
449451
} else { //(0,0,0), just for case
450452
magnitude = 0;
451453
}
@@ -458,9 +460,6 @@ define([
458460
// intersection point is outside the ellipsoid, try other value
459461
magnitude = Math.min(defaultValue(tile.data.minimumHeight, 0.0),-11500.0);
460462

461-
// take into account the position height
462-
magnitude -= cartographic.height;
463-
464463
// multiply by the *positive* value of the magnitude
465464
vectorToMinimumPoint = Cartesian3.multiplyByScalar(surfaceNormal, Math.abs(magnitude) + 1, scratchGetHeightIntersection);
466465
Cartesian3.subtract(cartesian, vectorToMinimumPoint, ray.origin);

Source/Scene/QuadtreePrimitive.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ define([
240240
QuadtreePrimitive.prototype.updateHeight = function(cartographic, callback) {
241241
var primitive = this;
242242
var object = {
243-
position : undefined,
243+
positionOnEllipsoidSurface : undefined,
244244
positionCartographic : cartographic,
245245
level : -1,
246246
callback : callback
@@ -455,7 +455,7 @@ define([
455455
customDataRemoved.length = 0;
456456
}
457457

458-
// Our goal with load ordering is to first load all of the tiles we need to
458+
// Our goal with load ordering is to first load all of the tiles we need to
459459
// render the current scene at full detail. Loading any other tiles is just
460460
// a form of prefetching, and we need not do it at all (other concerns aside). This
461461
// simple and obvious statement gets more complicated when we realize that, because
@@ -761,12 +761,13 @@ define([
761761
var data = customData[i];
762762

763763
if (tile.level > data.level) {
764-
if (!defined(data.position)) {
765-
data.position = ellipsoid.cartographicToCartesian(data.positionCartographic);
764+
if (!defined(data.positionOnEllipsoidSurface)) {
765+
// cartesian has to be on the ellipsoid surface for `ellipsoid.geodeticSurfaceNormal`
766+
data.positionOnEllipsoidSurface = Cartesian3.fromRadians(data.positionCartographic.longitude, data.positionCartographic.latitude, 0.0, ellipsoid);
766767
}
767768

768769
if (mode === SceneMode.SCENE3D) {
769-
var surfaceNormal = ellipsoid.geodeticSurfaceNormal(data.position, scratchRay.direction);
770+
var surfaceNormal = ellipsoid.geodeticSurfaceNormal(data.positionOnEllipsoidSurface, scratchRay.direction);
770771

771772
// compute origin point
772773

@@ -778,29 +779,26 @@ define([
778779

779780
// avoid dividing by zero
780781
if (Math.abs(surfaceNormal.x) > CesiumMath.EPSILON16){
781-
magnitude = data.position.x / surfaceNormal.x;
782+
magnitude = data.positionOnEllipsoidSurface.x / surfaceNormal.x;
782783
} else if (Math.abs(surfaceNormal.y) > CesiumMath.EPSILON16){
783-
magnitude = data.position.y / surfaceNormal.y;
784+
magnitude = data.positionOnEllipsoidSurface.y / surfaceNormal.y;
784785
} else if (Math.abs(surfaceNormal.z) > CesiumMath.EPSILON16){ //surface normal is (0,0,1) | (0,0,-1) | (0,0,0)
785-
magnitude = data.position.z / surfaceNormal.z;
786+
magnitude = data.positionOnEllipsoidSurface.z / surfaceNormal.z;
786787
} else { //(0,0,0), just for case
787788
magnitude = 0;
788789
}
789790

790791
var vectorToMinimumPoint = Cartesian3.multiplyByScalar(surfaceNormal, magnitude, scratchPosition);
791-
Cartesian3.subtract(data.position, vectorToMinimumPoint, scratchRay.origin);
792+
Cartesian3.subtract(data.positionOnEllipsoidSurface, vectorToMinimumPoint, scratchRay.origin);
792793

793794
// Theoretically, the intersection point can be outside the ellipsoid, so we have to check if the result's 'z' is inside the ellipsoid (with some buffer)
794795
if (Math.abs(scratchRay.origin.z) >= ellipsoid.radii.z -11500.0){
795796
// intersection point is outside the ellipsoid, try other value
796797
magnitude = Math.min(defaultValue(tile.data.minimumHeight, 0.0),-11500.0);
797798

798-
// take into account the position height
799-
magnitude -= data.positionCartographic.height;
800-
801799
// multiply by the *positive* value of the magnitude
802800
vectorToMinimumPoint = Cartesian3.multiplyByScalar(surfaceNormal, Math.abs(magnitude) + 1, scratchPosition);
803-
Cartesian3.subtract(data.position, vectorToMinimumPoint, scratchRay.origin);
801+
Cartesian3.subtract(data.positionOnEllipsoidSurface, vectorToMinimumPoint, scratchRay.origin);
804802
}
805803

806804
} else {

0 commit comments

Comments
 (0)