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 disappearing terrain #3365

Merged
merged 4 commits into from
Dec 22, 2015
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Change Log
* Added `ModelGraphics.nodeTransformations` which is a `PropertyBag` of `TranslationRotationScale` properties to be applied to a loaded model.
* Added CZML support for new `runAnimations` and `nodeTransformations` properties on the `model` packet.
* Added a new Sandcastle example: [CZML Model - Node Transformations](http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=CZML%20Model%20-%20Node%20Transformations.html&label=CZML).
* Fix disappearing terrain while fog is active. [#3335](https://github.com/AnalyticalGraphicsInc/cesium/issues/3335)

### 1.16 - 2015-12-01

Expand Down
90 changes: 45 additions & 45 deletions Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,64 +540,64 @@ define([
*/
GlobeSurfaceTileProvider.prototype.computeDistanceToTile = function(tile, frameState) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@lilleyse we want this fix in the 3d-tiles branch TileBoundingBox class, otherwise we will reintroduce this bug when merging TileBoundingBox to master. You might want to cherry pick these commits and make the change right away.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I'll do that.

var surfaceTile = tile.data;
var camera = frameState.camera;
var cameraCartesianPosition = camera.positionWC;
var cameraCartographicPosition = camera.positionCartographic;

var southwestCornerCartesian = surfaceTile.southwestCornerCartesian;
var northeastCornerCartesian = surfaceTile.northeastCornerCartesian;
var westNormal = surfaceTile.westNormal;
var southNormal = surfaceTile.southNormal;
var eastNormal = surfaceTile.eastNormal;
var northNormal = surfaceTile.northNormal;
var maximumHeight = surfaceTile.maximumHeight;
var result = 0.0;
if (!Rectangle.contains(tile.rectangle, cameraCartographicPosition)) {
var southwestCornerCartesian = surfaceTile.southwestCornerCartesian;
var northeastCornerCartesian = surfaceTile.northeastCornerCartesian;
var westNormal = surfaceTile.westNormal;
var southNormal = surfaceTile.southNormal;
var eastNormal = surfaceTile.eastNormal;
var northNormal = surfaceTile.northNormal;

if (frameState.mode !== SceneMode.SCENE3D) {
southwestCornerCartesian = frameState.mapProjection.project(Rectangle.southwest(tile.rectangle), southwestCornerScratch);
southwestCornerCartesian.z = southwestCornerCartesian.y;
southwestCornerCartesian.y = southwestCornerCartesian.x;
southwestCornerCartesian.x = 0.0;
northeastCornerCartesian = frameState.mapProjection.project(Rectangle.northeast(tile.rectangle), northeastCornerScratch);
northeastCornerCartesian.z = northeastCornerCartesian.y;
northeastCornerCartesian.y = northeastCornerCartesian.x;
northeastCornerCartesian.x = 0.0;
westNormal = negativeUnitY;
eastNormal = Cartesian3.UNIT_Y;
southNormal = negativeUnitZ;
northNormal = Cartesian3.UNIT_Z;
maximumHeight = 0.0;
}
if (frameState.mode !== SceneMode.SCENE3D) {
southwestCornerCartesian = frameState.mapProjection.project(Rectangle.southwest(tile.rectangle), southwestCornerScratch);
southwestCornerCartesian.z = southwestCornerCartesian.y;
southwestCornerCartesian.y = southwestCornerCartesian.x;
southwestCornerCartesian.x = 0.0;
northeastCornerCartesian = frameState.mapProjection.project(Rectangle.northeast(tile.rectangle), northeastCornerScratch);
northeastCornerCartesian.z = northeastCornerCartesian.y;
northeastCornerCartesian.y = northeastCornerCartesian.x;
northeastCornerCartesian.x = 0.0;
westNormal = negativeUnitY;
eastNormal = Cartesian3.UNIT_Y;
southNormal = negativeUnitZ;
northNormal = Cartesian3.UNIT_Z;
}

var cameraCartesianPosition = frameState.camera.positionWC;
var cameraCartographicPosition = frameState.camera.positionCartographic;
var vectorFromSouthwestCorner = Cartesian3.subtract(cameraCartesianPosition, southwestCornerCartesian, vectorScratch);
var distanceToWestPlane = Cartesian3.dot(vectorFromSouthwestCorner, westNormal);
var distanceToSouthPlane = Cartesian3.dot(vectorFromSouthwestCorner, southNormal);

var vectorFromSouthwestCorner = Cartesian3.subtract(cameraCartesianPosition, southwestCornerCartesian, vectorScratch);
var distanceToWestPlane = Cartesian3.dot(vectorFromSouthwestCorner, westNormal);
var distanceToSouthPlane = Cartesian3.dot(vectorFromSouthwestCorner, southNormal);
var vectorFromNortheastCorner = Cartesian3.subtract(cameraCartesianPosition, northeastCornerCartesian, vectorScratch);
var distanceToEastPlane = Cartesian3.dot(vectorFromNortheastCorner, eastNormal);
var distanceToNorthPlane = Cartesian3.dot(vectorFromNortheastCorner, northNormal);

var vectorFromNortheastCorner = Cartesian3.subtract(cameraCartesianPosition, northeastCornerCartesian, vectorScratch);
var distanceToEastPlane = Cartesian3.dot(vectorFromNortheastCorner, eastNormal);
var distanceToNorthPlane = Cartesian3.dot(vectorFromNortheastCorner, northNormal);
if (distanceToWestPlane > 0.0) {
result += distanceToWestPlane * distanceToWestPlane;
} else if (distanceToEastPlane > 0.0) {
result += distanceToEastPlane * distanceToEastPlane;
}

if (distanceToSouthPlane > 0.0) {
result += distanceToSouthPlane * distanceToSouthPlane;
} else if (distanceToNorthPlane > 0.0) {
result += distanceToNorthPlane * distanceToNorthPlane;
}
}

var cameraHeight;
if (frameState.mode === SceneMode.SCENE3D) {
cameraHeight = cameraCartographicPosition.height;
} else {
cameraHeight = cameraCartesianPosition.x;
}
var distanceFromTop = cameraHeight - maximumHeight;

var result = 0.0;

if (distanceToWestPlane > 0.0) {
result += distanceToWestPlane * distanceToWestPlane;
} else if (distanceToEastPlane > 0.0) {
result += distanceToEastPlane * distanceToEastPlane;
}

if (distanceToSouthPlane > 0.0) {
result += distanceToSouthPlane * distanceToSouthPlane;
} else if (distanceToNorthPlane > 0.0) {
result += distanceToNorthPlane * distanceToNorthPlane;
}

var maximumHeight = frameState.mode === SceneMode.SCENE3D ? surfaceTile.maximumHeight : 0.0;
var distanceFromTop = cameraHeight - maximumHeight;
if (distanceFromTop > 0.0) {
result += distanceFromTop * distanceFromTop;
}
Expand Down
2 changes: 1 addition & 1 deletion Specs/Scene/GlobeSurfaceTileProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ defineSuite([
url : 'Data/Images/Red16x16.png'
}));

frameState.camera.setView({ destination : Rectangle.fromDegrees(1.0e7, 1.0e7, 2.5e6, 2.5e6) });
frameState.camera.setView({ destination : new Rectangle(0.0000001, 0.0000001, 0.0000025, 0.0000025) });

return pollToPromise(function() {
globe.update(frameState);
Expand Down