]> git.mxchange.org Git - flightgear.git/commitdiff
ompute some vectors from the current view when they are used.
authorfrohlich <frohlich>
Sat, 7 Mar 2009 13:32:41 +0000 (13:32 +0000)
committerTim Moore <timoore@redhat.com>
Wed, 11 Mar 2009 22:14:34 +0000 (23:14 +0100)
Simplifies the update hell in the viewer a bit.

Modified Files:
src/Main/renderer.cxx src/Main/viewer.cxx src/Main/viewer.hxx
src/Time/tmp.cxx

src/Main/renderer.cxx
src/Main/viewer.cxx
src/Main/viewer.hxx
src/Time/tmp.cxx

index 26762df32d20de070561e3f484576d443307cede..0592db2357be6d7077737bb3d48e9e68d54ecb5c 100644 (file)
@@ -623,15 +623,16 @@ FGRenderer::update( bool refresh_camera_settings ) {
 
         static SGSkyState sstate;
 
-        sstate.view_pos  = toVec3f(current__view->get_view_pos());
-        sstate.zero_elev = toVec3f(current__view->get_zero_elev());
-        sstate.view_up   = current__view->get_world_up();
-        sstate.lon       = current__view->getLongitude_deg()
-                            * SGD_DEGREES_TO_RADIANS;
-        sstate.lat       = current__view->getLatitude_deg()
-                            * SGD_DEGREES_TO_RADIANS;
-        sstate.alt       = current__view->getAltitudeASL_ft()
-                            * SG_FEET_TO_METER;
+        SGVec3d viewPos = current__view->getViewPosition();
+        sstate.view_pos  = toVec3f(viewPos);
+        SGGeod geodViewPos = SGGeod::fromCart(viewPos);
+        SGGeod geodZeroViewPos = SGGeod::fromGeodM(geodViewPos, 0);
+        sstate.zero_elev = toVec3f(SGVec3d::fromGeod(geodZeroViewPos));
+        SGQuatd hlOr = SGQuatd::fromLonLat(geodViewPos);
+        sstate.view_up   = toVec3f(hlOr.backTransform(-SGVec3d::e3()));
+        sstate.lon       = geodViewPos.getLongitudeRad();
+        sstate.lat       = geodViewPos.getLatitudeRad();
+        sstate.alt       = geodViewPos.getElevationM();
         sstate.spin      = l->get_sun_rotation();
         sstate.gst       = globals->get_time_params()->getGst();
         sstate.sun_ra    = globals->get_ephem()->getSunRightAscension();
index f2ffd56c9d57a5fae327aae613bc7e6fc6068f45..7e243c05d8e452a376f083b8055d1c59fcaf45e5 100644 (file)
@@ -417,15 +417,6 @@ FGViewer::recalc ()
     recalcLookAt();
   }
 
-  SGGeod geodEyePoint = SGGeod::fromCart(_absolute_view_pos);
-  geodEyePoint.setElevationM(0);
-  _zero_elev = SGVec3d::fromGeod(geodEyePoint);
-  
-  SGQuatd hlOr = SGQuatd::fromLonLat(geodEyePoint);
-  _surface_south = toVec3f(hlOr.backTransform(-SGVec3d::e1()));
-  _surface_east = toVec3f(hlOr.backTransform(SGVec3d::e2()));
-  _world_up = toVec3f(hlOr.backTransform(-SGVec3d::e3()));
-
   // Update viewer's postion data for the eye location...
   _lon_deg = _location->getLongitude_deg();
   _lat_deg = _location->getLatitude_deg();
index 345828846a77d328dee13fed2584f1ab4d0f614d..709523d8127410c96e85bde375162cb115f477bf 100644 (file)
@@ -216,15 +216,6 @@ public:
 
     // Vectors and positions...
 
