Skip to content

Commit 834910e

Browse files
committed
Move horizon distance calculation from WWMath to Globe.
1 parent c406f69 commit 834910e

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

src/WorldWindow.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ define([
217217
*/
218218
this.verticalExaggeration = 1;
219219

220+
/**
221+
* Distance from camera point to horizon.
222+
* @type {Number}
223+
*/
224+
this.horizonDistance = 0;
225+
220226
/**
221227
* Indicates that picking will return all objects at the pick point, if any. The top-most object will have
222228
* its isOnTop flag set to true.
@@ -707,11 +713,10 @@ define([
707713
this.camera.computeViewingTransform(modelview);
708714

709715
if (projection) {
710-
var globeRadius = WWMath.max(this.globe.equatorialRadius, this.globe.polarRadius),
711-
eyePos = this.camera.position,
716+
var eyePos = this.camera.position,
712717
fieldOfView = this.camera.fieldOfView,
713-
eyeHorizon = WWMath.horizonDistanceForGlobeRadius(globeRadius, eyePos.altitude),
714-
atmosphereHorizon = WWMath.horizonDistanceForGlobeRadius(globeRadius, 160000),
718+
eyeHorizon = this.globe.horizonDistance(eyePos.altitude),
719+
atmosphereHorizon = this.globe.horizonDistance(160000),
715720
viewport = this.viewport;
716721

717722
// Set the far clip distance to the smallest value that does not clip the atmosphere.
@@ -805,6 +810,7 @@ define([
805810
dc.globe = this.globe;
806811
dc.navigator = this.navigator;
807812
dc.camera = this.camera;
813+
dc.horizonDistance = this.globe.horizonDistance(this.camera.position.altitude);
808814
dc.layers = this.layers.slice();
809815
dc.layers.push(dc.screenCreditController);
810816
this.computeDrawContext();

src/geom/Camera.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ define([
278278
modelview.extractEyePoint(forwardRay.origin);
279279
modelview.extractForwardVector(forwardRay.direction);
280280

281-
var globeRadius = WWMath.max(globe.equatorialRadius, globe.polarRadius);
282-
var horizon = WWMath.horizonDistanceForGlobeRadius(globeRadius, this.position.altitude);
281+
var horizon = globe.horizonDistance(this.position.altitude);
283282
forwardRay.pointAt(horizon, originPoint);
284283

285284
globe.computePositionFromPoint(originPoint[0], originPoint[1], originPoint[2], originPos);

src/globe/Globe.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,5 +677,18 @@ define([
677677
return this.elevationModel.elevationsForGrid(sector, numLat, numLon, targetResolution, result);
678678
};
679679

680+
/**
681+
* Computes the distance to a globe's horizon from a viewer at a given altitude.
682+
*
683+
* Only the globe's ellipsoid is considered; terrain height is not incorporated.
684+
* This returns zero if the altitude is less than or equal to zero.
685+
*
686+
* @param {Number} altitude The viewer's altitude above the globe, in meters.
687+
* @returns {Number} The distance to the horizon, in model coordinates.
688+
*/
689+
Globe.prototype.horizonDistance = function (altitude) {
690+
return (altitude > 0) ? Math.sqrt(altitude * (2 * this.equatorialRadius + altitude)) : 0;
691+
};
692+
680693
return Globe;
681694
});

src/util/WWMath.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -600,26 +600,6 @@ define([
600600
yAxisResult.normalize();
601601
},
602602

603-
/**
604-
* Computes the distance to a globe's horizon from a viewer at a given altitude.
605-
*
606-
* Only the globe's ellipsoid is considered; terrain height is not incorporated. This returns zero if the radius is zero
607-
* or if the altitude is less than or equal to zero.
608-
*
609-
* @param {Number} radius The globe's radius, in meters.
610-
* @param {Number} altitude The viewer's altitude above the globe, in meters.
611-
* @returns {Number} The distance to the horizon, in model coordinates.
612-
* @throws {ArgumentError} If the specified globe radius is negative.
613-
*/
614-
horizonDistanceForGlobeRadius: function (radius, altitude) {
615-
if (radius < 0) {
616-
throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath",
617-
"horizontalDistanceForGlobeRadius", "The specified globe radius is negative."));
618-
}
619-
620-
return (radius > 0 && altitude > 0) ? Math.sqrt(altitude * (2 * radius + altitude)) : 0;
621-
},
622-
623603
/**
624604
* Computes the near clip distance that corresponds to a specified far clip distance and resolution at the far clip
625605
* plane.

0 commit comments

Comments
 (0)