+
+ sgVec3 right;
+ sgVec3 eye_pos, at_pos;
+ sgVec3 position_offset; // eye position offsets (xyz)
+ sgVec3 target_position_offset; // target position offsets (xyz)
+
+ // The position vectors originate from the view point or target location
+ // depending on the type of view.
+
+ // LOOKAT mode...
+
+ // Update location data for target...
+ if ( _at_model ) {
+ // update or data from model location
+ updateAtModelLocation(_target_location);
+ } else {
+ // if not model then calculate our own target position...
+ recalcOurOwnLocation( _target_location, _target_lon_deg, _target_lat_deg, _target_alt_ft,
+ _target_roll_deg, _target_pitch_deg, _target_heading_deg );
+ }
+ // calculate the "at" target object positon relative to eye or view's tile center...
+ sgdVec3 dVec3;
+ sgdSetVec3(dVec3, _location->get_tile_center()[0], _location->get_tile_center()[1], _location->get_tile_center()[2]);
+ sgdSubVec3(dVec3,
+ _target_location->get_absolute_view_pos(globals->get_scenery()->get_center()),
+ dVec3 );
+ sgSetVec3(at_pos, dVec3[0], dVec3[1], dVec3[2]);
+
+ // Update location data for eye...
+ if ( _from_model ) {
+ // update or data from model location
+ updateFromModelLocation(_location);
+ } else {
+ // update from our own data, just the rotation here...
+ recalcOurOwnLocation( _location, _lon_deg, _lat_deg, _alt_ft,
+ _roll_deg, _pitch_deg, _heading_deg );
+ }
+ // save the eye positon...
+ sgCopyVec3(eye_pos, _location->get_view_pos());
+
+ // copy data from location class to local items...
+ copyLocationData();
+
+ // make sg vectors view up, right and forward vectors from LOCAL
+ sgSetVec3( _view_up, LOCAL[2][0], LOCAL[2][1], LOCAL[2][2] );
+ sgSetVec3( right, LOCAL[1][0], LOCAL[1][1], LOCAL[1][2] );
+
+ // rotate model or local matrix to get a matrix to apply Eye Position Offsets
+ sgMat4 VIEW_UP; // L0 forward L1 right L2 up
+ sgCopyVec4(VIEW_UP[0], LOCAL[1]);
+ sgCopyVec4(VIEW_UP[1], LOCAL[2]);
+ sgCopyVec4(VIEW_UP[2], LOCAL[0]);
+ sgZeroVec4(VIEW_UP[3]);
+
+ // get Orientation Offsets matrix
+ MakeVIEW_OFFSET( VIEW_OFFSET,
+ (_heading_offset_deg - 180) * SG_DEGREES_TO_RADIANS, _view_up,
+ _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right );
+
+ // add in the position offsets
+ sgSetVec3( position_offset, _y_offset_m, _x_offset_m, _z_offset_m );
+ sgXformVec3( position_offset, position_offset, VIEW_UP);
+
+ // apply the Orientation offsets
+ sgXformVec3( position_offset, position_offset, VIEW_OFFSET );
+
+ // add the Position offsets from object to the eye position
+ sgAddVec3( eye_pos, eye_pos, position_offset );
+
+ // add target offsets to at_position...
+ sgSetVec3(target_position_offset, _target_z_offset_m, _target_x_offset_m,
+ _target_y_offset_m );
+ sgXformVec3(target_position_offset, target_position_offset, ATLOCAL);
+ sgAddVec3( at_pos, at_pos, target_position_offset);
+
+ sgAddVec3( eye_pos, eye_pos, target_position_offset);
+
+ // Make the VIEW matrix for a "LOOKAT".
+ sgMakeLookAtMat4( VIEW, eye_pos, at_pos, _view_up );
+