-    // Get zero elev
-    const SGVec3d& get_zero_elev() {if ( _dirty ) { recalc(); } return _zero_elev; }
-    // Get world up vector
-    const SGVec3f& get_world_up() {if ( _dirty ) { recalc(); } return _world_up; }
-    // Get surface east vector
-    const SGVec3f& get_surface_east() {        if ( _dirty ) { recalc(); } return _surface_east; }
-    // Get surface south vector
-    const SGVec3f& get_surface_south() {if ( _dirty ) { recalc(); } return _surface_south; }
-
     const SGVec3d& get_view_pos() { if ( _dirty ) { recalc(); } return _absolute_view_pos; }
     const SGVec3d& getViewPosition() { if ( _dirty ) { recalc(); } return _absolute_view_pos; }
     const SGQuatd& getViewOrientation() { if ( _dirty ) { recalc(); } return mViewOrientation; }
@@ -354,20 +345,6 @@ private:
     // multiplied into the aspect_ratio to get the actual vertical fov
     double _aspect_ratio_multiplier;
 
-    // cartesion coordinates of current lon/lat if at sea level
-    SGVec3d _zero_elev;
-
-    // surface vector heading south
-    SGVec3f _surface_south;
-
-    // surface vector heading east (used to unambiguously align sky
-    // with sun)
-    SGVec3f _surface_east;
-
-    // world up vector (normal to the plane tangent to the earth's
-    // surface at the spot we are directly above
-    SGVec3f _world_up;
-
     // camera group controled by this view
     osg::ref_ptr<flightgear::CameraGroup> _cameraGroup;
     //////////////////////////////////////////////////////////////////
index 5b4a894dc21314eca2935ffe94611c5ab8283266..70cac6f823c14c167ded46db0ae339cf7534f15a 100644 (file)
@@ -89,7 +89,10 @@ void fgUpdateSunPos( void ) {
     l->sun_vec_inv() = - l->sun_vec();
 
     // calculate the sun's relative angle to local up
-    SGVec3f nup(normalize(v->get_world_up()));
+    SGVec3d viewPos = v->get_view_pos();
+    SGQuatd hlOr = SGQuatd::fromLonLat(SGGeod::fromCart(viewPos));
+    SGVec3f nup(toVec3f(hlOr.backTransform(-SGVec3d::e3())));
+
     SGVec3f nsun(toVec3f(normalize(l->get_sunpos())));
     // cout << "nup = " << nup[0] << "," << nup[1] << "," 
     //      << nup[2] << endl;
@@ -112,7 +115,7 @@ void fgUpdateSunPos( void ) {
     // earth's surface the sun is directly over, map into onto the
     // local plane representing "horizontal".
 
-    SGVec3f world_up = v->get_world_up();
+    SGVec3f world_up = toVec3f(hlOr.backTransform(-SGVec3d::e3()));
     SGVec3f view_pos = toVec3f(v->get_view_pos());
     // surface direction to go to head towards sun
     SGVec3f surface_to_sun;
@@ -130,13 +133,15 @@ void fgUpdateSunPos( void ) {
     // v->get_surface_east().  We do this so we can sort out the
     // acos() ambiguity.  I wish I could think of a more efficient
     // way. :-(
-    float east_dot = dot( surface_to_sun, v->get_surface_east() );
+    SGVec3f surface_east(toVec3f(hlOr.backTransform(SGVec3d::e2())));
+    float east_dot = dot( surface_to_sun, surface_east );
     // cout << "  East dot product = " << east_dot << endl;
 
     // calculate the angle between v->surface_to_sun and
     // v->surface_south.  this is how much we have to rotate the sky
     // for it to align with the sun
-    float dot_ = dot( surface_to_sun, v->get_surface_south() );
+    SGVec3f surface_south(toVec3f(hlOr.backTransform(-SGVec3d::e1())));
+    float dot_ = dot( surface_to_sun, surface_south );
     // cout << "  Dot product = " << dot << endl;
 
     if (dot_ > 1.0) {