From f5e7443ec904bffb992e51207e4355001b841a65 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 16 Apr 2018 16:25:11 -0400 Subject: [PATCH 1/2] Fix signed distance to bounding sphere. --- Source/Scene/Camera.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 915ca86bc001..dd98dd2a8c35 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2592,7 +2592,7 @@ define([ var toCenter = Cartesian3.subtract(this.positionWC, boundingSphere.center, scratchToCenter); var distance = -Cartesian3.dot(toCenter, this.directionWC); var proj = Cartesian3.multiplyByScalar(this.directionWC, distance, scratchProj); - var unsignedDistance = Math.max(0.0, Cartesian3.magnitude(proj) - boundingSphere.radius); + var unsignedDistance = Math.abs(Cartesian3.magnitude(proj) - boundingSphere.radius); return distance < 0.0 ? -unsignedDistance : unsignedDistance; }; From 07369991f225cc6dfcee7518a2477ebc78683541 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 18 Apr 2018 16:59:10 -0400 Subject: [PATCH 2/2] Revert change to make distance to bounding sphere signed. --- CHANGES.md | 4 +--- Source/Scene/Camera.js | 16 ++++------------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 34607c3ed702..b2414c010bab 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,9 +3,6 @@ Change Log ### 1.45 - 2018-05-01 -##### Breaking Changes :mega: -* `Camera.distanceToBoundingSphere` now returns the signed distance to the bounding sphere. Positive values indicate that the bounding sphere is in the positive half-plane of the camera position and view direction while a negative value indicates it is in the negative half-plane. - ##### Additions :tada: * Added option `logDepthBuffer` to `Viewer`. With this option there is typically a single frustum using logarithmic depth rendered. This increases performance by issuing less draw calls to the GPU and helps to avoid artifacts on the connection of two frustums. [#5851](https://github.com/AnalyticalGraphicsInc/cesium/pull/5851) * When a log depth buffer is supported, the frustum near and far planes default to `0.1` and `1e10` respectively. @@ -20,6 +17,7 @@ Change Log * Fix Firefox WebGL console warnings. [#5912](https://github.com/AnalyticalGraphicsInc/cesium/issues/5912) * Fix parsing Cesium.js in older browsers that do not support all TypedArray types. [#6396](https://github.com/AnalyticalGraphicsInc/cesium/pull/6396) * Fix flicker when adding, removing, or modifiying entities. [#3945](https://github.com/AnalyticalGraphicsInc/cesium/issues/3945) + ##### Additions :tada: * Improved `MapboxImageryProvider` performance by 300% via `tiles.mapbox.com` subdomain switching. [#6426](https://github.com/AnalyticalGraphicsInc/cesium/issues/6426) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index dd98dd2a8c35..50b48178c9d3 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2574,13 +2574,10 @@ define([ var scratchProj = new Cartesian3(); /** - * Return the signed distance from the camera to the front of the bounding sphere. - *

- * Positive values indicate that the bounding sphere is in the positive half-plane of the camera position and view direction while a negative value indicates it is in the negative half-plane. - *

+ * Return the distance from the camera to the front of the bounding sphere. * * @param {BoundingSphere} boundingSphere The bounding sphere in world coordinates. - * @returns {Number} The signed distance to the bounding sphere. + * @returns {Number} The distance to the bounding sphere. */ Camera.prototype.distanceToBoundingSphere = function(boundingSphere) { //>>includeStart('debug', pragmas.debug); @@ -2590,10 +2587,8 @@ define([ //>>includeEnd('debug'); var toCenter = Cartesian3.subtract(this.positionWC, boundingSphere.center, scratchToCenter); - var distance = -Cartesian3.dot(toCenter, this.directionWC); - var proj = Cartesian3.multiplyByScalar(this.directionWC, distance, scratchProj); - var unsignedDistance = Math.abs(Cartesian3.magnitude(proj) - boundingSphere.radius); - return distance < 0.0 ? -unsignedDistance : unsignedDistance; + var proj = Cartesian3.multiplyByScalar(this.directionWC, Cartesian3.dot(toCenter, this.directionWC), scratchProj); + return Math.max(0.0, Cartesian3.magnitude(proj) - boundingSphere.radius); }; var scratchPixelSize = new Cartesian2(); @@ -2620,9 +2615,6 @@ define([ //>>includeEnd('debug'); var distance = this.distanceToBoundingSphere(boundingSphere); - if (distance < 0.0) { - return 0.0; - } var pixelSize = this.frustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, scratchPixelSize); return Math.max(pixelSize.x, pixelSize.y); };