From 30b05ee7a3b18bf3e87103e9ae346200ebed24a2 Mon Sep 17 00:00:00 2001 From: frohlich Date: Sat, 7 Mar 2009 13:32:41 +0000 Subject: [PATCH] ompute some vectors from the current view when they are used. 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 | 19 ++++++++++--------- src/Main/viewer.cxx | 9 --------- src/Main/viewer.hxx | 23 ----------------------- src/Time/tmp.cxx | 13 +++++++++---- 4 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/Main/renderer.cxx b/src/Main/renderer.cxx index 26762df32..0592db235 100644 --- a/src/Main/renderer.cxx +++ b/src/Main/renderer.cxx @@ -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(); diff --git a/src/Main/viewer.cxx b/src/Main/viewer.cxx index f2ffd56c9..7e243c05d 100644 --- a/src/Main/viewer.cxx +++ b/src/Main/viewer.cxx @@ -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(); diff --git a/src/Main/viewer.hxx b/src/Main/viewer.hxx index 345828846..709523d81 100644 --- a/src/Main/viewer.hxx +++ b/src/Main/viewer.hxx @@ -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 _cameraGroup; ////////////////////////////////////////////////////////////////// diff --git a/src/Time/tmp.cxx b/src/Time/tmp.cxx index 5b4a894dc..70cac6f82 100644 --- a/src/Time/tmp.cxx +++ b/src/Time/tmp.cxx @@ -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) {