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
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();
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();
// 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; }
// 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;
//////////////////////////////////////////////////////////////////
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;
// 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;
// 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) {