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;
<< l->get_sun_angle() );
// calculate vector to sun's position on the earth's surface
- SGVec3d rel_sunpos = globals->get_scenery()->get_center();
- rel_sunpos += l->get_sunpos() - toVec3d(v->get_view_pos());
+ SGVec3d rel_sunpos = l->get_sunpos() - v->get_view_pos();
// vector in cartesian coordinates from current position to the
// postion on the earth's surface the sun is directly over
SGVec3f to_sun = toVec3f(rel_sunpos);
// earth's surface the sun is directly over, map into onto the
// local plane representing "horizontal".
- SGVec3f world_up = v->get_world_up();
- SGVec3f view_pos = v->get_view_pos();
+ 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;
sgmap_vec_onto_cur_surface_plane( world_up.data(), view_pos.data(),
// 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) {