1 // viewer.cxx -- class for managing a viewer in the flightgear world.
3 // Written by Curtis Olson, started August 1997.
4 // overhaul started October 2000.
5 // partially rewritten by Jim Wilson jim@kelcomaine.com using interface
6 // by David Megginson March 2002
8 // Copyright (C) 1997 - 2000 Curtis L. Olson - http://www.flightgear.org/~curt
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <simgear/compiler.h>
29 #include "fg_props.hxx"
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/constants.h>
37 #include <simgear/math/point3d.hxx>
38 #include <simgear/math/polar3d.hxx>
39 #include <simgear/math/sg_geodesy.hxx>
40 #include <simgear/scene/model/location.hxx>
41 #include <simgear/scene/model/placement.hxx>
42 #include <simgear/math/vector.hxx>
44 #include <Main/globals.hxx>
45 #include <Scenery/scenery.hxx>
46 #include <Model/acmodel.hxx>
51 //////////////////////////////////////////////////////////////////
52 // Norman's Optimized matrix rotators! //
53 //////////////////////////////////////////////////////////////////
56 // Since these are pure rotation matrices we can save some bookwork
57 // by considering them to be 3x3 until the very end -- NHV
58 static void MakeVIEW_OFFSET( sgMat4 dst,
59 const float angle1, const sgVec3 axis1,
60 const float angle2, const sgVec3 axis2,
61 const float angle3, const sgVec3 axis3 )
63 // make rotmatrix1 from angle and axis
64 float s = (float) sin ( angle1 ) ;
65 float c = (float) cos ( angle1 ) ;
66 float t = SG_ONE - c ;
69 float tmp = t * axis1[0];
70 mat1[0][0] = tmp * axis1[0] + c ;
71 mat1[0][1] = tmp * axis1[1] + s * axis1[2] ;
72 mat1[0][2] = tmp * axis1[2] - s * axis1[1] ;
75 mat1[1][0] = tmp * axis1[0] - s * axis1[2] ;
76 mat1[1][1] = tmp * axis1[1] + c ;
77 mat1[1][2] = tmp * axis1[2] + s * axis1[0] ;
80 mat1[2][0] = tmp * axis1[0] + s * axis1[1] ;
81 mat1[2][1] = tmp * axis1[1] - s * axis1[0] ;
82 mat1[2][2] = tmp * axis1[2] + c ;
84 // make rotmatrix2 from angle and axis
85 s = (float) sin ( angle2 ) ;
86 c = (float) cos ( angle2 ) ;
91 mat2[0][0] = tmp * axis2[0] + c ;
92 mat2[0][1] = tmp * axis2[1] + s * axis2[2] ;
93 mat2[0][2] = tmp * axis2[2] - s * axis2[1] ;
96 mat2[1][0] = tmp * axis2[0] - s * axis2[2] ;
97 mat2[1][1] = tmp * axis2[1] + c ;
98 mat2[1][2] = tmp * axis2[2] + s * axis2[0] ;
101 mat2[2][0] = tmp * axis2[0] + s * axis2[1] ;
102 mat2[2][1] = tmp * axis2[1] - s * axis2[0] ;
103 mat2[2][2] = tmp * axis2[2] + c ;
106 // make rotmatrix3 from angle and axis (roll)
107 s = (float) sin ( angle3 ) ;
108 c = (float) cos ( angle3 ) ;
113 mat3[0][0] = tmp * axis3[0] + c ;
114 mat3[0][1] = tmp * axis3[1] + s * axis3[2] ;
115 mat3[0][2] = tmp * axis3[2] - s * axis3[1] ;
118 mat3[1][0] = tmp * axis3[0] - s * axis3[2] ;
119 mat3[1][1] = tmp * axis3[1] + c ;
120 mat3[1][2] = tmp * axis3[2] + s * axis3[0] ;
123 mat3[2][0] = tmp * axis3[0] + s * axis3[1] ;
124 mat3[2][1] = tmp * axis3[1] - s * axis3[0] ;
125 mat3[2][2] = tmp * axis3[2] + c ;
130 for ( int j = 0 ; j < 3 ; j++ ) {
131 matt[0][j] = mat2[0][0] * mat1[0][j] +
132 mat2[0][1] * mat1[1][j] +
133 mat2[0][2] * mat1[2][j];
135 matt[1][j] = mat2[1][0] * mat1[0][j] +
136 mat2[1][1] * mat1[1][j] +
137 mat2[1][2] * mat1[2][j];
139 matt[2][j] = mat2[2][0] * mat1[0][j] +
140 mat2[2][1] * mat1[1][j] +
141 mat2[2][2] * mat1[2][j];
145 for ( int j = 0 ; j < 3 ; j++ ) {
146 dst[0][j] = mat3[0][0] * matt[0][j] +
147 mat3[0][1] * matt[1][j] +
148 mat3[0][2] * matt[2][j];
150 dst[1][j] = mat3[1][0] * matt[0][j] +
151 mat3[1][1] * matt[1][j] +
152 mat3[1][2] * matt[2][j];
154 dst[2][j] = mat3[2][0] * matt[0][j] +
155 mat3[2][1] * matt[1][j] +
156 mat3[2][2] * matt[2][j];
158 // fill in 4x4 matrix elements
169 ////////////////////////////////////////////////////////////////////////
170 // Implementation of FGViewer.
171 ////////////////////////////////////////////////////////////////////////
174 FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
175 bool at_model, int at_model_index,
176 double damp_roll, double damp_pitch, double damp_heading,
177 double x_offset_m, double y_offset_m, double z_offset_m,
178 double heading_offset_deg, double pitch_offset_deg,
179 double roll_offset_deg,
180 double fov_deg, double aspect_ratio_multiplier,
181 double target_x_offset_m, double target_y_offset_m,
182 double target_z_offset_m, double near_m, bool internal ):
197 _scaling_type(FG_SCALING_MAX)
199 sgdZeroVec3(_absolute_view_pos);
201 _from_model = from_model;
202 _from_model_index = from_model_index;
203 _at_model = at_model;
204 _at_model_index = at_model_index;
206 _internal = internal;
209 _damp_roll = 1.0 / pow(10.0, fabs(damp_roll));
210 if (damp_pitch > 0.0)
211 _damp_pitch = 1.0 / pow(10.0, fabs(damp_pitch));
212 if (damp_heading > 0.0)
213 _damp_heading = 1.0 / pow(10.0, fabs(damp_heading));
215 _x_offset_m = x_offset_m;
216 _y_offset_m = y_offset_m;
217 _z_offset_m = z_offset_m;
218 _heading_offset_deg = heading_offset_deg;
219 _pitch_offset_deg = pitch_offset_deg;
220 _roll_offset_deg = roll_offset_deg;
221 _goal_heading_offset_deg = heading_offset_deg;
222 _goal_pitch_offset_deg = pitch_offset_deg;
223 _goal_roll_offset_deg = roll_offset_deg;
229 _aspect_ratio_multiplier = aspect_ratio_multiplier;
230 _target_x_offset_m = target_x_offset_m;
231 _target_y_offset_m = target_y_offset_m;
232 _target_z_offset_m = target_z_offset_m;
233 _ground_level_nearplane_m = near_m;
234 // a reasonable guess for init, so that the math doesn't blow up
239 FGViewer::~FGViewer( void ) {
246 _location = (SGLocation *) globals->get_aircraft_model()->get3DModel()->getSGLocation();
248 _location = (SGLocation *) new SGLocation;
250 if ( _type == FG_LOOKAT ) {
252 _target_location = (SGLocation *) globals->get_aircraft_model()->get3DModel()->getSGLocation();
254 _target_location = (SGLocation *) new SGLocation;
269 FGViewer::setType ( int type )
278 FGViewer::setInternal ( bool internal )
280 _internal = internal;
284 FGViewer::setLongitude_deg (double lon_deg)
291 FGViewer::setLatitude_deg (double lat_deg)
298 FGViewer::setAltitude_ft (double alt_ft)
305 FGViewer::setPosition (double lon_deg, double lat_deg, double alt_ft)
314 FGViewer::setTargetLongitude_deg (double lon_deg)
317 _target_lon_deg = lon_deg;
321 FGViewer::setTargetLatitude_deg (double lat_deg)
324 _target_lat_deg = lat_deg;
328 FGViewer::setTargetAltitude_ft (double alt_ft)
331 _target_alt_ft = alt_ft;
335 FGViewer::setTargetPosition (double lon_deg, double lat_deg, double alt_ft)
338 _target_lon_deg = lon_deg;
339 _target_lat_deg = lat_deg;
340 _target_alt_ft = alt_ft;
344 FGViewer::setRoll_deg (double roll_deg)
347 _roll_deg = roll_deg;
351 FGViewer::setPitch_deg (double pitch_deg)
354 _pitch_deg = pitch_deg;
358 FGViewer::setHeading_deg (double heading_deg)
361 _heading_deg = heading_deg;
365 FGViewer::setOrientation (double roll_deg, double pitch_deg, double heading_deg)
368 _roll_deg = roll_deg;
369 _pitch_deg = pitch_deg;
370 _heading_deg = heading_deg;
374 FGViewer::setTargetRoll_deg (double target_roll_deg)
377 _target_roll_deg = target_roll_deg;
381 FGViewer::setTargetPitch_deg (double target_pitch_deg)
384 _target_pitch_deg = target_pitch_deg;
388 FGViewer::setTargetHeading_deg (double target_heading_deg)
391 _target_heading_deg = target_heading_deg;
395 FGViewer::setTargetOrientation (double target_roll_deg, double target_pitch_deg, double target_heading_deg)
398 _target_roll_deg = target_roll_deg;
399 _target_pitch_deg = target_pitch_deg;
400 _target_heading_deg = target_heading_deg;
404 FGViewer::setXOffset_m (double x_offset_m)
407 _x_offset_m = x_offset_m;
411 FGViewer::setYOffset_m (double y_offset_m)
414 _y_offset_m = y_offset_m;
418 FGViewer::setZOffset_m (double z_offset_m)
421 _z_offset_m = z_offset_m;
425 FGViewer::setTargetXOffset_m (double target_x_offset_m)
428 _target_x_offset_m = target_x_offset_m;
432 FGViewer::setTargetYOffset_m (double target_y_offset_m)
435 _target_y_offset_m = target_y_offset_m;
439 FGViewer::setTargetZOffset_m (double target_z_offset_m)
442 _target_z_offset_m = target_z_offset_m;
446 FGViewer::setPositionOffsets (double x_offset_m, double y_offset_m, double z_offset_m)
449 _x_offset_m = x_offset_m;
450 _y_offset_m = y_offset_m;
451 _z_offset_m = z_offset_m;
455 FGViewer::setRollOffset_deg (double roll_offset_deg)
458 _roll_offset_deg = roll_offset_deg;
462 FGViewer::setPitchOffset_deg (double pitch_offset_deg)
465 _pitch_offset_deg = pitch_offset_deg;
469 FGViewer::setHeadingOffset_deg (double heading_offset_deg)
472 _heading_offset_deg = heading_offset_deg;
476 FGViewer::setGoalRollOffset_deg (double goal_roll_offset_deg)
479 _goal_roll_offset_deg = goal_roll_offset_deg;
483 FGViewer::setGoalPitchOffset_deg (double goal_pitch_offset_deg)
486 _goal_pitch_offset_deg = goal_pitch_offset_deg;
487 if ( _goal_pitch_offset_deg < -90 ) {
488 _goal_pitch_offset_deg = -90.0;
490 if ( _goal_pitch_offset_deg > 90.0 ) {
491 _goal_pitch_offset_deg = 90.0;
497 FGViewer::setGoalHeadingOffset_deg (double goal_heading_offset_deg)
500 _goal_heading_offset_deg = goal_heading_offset_deg;
501 while ( _goal_heading_offset_deg < 0.0 ) {
502 _goal_heading_offset_deg += 360;
504 while ( _goal_heading_offset_deg > 360 ) {
505 _goal_heading_offset_deg -= 360;
510 FGViewer::setOrientationOffsets (double roll_offset_deg, double pitch_offset_deg, double heading_offset_deg)
513 _roll_offset_deg = roll_offset_deg;
514 _pitch_offset_deg = pitch_offset_deg;
515 _heading_offset_deg = heading_offset_deg;
519 FGViewer::get_absolute_view_pos ()
523 return _absolute_view_pos;
527 FGViewer::getRelativeViewPos ()
531 return _relative_view_pos;
535 FGViewer::getZeroElevViewPos ()
539 return _zero_elev_view_pos;
543 FGViewer::updateFromModelLocation (SGLocation * location)
545 sgCopyMat4(LOCAL, location->getCachedTransformMatrix());
549 FGViewer::updateAtModelLocation (SGLocation * location)
552 location->getCachedTransformMatrix());
556 FGViewer::recalcOurOwnLocation (SGLocation * location, double lon_deg, double lat_deg, double alt_ft,
557 double roll_deg, double pitch_deg, double heading_deg)
559 // update from our own data...
560 dampEyeData(roll_deg, pitch_deg, heading_deg);
561 location->setPosition( lon_deg, lat_deg, alt_ft );
562 location->setOrientation( roll_deg, pitch_deg, heading_deg );
564 location->getTransformMatrix(globals->get_scenery()->get_center()));
567 // recalc() is done every time one of the setters is called (making the
568 // cached data "dirty") on the next "get". It calculates all the outputs
573 if (_type == FG_LOOKFROM) {
582 // recalculate for LookFrom view type...
584 FGViewer::recalcLookFrom ()
587 sgVec3 right, forward;
589 sgVec3 position_offset; // eye position offsets (xyz)
593 // Update location data...
595 // update or data from model location
596 updateFromModelLocation(_location);
598 // update from our own data...
599 recalcOurOwnLocation( _location, _lon_deg, _lat_deg, _alt_ft,
600 _roll_deg, _pitch_deg, _heading_deg );
603 // copy data from location class to local items...
606 // make sg vectors view up, right and forward vectors from LOCAL
607 sgSetVec3( _view_up, LOCAL[2][0], LOCAL[2][1], LOCAL[2][2] );
608 sgSetVec3( right, LOCAL[1][0], LOCAL[1][1], LOCAL[1][2] );
609 sgSetVec3( forward, -LOCAL[0][0], -LOCAL[0][1], -LOCAL[0][2] );
611 // Note that when in "lookfrom" view the "view up" vector is always applied
612 // to the viewer. View up is based on verticle of the aircraft itself. (see
613 // "LOCAL" matrix above)
615 // Orientation Offsets matrix
616 MakeVIEW_OFFSET( VIEW_OFFSET,
617 _heading_offset_deg * SG_DEGREES_TO_RADIANS, _view_up,
618 _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right,
619 _roll_offset_deg * SG_DEGREES_TO_RADIANS, forward );
621 // Make the VIEW matrix.
622 sgSetVec4(VIEW[0], right[0], right[1], right[2],SG_ZERO);
623 sgSetVec4(VIEW[1], forward[0], forward[1], forward[2],SG_ZERO);
624 sgSetVec4(VIEW[2], _view_up[0], _view_up[1], _view_up[2],SG_ZERO);
625 sgSetVec4(VIEW[3], SG_ZERO, SG_ZERO, SG_ZERO,SG_ONE);
627 // rotate model or local matrix to get a matrix to apply Eye Position Offsets
628 sgMat4 VIEW_UP; // L0 forward L1 right L2 up
629 sgCopyVec4(VIEW_UP[0], LOCAL[1]);
630 sgCopyVec4(VIEW_UP[1], LOCAL[2]);
631 sgCopyVec4(VIEW_UP[2], LOCAL[0]);
632 sgZeroVec4(VIEW_UP[3]);
634 // Eye Position Offsets to vector
635 sgSetVec3( position_offset, _x_offset_m, _y_offset_m, _z_offset_m );
636 sgXformVec3( position_offset, position_offset, VIEW_UP);
638 // add the offsets including rotations to the translation vector
639 sgAddVec3( _view_pos, position_offset );
641 // multiply the OFFSETS (for heading and pitch) into the VIEW
642 sgPostMultMat4(VIEW, VIEW_OFFSET);
644 // add the position data to the matrix
645 sgSetVec4(VIEW[3], _view_pos[0], _view_pos[1], _view_pos[2],SG_ONE);
650 FGViewer::recalcLookAt ()
653 sgVec3 right, forward;
654 sgVec3 eye_pos, at_pos;
655 sgVec3 position_offset; // eye position offsets (xyz)
656 sgVec3 target_position_offset; // target position offsets (xyz)
658 // The position vectors originate from the view point or target location
659 // depending on the type of view.
663 // Update location data for target...
665 // update or data from model location
666 updateAtModelLocation(_target_location);
668 // if not model then calculate our own target position...
669 recalcOurOwnLocation( _target_location, _target_lon_deg, _target_lat_deg, _target_alt_ft,
670 _target_roll_deg, _target_pitch_deg, _target_heading_deg );
672 // calculate the "at" target object positon relative to eye or view's tile center...
674 sgdSetVec3(dVec3, _location->get_tile_center()[0], _location->get_tile_center()[1], _location->get_tile_center()[2]);
676 _target_location->get_absolute_view_pos(globals->get_scenery()->get_center()),
678 sgSetVec3(at_pos, dVec3[0], dVec3[1], dVec3[2]);
680 // Update location data for eye...
682 // update or data from model location
683 updateFromModelLocation(_location);
685 // update from our own data, just the rotation here...
686 recalcOurOwnLocation( _location, _lon_deg, _lat_deg, _alt_ft,
687 _roll_deg, _pitch_deg, _heading_deg );
689 // save the eye positon...
690 sgCopyVec3(eye_pos, _location->get_view_pos());
692 // copy data from location class to local items...
695 // make sg vectors view up, right and forward vectors from LOCAL
696 sgSetVec3( _view_up, LOCAL[2][0], LOCAL[2][1], LOCAL[2][2] );
697 sgSetVec3( right, LOCAL[1][0], LOCAL[1][1], LOCAL[1][2] );
698 sgSetVec3( forward, -LOCAL[0][0], -LOCAL[0][1], -LOCAL[0][2] );
700 // rotate model or local matrix to get a matrix to apply Eye Position Offsets
701 sgMat4 VIEW_UP; // L0 forward L1 right L2 up
702 sgCopyVec4(VIEW_UP[0], LOCAL[1]);
703 sgCopyVec4(VIEW_UP[1], LOCAL[2]);
704 sgCopyVec4(VIEW_UP[2], LOCAL[0]);
705 sgZeroVec4(VIEW_UP[3]);
707 // get Orientation Offsets matrix
708 MakeVIEW_OFFSET( VIEW_OFFSET,
709 (_heading_offset_deg - 180) * SG_DEGREES_TO_RADIANS, _view_up,
710 _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right,
711 _roll_offset_deg * SG_DEGREES_TO_RADIANS, forward );
713 // add in the position offsets
714 sgSetVec3( position_offset, _y_offset_m, _x_offset_m, _z_offset_m );
715 sgXformVec3( position_offset, position_offset, VIEW_UP);
717 // apply the Orientation offsets
718 sgXformVec3( position_offset, position_offset, VIEW_OFFSET );
720 // add the Position offsets from object to the eye position
721 sgAddVec3( eye_pos, eye_pos, position_offset );
723 // add target offsets to at_position...
724 sgSetVec3(target_position_offset, _target_z_offset_m, _target_x_offset_m,
725 _target_y_offset_m );
726 sgXformVec3(target_position_offset, target_position_offset, ATLOCAL);
727 sgAddVec3( at_pos, at_pos, target_position_offset);
729 sgAddVec3( eye_pos, eye_pos, target_position_offset);
731 // Make the VIEW matrix for a "LOOKAT".
732 sgMakeLookAtMat4( VIEW, eye_pos, at_pos, _view_up );
736 // copy results from location class to viewer...
737 // FIXME: some of these should be changed to reference directly to SGLocation...
739 FGViewer::copyLocationData()
741 // Get our friendly vectors from the eye location...
742 sgCopyVec3(_zero_elev_view_pos, _location->get_zero_elev());
743 sgCopyVec3(_relative_view_pos, _location->get_view_pos());
744 sgdCopyVec3(_absolute_view_pos,
745 _location->get_absolute_view_pos(globals->get_scenery()->get_center()));
746 sgCopyMat4(UP, _location->getCachedUpMatrix());
747 sgCopyVec3(_world_up, _location->get_world_up());
748 // these are the vectors that the sun and moon code like to get...
749 sgCopyVec3(_surface_east, _location->get_surface_east());
750 sgCopyVec3(_surface_south, _location->get_surface_south());
752 // Update viewer's postion data for the eye location...
753 _lon_deg = _location->getLongitude_deg();
754 _lat_deg = _location->getLatitude_deg();
755 _alt_ft = _location->getAltitudeASL_ft();
756 _roll_deg = _location->getRoll_deg();
757 _pitch_deg = _location->getPitch_deg();
758 _heading_deg = _location->getHeading_deg();
760 // Update viewer's postion data for the target (at object) location
761 if (_type == FG_LOOKAT) {
762 _target_lon_deg = _target_location->getLongitude_deg();
763 _target_lat_deg = _target_location->getLatitude_deg();
764 _target_alt_ft = _target_location->getAltitudeASL_ft();
765 _target_roll_deg = _target_location->getRoll_deg();
766 _target_pitch_deg = _target_location->getPitch_deg();
767 _target_heading_deg = _target_location->getHeading_deg();
770 // copy coordinates to outputs for viewer...
771 sgCopyVec3(_zero_elev, _zero_elev_view_pos);
772 sgCopyVec3(_view_pos, _relative_view_pos);
776 FGViewer::dampEyeData (double &roll_deg, double &pitch_deg, double &heading_deg)
778 const double interval = 0.01;
780 static FGViewer *last_view = 0;
781 if (last_view != this) {
783 _damped_roll_deg = roll_deg;
784 _damped_pitch_deg = pitch_deg;
785 _damped_heading_deg = heading_deg;
790 if (_damp_sync < interval) {
791 if (_damp_roll > 0.0)
792 roll_deg = _damped_roll_deg;
793 if (_damp_pitch > 0.0)
794 pitch_deg = _damped_pitch_deg;
795 if (_damp_heading > 0.0)
796 heading_deg = _damped_heading_deg;
800 while (_damp_sync >= interval) {
801 _damp_sync -= interval;
804 if (_damp_roll > 0.0) {
805 d = _damped_roll_deg - roll_deg;
807 _damped_roll_deg -= 360.0;
809 _damped_roll_deg += 360.0;
810 roll_deg = _damped_roll_deg = roll_deg * _damp_roll + _damped_roll_deg * (1 - _damp_roll);
813 if (_damp_pitch > 0.0) {
814 d = _damped_pitch_deg - pitch_deg;
816 _damped_pitch_deg -= 360.0;
818 _damped_pitch_deg += 360.0;
819 pitch_deg = _damped_pitch_deg = pitch_deg * _damp_pitch + _damped_pitch_deg * (1 - _damp_pitch);
822 if (_damp_heading > 0.0) {
823 d = _damped_heading_deg - heading_deg;
825 _damped_heading_deg -= 360.0;
827 _damped_heading_deg += 360.0;
828 heading_deg = _damped_heading_deg = heading_deg * _damp_heading + _damped_heading_deg * (1 - _damp_heading);
834 FGViewer::get_h_fov()
836 switch (_scaling_type) {
837 case FG_SCALING_WIDTH: // h_fov == fov
840 if (_aspect_ratio < 1.0) {
846 atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
847 / (_aspect_ratio*_aspect_ratio_multiplier))
848 * SG_RADIANS_TO_DEGREES * 2;
859 FGViewer::get_v_fov()
861 switch (_scaling_type) {
862 case FG_SCALING_WIDTH: // h_fov == fov
864 atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
865 * (_aspect_ratio*_aspect_ratio_multiplier))
866 * SG_RADIANS_TO_DEGREES * 2;
868 if (_aspect_ratio < 1.0) {
871 atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
872 * (_aspect_ratio*_aspect_ratio_multiplier))
873 * SG_RADIANS_TO_DEGREES * 2;
885 FGViewer::update (double dt)
890 int dt_ms = int(dt * 1000);
891 for ( i = 0; i < dt_ms; i++ ) {
892 if ( fabs( _goal_heading_offset_deg - _heading_offset_deg) < 1 ) {
893 setHeadingOffset_deg( _goal_heading_offset_deg );
896 // move current_view.headingoffset towards
897 // current_view.goal_view_offset
898 if ( _goal_heading_offset_deg > _heading_offset_deg )
900 if ( _goal_heading_offset_deg - _heading_offset_deg < 180 ){
901 incHeadingOffset_deg( 0.5 );
903 incHeadingOffset_deg( -0.5 );
906 if ( _heading_offset_deg - _goal_heading_offset_deg < 180 ){
907 incHeadingOffset_deg( -0.5 );
909 incHeadingOffset_deg( 0.5 );
912 if ( _heading_offset_deg > 360 ) {
913 incHeadingOffset_deg( -360 );
914 } else if ( _heading_offset_deg < 0 ) {
915 incHeadingOffset_deg( 360 );
920 for ( i = 0; i < dt_ms; i++ ) {
921 if ( fabs( _goal_pitch_offset_deg - _pitch_offset_deg ) < 1 ) {
922 setPitchOffset_deg( _goal_pitch_offset_deg );
925 // move current_view.pitch_offset_deg towards
926 // current_view.goal_pitch_offset
927 if ( _goal_pitch_offset_deg > _pitch_offset_deg )
929 incPitchOffset_deg( 1.0 );
931 incPitchOffset_deg( -1.0 );
933 if ( _pitch_offset_deg > 90 ) {
934 setPitchOffset_deg(90);
935 } else if ( _pitch_offset_deg < -90 ) {
936 setPitchOffset_deg( -90 );
942 for ( i = 0; i < dt_ms; i++ ) {
943 if ( fabs( _goal_roll_offset_deg - _roll_offset_deg ) < 1 ) {
944 setRollOffset_deg( _goal_roll_offset_deg );
947 // move current_view.roll_offset_deg towards
948 // current_view.goal_roll_offset
949 if ( _goal_roll_offset_deg > _roll_offset_deg )
951 incRollOffset_deg( 1.0 );
953 incRollOffset_deg( -1.0 );
955 if ( _roll_offset_deg > 90 ) {
956 setRollOffset_deg(90);
957 } else if ( _roll_offset_deg < -90 ) {
958 setRollOffset_deg( -90 );