diff --git a/src/globe/Globe.js b/src/globe/Globe.js index 6766c4e6..9f94a394 100644 --- a/src/globe/Globe.js +++ b/src/globe/Globe.js @@ -388,6 +388,12 @@ define([ "missingResult")); } + // For backwards compatibility, check whether the projection defines a surfaceNormalAtPoint function + // before calling it. If it's not available, use the old code to compute the normal. + if (this.projection.surfaceNormalAtPoint) { + return this.projection.surfaceNormalAtPoint(this, x, y, z, result); + } + if (this.is2D()) { result[0] = 0; result[1] = 0; diff --git a/src/projections/GeographicProjection.js b/src/projections/GeographicProjection.js index 4f88e751..154cc031 100644 --- a/src/projections/GeographicProjection.js +++ b/src/projections/GeographicProjection.js @@ -199,5 +199,30 @@ define([ return result; }; + /** + * Computes the Cartesian surface normal vector at a specified Cartesian point. + * + * @param {Globe} globe The globe this projection is applied to. + * @param {number} x The X component of the Cartesian point. + * @param {number} y The Y component of the Cartesian point. + * @param {number} z The Z component of the Cartesian point. + * @param {Vec3} result A variable in which to return the computed vector. + * + * @returns{Vec3} The specified result argument containing the computed vector. + * @throws {ArgumentError} If either the specified globe or result argument is null or undefined. + */ + GeographicProjection.prototype.surfaceNormalAtPoint = function (globe, x, y, z, result) { + if (!result) { + throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "GeographicProjection", "surfaceNormalAtPoint", + "missingResult")); + } + + result[0] = 0; + result[1] = 0; + result[2] = 1; + + return result; + }; + return GeographicProjection; }); \ No newline at end of file diff --git a/src/projections/ProjectionWgs84.js b/src/projections/ProjectionWgs84.js index 7b2de47c..d89c392d 100644 --- a/src/projections/ProjectionWgs84.js +++ b/src/projections/ProjectionWgs84.js @@ -272,5 +272,21 @@ define([ return this.northTangentAtLocation(globe, this.scratchPosition.latitude, this.scratchPosition.longitude, result); }; + ProjectionWgs84.prototype.surfaceNormalAtPoint = function (globe, x, y, z, result) { + if (!globe) { + throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "ProjectionWgs84", + "surfaceNormalAtPoint", "missingGlobe")); + } + + var eSquared = globe.equatorialRadius * globe.equatorialRadius, + polSquared = globe.polarRadius * globe.polarRadius; + + result[0] = x / eSquared; + result[1] = y / polSquared; + result[2] = z / eSquared; + + return result.normalize(); + }; + return ProjectionWgs84; }); \ No newline at end of file