@@ -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}
0 commit comments