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 signed distance to bounding sphere. #6452

Merged
merged 2 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

Expand Down
16 changes: 4 additions & 12 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2574,13 +2574,10 @@ define([
var scratchProj = new Cartesian3();

/**
* Return the signed distance from the camera to the front of the bounding sphere.
* <p>
* 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.
* </p>
* 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);
Expand All @@ -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.max(0.0, 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();
Expand All @@ -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);
};
Expand Down