-
- // LOOKAT mode...
- if ( _from_model ) {
- // update or data from model location
- updateFromModelLocation(_location);
- } else {
- // update from our own data, just the rotation here...
- recalcOurOwnLocation( _lon_deg, _lat_deg, _alt_ft,
- _roll_deg, _pitch_deg, _heading_deg );
- // get world up data from just recalced location
- sgCopyMat4(UP, _location->getUpMatrix());
- sgCopyVec3(_world_up, _location->get_world_up());
- }
- // save they eye positon...
- sgCopyVec3(eye_pos, _location->get_view_pos());
- // save the eye rotation before getting target values!!!
- sgCopyMat4(tmpROT, LOCAL);
-
- if ( _at_model ) {
- // update or data from model location
- updateFromModelLocation(_target_location);
- } else {
- // if not model then calculate our own target position...
- recalcOurOwnLocation( _target_lon_deg, _target_lat_deg, _target_alt_ft,
- _target_roll_deg, _target_pitch_deg, _target_heading_deg );
- }
- // restore the eye rotation (the from position rotation)
- sgCopyMat4(LOCAL, tmpROT);
-
- }
-
- // the coordinates generated by the above "recalcPositionVectors"
- sgCopyVec3(_zero_elev, _zero_elev_view_pos);
- sgCopyVec3(_view_pos, _relative_view_pos);
-
- // FIXME:
- // Doing this last recalc here for published values...where the airplane is
- // This should be per aircraft or model (for published values) before
- // multiple FDM can be done.
- // This info should come directly from the model (not through viewer),
- // because in some cases there is no model directly assigned as a lookfrom
- // position. The problem that arises is related to the FDM interface looking
- // indirectly to the viewer to find the altitude of the aircraft on the runway.
- //
- // Note that recalcPositionVectors can be removed from viewer when this
- // issue is addressed.
- //
- if (!_from_model) {
- recalcPositionVectors(fgGetDouble("/position/longitude-deg"),
- fgGetDouble("/position/latitude-deg"),
- fgGetDouble("/position/altitude-ft"));
- }
-
- // 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] );
- sgSetVec3( forward, -LOCAL[0][0], -LOCAL[0][1], -LOCAL[0][2] );
-
- if (_type == FG_LOOKAT) {
-
- // Note that when in "lookat" view the "world up" vector is always applied
- // to the viewer. World up is based on verticle at a given lon/lat (see
- // matrix "UP" above).
-
- // Orientation Offsets matrix
- MakeVIEW_OFFSET( VIEW_OFFSET,
- (_heading_offset_deg -_heading_deg) * SG_DEGREES_TO_RADIANS, _world_up,
- _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right );
-
- // add in the Orientation Offsets here
- sgSetVec3( position_offset, _x_offset_m, _y_offset_m, _z_offset_m );
- sgXformVec3( position_offset, position_offset, UP);
-
- sgXformVec3( position_offset, position_offset, VIEW_OFFSET );
-
- // add the Position offsets from object to the eye position
- sgAddVec3( eye_pos, eye_pos, position_offset );
-
- // at position (what we are looking at)
- sgCopyVec3( at_pos, _view_pos );
-
- // Make the VIEW matrix for a "LOOKAT".
- sgMakeLookAtMat4( VIEW, eye_pos, at_pos, _view_up );
- }
-
- if (_type == FG_LOOKFROM) {
-
- // Note that when in "lookfrom" view the "view up" vector is always applied
- // to the viewer. View up is based on verticle of the aircraft itself. (see
- // "LOCAL" matrix above)
-
- // Orientation Offsets matrix
- MakeVIEW_OFFSET( VIEW_OFFSET,
- _heading_offset_deg * SG_DEGREES_TO_RADIANS, _view_up,
- _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right );
-
- // Make the VIEW matrix.
- sgSetVec4(VIEW[0], right[0], right[1], right[2],SG_ZERO);
- sgSetVec4(VIEW[1], forward[0], forward[1], forward[2],SG_ZERO);
- sgSetVec4(VIEW[2], _view_up[0], _view_up[1], _view_up[2],SG_ZERO);
- sgSetVec4(VIEW[3], SG_ZERO, SG_ZERO, SG_ZERO,SG_ONE);
-
- // rotate 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]);
-
- // Eye Position Offsets to vector
- sgSetVec3( position_offset, _x_offset_m, _y_offset_m, _z_offset_m );
- sgXformVec3( position_offset, position_offset, VIEW_UP);
-
- // add the offsets including rotations to the translation vector
- sgAddVec3( _view_pos, position_offset );
-
- // multiply the OFFSETS (for heading and pitch) into the VIEW
- sgPostMultMat4(VIEW, VIEW_OFFSET);
-
- // add the position data to the matrix
- sgSetVec4(VIEW[3], _view_pos[0], _view_pos[1], _view_pos[2],SG_ONE);
-