diff --git a/worldwind/src/main/java/gov/nasa/worldwind/geom/Camera.java b/worldwind/src/main/java/gov/nasa/worldwind/geom/Camera.java index 73b973fea..6b60a005b 100644 --- a/worldwind/src/main/java/gov/nasa/worldwind/geom/Camera.java +++ b/worldwind/src/main/java/gov/nasa/worldwind/geom/Camera.java @@ -108,9 +108,8 @@ public Matrix4 computeViewingTransform(Matrix4 result) { Logger.logMessage(Logger.ERROR, "Camera", "computeViewingTransform", "missingResult")); } - // TODO interpret altitude mode other than absolute // Transform by the local cartesian transform at the camera's position. - this.wwd.getGlobe().geographicToCartesianTransform(this.position.latitude, this.position.longitude, this.position.altitude, result); + this.geographicToCartesianTransform(this.position, this.altitudeMode, result); // Transform by the heading, tilt and roll. result.multiplyByRotation(0, 0, 1, -this.heading); // rotate clockwise about the Z axis @@ -166,6 +165,7 @@ public Camera setFromLookAt(LookAt lookAt) { this.modelview.multiplyByMatrix(this.origin); this.position.set(this.originPos); + this.altitudeMode = WorldWind.ABSOLUTE; // Calculated position is absolute this.heading = this.modelview.extractHeading(lookAt.roll); // disambiguate heading and roll this.tilt = this.modelview.extractTilt(); this.roll = lookAt.roll; // roll passes straight through @@ -193,9 +193,8 @@ public Camera setFromLookAt(LookAt lookAt) { } protected Matrix4 lookAtToViewingTransform(LookAt lookAt, Matrix4 result) { - // TODO interpret altitude mode other than absolute // Transform by the local cartesian transform at the look-at's position. - this.wwd.getGlobe().geographicToCartesianTransform(lookAt.position.latitude, lookAt.position.longitude, lookAt.position.altitude, result); + this.geographicToCartesianTransform(lookAt.position, lookAt.altitudeMode, result); // Transform by the heading and tilt. result.multiplyByRotation(0, 0, 1, -lookAt.heading); // rotate clockwise about the Z axis @@ -211,4 +210,23 @@ protected Matrix4 lookAtToViewingTransform(LookAt lookAt, Matrix4 result) { return result; } + protected void geographicToCartesianTransform(Position position, @WorldWind.AltitudeMode int altitudeMode, Matrix4 result) { + switch (altitudeMode) { + case WorldWind.ABSOLUTE: + this.wwd.getGlobe().geographicToCartesianTransform( + position.latitude, position.longitude, position.altitude * this.wwd.getVerticalExaggeration(), result); + break; + case WorldWind.CLAMP_TO_GROUND: + this.wwd.getGlobe().geographicToCartesianTransform( + position.latitude, position.longitude, this.wwd.getGlobe().getElevationAtLocation( + position.latitude, position.longitude) * this.wwd.getVerticalExaggeration(), result); + break; + case WorldWind.RELATIVE_TO_GROUND: + this.wwd.getGlobe().geographicToCartesianTransform( + position.latitude, position.longitude, (position.altitude + this.wwd.getGlobe().getElevationAtLocation( + position.latitude, position.longitude)) * this.wwd.getVerticalExaggeration(), result); + break; + } + } + } diff --git a/worldwind/src/main/java/gov/nasa/worldwind/render/RenderContext.java b/worldwind/src/main/java/gov/nasa/worldwind/render/RenderContext.java index b5b2911fd..acb760472 100644 --- a/worldwind/src/main/java/gov/nasa/worldwind/render/RenderContext.java +++ b/worldwind/src/main/java/gov/nasa/worldwind/render/RenderContext.java @@ -363,14 +363,17 @@ public Vec3 geographicToCartesian(double latitude, double longitude, double alti switch (altitudeMode) { case WorldWind.ABSOLUTE: if (this.globe != null) { - return this.globe.geographicToCartesian(latitude, longitude, altitude * this.verticalExaggeration, result); + return this.globe.geographicToCartesian(latitude, longitude, + altitude * this.verticalExaggeration, result); } case WorldWind.CLAMP_TO_GROUND: if (this.terrain != null && this.terrain.surfacePoint(latitude, longitude, result)) { return result; // found a point on the terrain } else if (this.globe != null) { - // TODO use elevation model height as a fallback - return this.globe.geographicToCartesian(latitude, longitude, 0, result); + // Use elevation model height as a fallback + return this.globe.geographicToCartesian(latitude, longitude, + this.globe.getElevationAtLocation(latitude, longitude) + * this.verticalExaggeration, result); } case WorldWind.RELATIVE_TO_GROUND: if (this.terrain != null && this.terrain.surfacePoint(latitude, longitude, result)) { @@ -382,8 +385,10 @@ public Vec3 geographicToCartesian(double latitude, double longitude, double alti } return result; // found a point relative to the terrain } else if (this.globe != null) { - // TODO use elevation model height as a fallback - return this.globe.geographicToCartesian(latitude, longitude, altitude, result); + // Use elevation model height as a fallback + return this.globe.geographicToCartesian(latitude, longitude, + (altitude + this.globe.getElevationAtLocation(latitude, longitude)) + * this.verticalExaggeration, result); } } diff --git a/worldwind/src/main/java/gov/nasa/worldwind/shape/OmnidirectionalSightline.java b/worldwind/src/main/java/gov/nasa/worldwind/shape/OmnidirectionalSightline.java index 8d4ca68e7..94e760a74 100644 --- a/worldwind/src/main/java/gov/nasa/worldwind/shape/OmnidirectionalSightline.java +++ b/worldwind/src/main/java/gov/nasa/worldwind/shape/OmnidirectionalSightline.java @@ -85,10 +85,6 @@ public class OmnidirectionalSightline extends AbstractRenderable implements Attr private Vec3 centerPoint = new Vec3(); - private Vec3 scratchPoint = new Vec3(); - - private Vec3 scratchVector = new Vec3(); - private int pickedObjectId; private Color pickColor = new Color(); @@ -383,33 +379,9 @@ protected void doRender(RenderContext rc) { } protected boolean determineCenterPoint(RenderContext rc) { - double lat = this.position.latitude; - double lon = this.position.longitude; - double alt = this.position.altitude; - - switch (this.altitudeMode) { - case WorldWind.ABSOLUTE: - if (rc.globe != null) { - rc.globe.geographicToCartesian(lat, lon, alt * rc.verticalExaggeration, this.centerPoint); - } - break; - case WorldWind.CLAMP_TO_GROUND: - if (rc.terrain != null && rc.terrain.surfacePoint(lat, lon, this.scratchPoint)) { - this.centerPoint.set(this.scratchPoint); // found a point on the terrain - } - break; - case WorldWind.RELATIVE_TO_GROUND: - if (rc.terrain != null && rc.terrain.surfacePoint(lat, lon, this.scratchPoint)) { - this.centerPoint.set(this.scratchPoint); // found a point on the terrain - if (alt != 0) { // Offset along the normal vector at the terrain surface point. - rc.globe.geographicToCartesianNormal(lat, lon, this.scratchVector); - this.centerPoint.x += this.scratchVector.x * alt; - this.centerPoint.y += this.scratchVector.y * alt; - this.centerPoint.z += this.scratchVector.z * alt; - } - } - break; - } + rc.geographicToCartesian( + this.position.latitude, this.position.longitude, this.position.altitude, + this.altitudeMode, this.centerPoint); return this.centerPoint.x != 0 && this.centerPoint.y != 0