Skip to content

Commit

Permalink
Move globeHeight and cameraUnderground into Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed May 27, 2020
1 parent 6cd564c commit 45dfb2d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
43 changes: 33 additions & 10 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ function Scene(options) {
this._primitives = new PrimitiveCollection();
this._groundPrimitives = new PrimitiveCollection();

this._globeHeight = undefined;
this._cameraUnderground = false;

this._logDepthBuffer = context.fragmentDepth;
this._logDepthBufferDirty = true;

Expand Down Expand Up @@ -1658,6 +1661,15 @@ Object.defineProperties(Scene.prototype, {
return this._globeTranslucencyState;
},
},

/**
* @private
*/
globeHeight: {
get: function () {
return this._globeHeight;
},
},
});

/**
Expand Down Expand Up @@ -3702,18 +3714,28 @@ function callAfterRenderFunctions(scene) {
functions.length = 0;
}

function getGlobeHeight(scene) {
var globe = scene._globe;
var camera = scene.camera;
var cartographic = camera.positionCartographic;
if (defined(globe) && globe.show && defined(cartographic)) {
return globe.getHeight(cartographic);
}
return undefined;
}

function isCameraUnderground(scene) {
var camera = scene.camera;
var mode = scene._mode;
var globe = scene.globe;
var cameraController = scene._screenSpaceCameraController;
var cartographic = camera.positionCartographic;

if (
!cameraController.onMap() &&
defined(cartographic) &&
cartographic.height < 0.0
) {
if (!defined(cartographic)) {
return false;
}

if (!cameraController.onMap() && cartographic.height < 0.0) {
// The camera can go off the map while in Columbus View.
// Make a best guess as to whether it's underground by checking if its height is less than zero.
return true;
Expand All @@ -3728,7 +3750,8 @@ function isCameraUnderground(scene) {
return false;
}

return cameraController.isCameraUnderground(camera);
var globeHeight = scene._globeHeight;
return defined(globeHeight) && cartographic.height < globeHeight;
}

/**
Expand All @@ -3744,17 +3767,17 @@ Scene.prototype.initializeFrame = function () {

this._tweens.update();

this._globeHeight = getGlobeHeight(this);
this._cameraUnderground = isCameraUnderground(this);
this._globeTranslucencyState.update(this);

this._screenSpaceCameraController.update();
if (defined(this._deviceOrientationCameraController)) {
this._deviceOrientationCameraController.update();
}

this.camera.update(this._mode);
this.camera._updateCameraChanged();

this._cameraUnderground = isCameraUnderground(this);

this._globeTranslucencyState.update(this);
};

function updateDebugShowFramesPerSecond(scene, renderedThisFrame) {
Expand Down
29 changes: 4 additions & 25 deletions Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ function ScreenSpaceCameraController(scene) {
this._zoomingOnVector = false;
this._rotatingZoom = false;
this._adjustedHeightForTerrain = false;
this._globeHeight = undefined;
this._cameraUnderground = false;

var projection = scene.mapProjection;
Expand Down Expand Up @@ -307,19 +306,6 @@ function ScreenSpaceCameraController(scene) {
this._undergroundSurfaceHeight = -20000.0;
}

/**
* @private
*/
ScreenSpaceCameraController.prototype.isCameraUnderground = function (camera) {
var globeHeight = this._globeHeight;
var cartographic = camera.positionCartographic;
return (
defined(globeHeight) &&
defined(cartographic) &&
cartographic.height < globeHeight
);
};

function decay(time, coefficient) {
if (time < 0) {
return 0.0;
Expand Down Expand Up @@ -1135,7 +1121,7 @@ var scratchSurfaceNormal = new Cartesian3();
function getZoomDistanceUnderground(controller, ray, height) {
var origin = ray.origin;
var direction = ray.direction;
var globeHeight = defaultValue(controller._globeHeight, 0.0);
var globeHeight = defaultValue(controller._scene.globeHeight, 0.0);
var distanceFromSurface = Math.abs(height - globeHeight);
var distanceFromUndergroundSurface = Math.abs(
height - controller._undergroundSurfaceHeight
Expand Down Expand Up @@ -1203,7 +1189,7 @@ function getHeight(controller) {

function getDistanceFromClosestSurface(controller) {
var height = getHeight(controller);
var globeHeight = defaultValue(controller._globeHeight, 0.0);
var globeHeight = defaultValue(controller._scene.globeHeight, 0.0);
var distanceFromSurface = Math.abs(height - globeHeight);
var distanceFromUndergroundSurface = Math.abs(
height - controller._undergroundSurfaceHeight
Expand Down Expand Up @@ -2816,7 +2802,7 @@ function adjustHeightForTerrain(controller) {

var heightUpdated = false;
if (cartographic.height < controller._minimumCollisionTerrainHeight) {
var globeHeight = controller._globeHeight;
var globeHeight = controller._scene.globeHeight;
if (defined(globeHeight)) {
var height = globeHeight + controller.minimumZoomDistance;
if (cartographic.height < height) {
Expand Down Expand Up @@ -2878,12 +2864,6 @@ ScreenSpaceCameraController.prototype.update = function () {
var globe = scene.globe;
var mode = scene.mode;

var cartographic = camera.positionCartographic;
this._globeHeight = undefined;
if (defined(globe) && globe.show) {
this._globeHeight = globe.getHeight(cartographic);
}

if (!Matrix4.equals(camera.transform, Matrix4.IDENTITY)) {
this._globe = undefined;
this._ellipsoid = Ellipsoid.UNIT_SPHERE;
Expand All @@ -2894,8 +2874,7 @@ ScreenSpaceCameraController.prototype.update = function () {
: scene.mapProjection.ellipsoid;
}

this._cameraUnderground =
this.isCameraUnderground(camera) && defined(this._globe);
this._cameraUnderground = scene.cameraUnderground && defined(this._globe);

this._minimumCollisionTerrainHeight =
this.minimumCollisionTerrainHeight * scene.terrainExaggeration;
Expand Down

0 comments on commit 45dfb2d

Please sign in to comment.