Skip to content

Commit 29d100d

Browse files
committed
Implement altitudeMode support in Camera logic.
1 parent 1727068 commit 29d100d

File tree

4 files changed

+27
-37
lines changed

4 files changed

+27
-37
lines changed

worldwind/src/main/java/gov/nasa/worldwind/geom/Camera.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ public Matrix4 computeViewingTransform(Matrix4 result) {
108108
Logger.logMessage(Logger.ERROR, "Camera", "computeViewingTransform", "missingResult"));
109109
}
110110

111-
// TODO interpret altitude mode other than absolute
112111
// Transform by the local cartesian transform at the camera's position.
113-
this.wwd.getGlobe().geographicToCartesianTransform(this.position.latitude, this.position.longitude, this.position.altitude, result);
112+
this.geographicToCartesianTransform(this.position, this.altitudeMode, result);
114113

115114
// Transform by the heading, tilt and roll.
116115
result.multiplyByRotation(0, 0, 1, -this.heading); // rotate clockwise about the Z axis
@@ -166,6 +165,7 @@ public Camera setFromLookAt(LookAt lookAt) {
166165
this.modelview.multiplyByMatrix(this.origin);
167166

168167
this.position.set(this.originPos);
168+
this.altitudeMode = WorldWind.ABSOLUTE; // Calculated position is absolute
169169
this.heading = this.modelview.extractHeading(lookAt.roll); // disambiguate heading and roll
170170
this.tilt = this.modelview.extractTilt();
171171
this.roll = lookAt.roll; // roll passes straight through
@@ -193,9 +193,8 @@ public Camera setFromLookAt(LookAt lookAt) {
193193
}
194194

195195
protected Matrix4 lookAtToViewingTransform(LookAt lookAt, Matrix4 result) {
196-
// TODO interpret altitude mode other than absolute
197196
// Transform by the local cartesian transform at the look-at's position.
198-
this.wwd.getGlobe().geographicToCartesianTransform(lookAt.position.latitude, lookAt.position.longitude, lookAt.position.altitude, result);
197+
this.geographicToCartesianTransform(lookAt.position, lookAt.altitudeMode, result);
199198

200199
// Transform by the heading and tilt.
201200
result.multiplyByRotation(0, 0, 1, -lookAt.heading); // rotate clockwise about the Z axis
@@ -211,4 +210,23 @@ protected Matrix4 lookAtToViewingTransform(LookAt lookAt, Matrix4 result) {
211210
return result;
212211
}
213212

213+
protected void geographicToCartesianTransform(Position position, @WorldWind.AltitudeMode int altitudeMode, Matrix4 result) {
214+
switch (altitudeMode) {
215+
case WorldWind.ABSOLUTE:
216+
this.wwd.getGlobe().geographicToCartesianTransform(
217+
position.latitude, position.longitude, position.altitude * this.wwd.getVerticalExaggeration(), result);
218+
break;
219+
case WorldWind.CLAMP_TO_GROUND:
220+
this.wwd.getGlobe().geographicToCartesianTransform(
221+
position.latitude, position.longitude, this.wwd.getGlobe().getElevationAtLocation(
222+
position.latitude, position.longitude) * this.wwd.getVerticalExaggeration(), result);
223+
break;
224+
case WorldWind.RELATIVE_TO_GROUND:
225+
this.wwd.getGlobe().geographicToCartesianTransform(
226+
position.latitude, position.longitude, (position.altitude + this.wwd.getGlobe().getElevationAtLocation(
227+
position.latitude, position.longitude)) * this.wwd.getVerticalExaggeration(), result);
228+
break;
229+
}
230+
}
231+
214232
}

worldwind/src/main/java/gov/nasa/worldwind/layer/graticule/AbstractGraticuleLayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ private double getLabelOffset(RenderContext rc) {
438438
Vec3 getSurfacePoint(RenderContext rc, double latitude, double longitude) {
439439
if (!rc.terrain.surfacePoint(latitude, longitude, surfacePoint))
440440
rc.globe.geographicToCartesian(latitude, longitude,
441-
rc.globe.getElevationAtLocation(latitude, longitude), surfacePoint);
441+
rc.globe.getElevationAtLocation(latitude, longitude) * rc.verticalExaggeration, surfacePoint);
442442

443443
return surfacePoint;
444444
}

worldwind/src/main/java/gov/nasa/worldwind/render/RenderContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public Vec3 geographicToCartesian(double latitude, double longitude, double alti
383383
return result; // found a point relative to the terrain
384384
} else if (this.globe != null) {
385385
// TODO use elevation model height as a fallback
386-
return this.globe.geographicToCartesian(latitude, longitude, altitude, result);
386+
return this.globe.geographicToCartesian(latitude, longitude, altitude * this.verticalExaggeration, result);
387387
}
388388
}
389389

worldwind/src/main/java/gov/nasa/worldwind/shape/OmnidirectionalSightline.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ public class OmnidirectionalSightline extends AbstractRenderable implements Attr
8585

8686
private Vec3 centerPoint = new Vec3();
8787

88-
private Vec3 scratchPoint = new Vec3();
89-
90-
private Vec3 scratchVector = new Vec3();
91-
9288
private int pickedObjectId;
9389

9490
private Color pickColor = new Color();
@@ -383,33 +379,9 @@ protected void doRender(RenderContext rc) {
383379
}
384380

385381
protected boolean determineCenterPoint(RenderContext rc) {
386-
double lat = this.position.latitude;
387-
double lon = this.position.longitude;
388-
double alt = this.position.altitude;
389-
390-
switch (this.altitudeMode) {
391-
case WorldWind.ABSOLUTE:
392-
if (rc.globe != null) {
393-
rc.globe.geographicToCartesian(lat, lon, alt * rc.verticalExaggeration, this.centerPoint);
394-
}
395-
break;
396-
case WorldWind.CLAMP_TO_GROUND:
397-
if (rc.terrain != null && rc.terrain.surfacePoint(lat, lon, this.scratchPoint)) {
398-
this.centerPoint.set(this.scratchPoint); // found a point on the terrain
399-
}
400-
break;
401-
case WorldWind.RELATIVE_TO_GROUND:
402-
if (rc.terrain != null && rc.terrain.surfacePoint(lat, lon, this.scratchPoint)) {
403-
this.centerPoint.set(this.scratchPoint); // found a point on the terrain
404-
if (alt != 0) { // Offset along the normal vector at the terrain surface point.
405-
rc.globe.geographicToCartesianNormal(lat, lon, this.scratchVector);
406-
this.centerPoint.x += this.scratchVector.x * alt;
407-
this.centerPoint.y += this.scratchVector.y * alt;
408-
this.centerPoint.z += this.scratchVector.z * alt;
409-
}
410-
}
411-
break;
412-
}
382+
rc.geographicToCartesian(
383+
this.position.latitude, this.position.longitude, this.position.altitude,
384+
this.altitudeMode, this.centerPoint);
413385

414386
return this.centerPoint.x != 0
415387
&& this.centerPoint.y != 0

0 commit comments

Comments
 (0)