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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <simgear/compiler.h>
32 #include "fg_props.hxx"
38 #include <simgear/debug/logstream.hxx>
39 #include <simgear/constants.h>
40 #include <simgear/math/point3d.hxx>
41 #include <simgear/math/polar3d.hxx>
42 #include <simgear/math/sg_geodesy.hxx>
43 #include <simgear/scene/model/location.hxx>
44 #include <simgear/scene/model/placement.hxx>
45 #include <simgear/math/vector.hxx>
47 #include <Main/globals.hxx>
48 #include <Scenery/scenery.hxx>
49 #include <Model/acmodel.hxx>
54 //////////////////////////////////////////////////////////////////
55 // Norman's Optimized matrix rotators! //
56 //////////////////////////////////////////////////////////////////
59 // Since these are pure rotation matrices we can save some bookwork
60 // by considering them to be 3x3 until the very end -- NHV
61 static void MakeVIEW_OFFSET( sgMat4 dst,
62 const float angle1, const sgVec3 axis1,
63 const float angle2, const sgVec3 axis2,
64 const float angle3, const sgVec3 axis3 )
66 // make rotmatrix1 from angle and axis
67 float s = (float) sin ( angle1 ) ;
68 float c = (float) cos ( angle1 ) ;
69 float t = SG_ONE - c ;
72 float tmp = t * axis1[0];
73 mat1[0][0] = tmp * axis1[0] + c ;
74 mat1[0][1] = tmp * axis1[1] + s * axis1[2] ;
75 mat1[0][2] = tmp * axis1[2] - s * axis1[1] ;
78 mat1[1][0] = tmp * axis1[0] - s * axis1[2] ;
79 mat1[1][1] = tmp * axis1[1] + c ;
80 mat1[1][2] = tmp * axis1[2] + s * axis1[0] ;
83 mat1[2][0] = tmp * axis1[0] + s * axis1[1] ;
84 mat1[2][1] = tmp * axis1[1] - s * axis1[0] ;
85 mat1[2][2] = tmp * axis1[2] + c ;
87 // make rotmatrix2 from angle and axis
88 s = (float) sin ( angle2 ) ;
89 c = (float) cos ( angle2 ) ;
94 mat2[0][0] = tmp * axis2[0] + c ;
95 mat2[0][1] = tmp * axis2[1] + s * axis2[2] ;
96 mat2[0][2] = tmp * axis2[2] - s * axis2[1] ;
99 mat2[1][0] = tmp * axis2[0] - s * axis2[2] ;
100 mat2[1][1] = tmp * axis2[1] + c ;
101 mat2[1][2] = tmp * axis2[2] + s * axis2[0] ;
104 mat2[2][0] = tmp * axis2[0] + s * axis2[1] ;
105 mat2[2][1] = tmp * axis2[1] - s * axis2[0] ;
106 mat2[2][2] = tmp * axis2[2] + c ;
109 // make rotmatrix3 from angle and axis (roll)
110 s = (float) sin ( angle3 ) ;
111 c = (float) cos ( angle3 ) ;
116 mat3[0][0] = tmp * axis3[0] + c ;
117 mat3[0][1] = tmp * axis3[1] + s * axis3[2] ;
118 mat3[0][2] = tmp * axis3[2] - s * axis3[1] ;
121 mat3[1][0] = tmp * axis3[0] - s * axis3[2] ;
122 mat3[1][1] = tmp * axis3[1] + c ;
123 mat3[1][2] = tmp * axis3[2] + s * axis3[0] ;
126 mat3[2][0] = tmp * axis3[0] + s * axis3[1] ;
127 mat3[2][1] = tmp * axis3[1] - s * axis3[0] ;
128 mat3[2][2] = tmp * axis3[2] + c ;
133 for ( int j = 0 ; j < 3 ; j++ ) {
134 matt[0][j] = mat2[0][0] * mat1[0][j] +
135 mat2[0][1] * mat1[1][j] +
136 mat2[0][2] * mat1[2][j];
138 matt[1][j] = mat2[1][0] * mat1[0][j] +
139 mat2[1][1] * mat1[1][j] +
140 mat2[1][2] * mat1[2][j];
142 matt[2][j] = mat2[2][0] * mat1[0][j] +
143 mat2[2][1] * mat1[1][j] +
144 mat2[2][2] * mat1[2][j];
148 for ( int j = 0 ; j < 3 ; j++ ) {
149 dst[0][j] = mat3[0][0] * matt[0][j] +
150 mat3[0][1] * matt[1][j] +
151 mat3[0][2] * matt[2][j];
153 dst[1][j] = mat3[1][0] * matt[0][j] +
154 mat3[1][1] * matt[1][j] +
155 mat3[1][2] * matt[2][j];
157 dst[2][j] = mat3[2][0] * matt[0][j] +
158 mat3[2][1] * matt[1][j] +
159 mat3[2][2] * matt[2][j];
161 // fill in 4x4 matrix elements
172 ////////////////////////////////////////////////////////////////////////
173 // Implementation of FGViewer.
174 ////////////////////////////////////////////////////////////////////////
177 FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
178 bool at_model, int at_model_index,
179 double damp_roll, double damp_pitch, double damp_heading,
180 double x_offset_m, double y_offset_m, double z_offset_m,
181 double heading_offset_deg, double pitch_offset_deg,
182 double roll_offset_deg,
183 double fov_deg, double aspect_ratio_multiplier,
184 double target_x_offset_m, double target_y_offset_m,
185 double target_z_offset_m, double near_m, bool internal ):
200 _scaling_type(FG_SCALING_MAX)
202 sgdZeroVec3(_absolute_view_pos);
204 _from_model = from_model;
205 _from_model_index = from_model_index;
206 _at_model = at_model;
207 _at_model_index = at_model_index;
209 _internal = internal;
212 _damp_roll = 1.0 / pow(10.0, fabs(damp_roll));
213 if (damp_pitch > 0.0)
214 _damp_pitch = 1.0 / pow(10.0, fabs(damp_pitch));
215 if (damp_heading > 0.0)
216 _damp_heading = 1.0 / pow(10.0, fabs(damp_heading));
218 _x_offset_m = x_offset_m;
219 _y_offset_m = y_offset_m;
220 _z_offset_m = z_offset_m;
221 _heading_offset_deg = heading_offset_deg;
222 _pitch_offset_deg = pitch_offset_deg;
223 _roll_offset_deg = roll_offset_deg;
224 _goal_heading_offset_deg = heading_offset_deg;
225 _goal_pitch_offset_deg = pitch_offset_deg;
226 _goal_roll_offset_deg = roll_offset_deg;
232 _aspect_ratio_multiplier = aspect_ratio_multiplier;
233 _target_x_offset_m = target_x_offset_m;
234 _target_y_offset_m = target_y_offset_m;
235 _target_z_offset_m = target_z_offset_m;
236 _ground_level_nearplane_m = near_m;
237 // a reasonable guess for init, so that the math doesn't blow up
242 FGViewer::~FGViewer( void ) {
249 _location = (SGLocation *) globals->get_aircraft_model()->get3DModel()->getSGLocation();
251 _location = (SGLocation *) new SGLocation;
253 if ( _type == FG_LOOKAT ) {
255 _target_location = (SGLocation *) globals->get_aircraft_model()->get3DModel()->getSGLocation();
257 _target_location = (SGLocation *) new SGLocation;
272 FGViewer::setType ( int type )
281 FGViewer::setInternal ( bool internal )
283 _internal = internal;
287 FGViewer::setLongitude_deg (double lon_deg)
294 FGViewer::setLatitude_deg (double lat_deg)
301 FGViewer::setAltitude_ft (double alt_ft)
308 FGViewer::setPosition (double lon_deg, double lat_deg, double alt_ft)
317 FGViewer::setTargetLongitude_deg (double lon_deg)
320 _target_lon_deg = lon_deg;
324 FGViewer::setTargetLatitude_deg (double lat_deg)
327 _target_lat_deg = lat_deg;
331 FGViewer::setTargetAltitude_ft (double alt_ft)
334 _target_alt_ft = alt_ft;
338 FGViewer::setTargetPosition (double lon_deg, double lat_deg, double alt_ft)
341 _target_lon_deg = lon_deg;
342 _target_lat_deg = lat_deg;
343 _target_alt_ft = alt_ft;
347 FGViewer::setRoll_deg (double roll_deg)
350 _roll_deg = roll_deg;
354 FGViewer::setPitch_deg (double pitch_deg)
357 _pitch_deg = pitch_deg;
361 FGViewer::setHeading_deg (double heading_deg)
364 _heading_deg = heading_deg;
368 FGViewer::setOrientation (double roll_deg, double pitch_deg, double heading_deg)
371 _roll_deg = roll_deg;
372 _pitch_deg = pitch_deg;
373 _heading_deg = heading_deg;
377 FGViewer::setTargetRoll_deg (double target_roll_deg)
380 _target_roll_deg = target_roll_deg;
384 FGViewer::setTargetPitch_deg (double target_pitch_deg)
387 _target_pitch_deg = target_pitch_deg;
391 FGViewer::setTargetHeading_deg (double target_heading_deg)
394 _target_heading_deg = target_heading_deg;
398 FGViewer::setTargetOrientation (double target_roll_deg, double target_pitch_deg, double target_heading_deg)
401 _target_roll_deg = target_roll_deg;
402 _target_pitch_deg = target_pitch_deg;
403 _target_heading_deg = target_heading_deg;
407 FGViewer::setXOffset_m (double x_offset_m)
410 _x_offset_m = x_offset_m;
414 FGViewer::setYOffset_m (double y_offset_m)
417 _y_offset_m = y_offset_m;
421 FGViewer::setZOffset_m (double z_offset_m)
424 _z_offset_m = z_offset_m;
428 FGViewer::setTargetXOffset_m (double target_x_offset_m)
431 _target_x_offset_m = target_x_offset_m;
435 FGViewer::setTargetYOffset_m (double target_y_offset_m)
438 _target_y_offset_m = target_y_offset_m;
442 FGViewer::setTargetZOffset_m (double target_z_offset_m)
445 _target_z_offset_m = target_z_offset_m;
449 FGViewer::setPositionOffsets (double x_offset_m, double y_offset_m, double z_offset_m)
452 _x_offset_m = x_offset_m;
453 _y_offset_m = y_offset_m;
454 _z_offset_m = z_offset_m;
458 FGViewer::setRollOffset_deg (double roll_offset_deg)
461 _roll_offset_deg = roll_offset_deg;
465 FGViewer::setPitchOffset_deg (double pitch_offset_deg)
468 _pitch_offset_deg = pitch_offset_deg;
472 FGViewer::setHeadingOffset_deg (double heading_offset_deg)
475 _heading_offset_deg = heading_offset_deg;
479 FGViewer::setGoalRollOffset_deg (double goal_roll_offset_deg)
482 _goal_roll_offset_deg = goal_roll_offset_deg;
486 FGViewer::setGoalPitchOffset_deg (double goal_pitch_offset_deg)
489 _goal_pitch_offset_deg = goal_pitch_offset_deg;
490 if ( _goal_pitch_offset_deg < -90 ) {
491 _goal_pitch_offset_deg = -90.0;
493 if ( _goal_pitch_offset_deg > 90.0 ) {
494 _goal_pitch_offset_deg = 90.0;
500 FGViewer::setGoalHeadingOffset_deg (double goal_heading_offset_deg)
503 _goal_heading_offset_deg = goal_heading_offset_deg;
504 while ( _goal_heading_offset_deg < 0.0 ) {
505 _goal_heading_offset_deg += 360;
507 while ( _goal_heading_offset_deg > 360 ) {
508 _goal_heading_offset_deg -= 360;
513 FGViewer::setOrientationOffsets (double roll_offset_deg, double pitch_offset_deg, double heading_offset_deg)
516 _roll_offset_deg = roll_offset_deg;
517 _pitch_offset_deg = pitch_offset_deg;
518 _heading_offset_deg = heading_offset_deg;
522 FGViewer::get_absolute_view_pos ()
526 return _absolute_view_pos;
530 FGViewer::getRelativeViewPos ()
534 return _relative_view_pos;
538 FGViewer::updateFromModelLocation (SGLocation * location)
540 sgCopyMat4(LOCAL, location->getTransformMatrix());
544 FGViewer::updateAtModelLocation (SGLocation * location)
546 sgCopyMat4(ATLOCAL, location->getTransformMatrix());
550 FGViewer::recalcOurOwnLocation (SGLocation * location, double lon_deg, double lat_deg, double alt_ft,
551 double roll_deg, double pitch_deg, double heading_deg)
553 // update from our own data...
554 dampEyeData(roll_deg, pitch_deg, heading_deg);
555 location->setPosition( lon_deg, lat_deg, alt_ft );
556 location->setOrientation( roll_deg, pitch_deg, heading_deg );
557 sgCopyMat4(LOCAL, location->getTransformMatrix());
560 // recalc() is done every time one of the setters is called (making the
561 // cached data "dirty") on the next "get". It calculates all the outputs
566 if (_type == FG_LOOKFROM) {
575 // recalculate for LookFrom view type...
577 FGViewer::recalcLookFrom ()
579 sgVec3 right, forward;
580 sgVec3 position_offset; // eye position offsets (xyz)
584 // Update location data...
586 // update or data from model location
587 updateFromModelLocation(_location);
589 // update from our own data...
590 recalcOurOwnLocation( _location, _lon_deg, _lat_deg, _alt_ft,
591 _roll_deg, _pitch_deg, _heading_deg );
594 // copy data from location class to local items...
597 // make sg vectors view up, right and forward vectors from LOCAL
598 sgSetVec3( _view_up, LOCAL[2][0], LOCAL[2][1], LOCAL[2][2] );
599 sgSetVec3( right, LOCAL[1][0], LOCAL[1][1], LOCAL[1][2] );
600 sgSetVec3( forward, -LOCAL[0][0], -LOCAL[0][1], -LOCAL[0][2] );
602 // Note that when in "lookfrom" view the "view up" vector is always applied
603 // to the viewer. View up is based on verticle of the aircraft itself. (see
604 // "LOCAL" matrix above)
606 // Orientation Offsets matrix
607 MakeVIEW_OFFSET( VIEW_OFFSET,
608 _heading_offset_deg * SG_DEGREES_TO_RADIANS, _view_up,
609 _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right,
610 _roll_offset_deg * SG_DEGREES_TO_RADIANS, forward );
612 // Make the VIEW matrix.
613 sgSetVec4(VIEW[0], right[0], right[1], right[2],SG_ZERO);
614 sgSetVec4(VIEW[1], forward[0], forward[1], forward[2],SG_ZERO);
615 sgSetVec4(VIEW[2], _view_up[0], _view_up[1], _view_up[2],SG_ZERO);
616 sgSetVec4(VIEW[3], SG_ZERO, SG_ZERO, SG_ZERO,SG_ONE);
618 // rotate model or local matrix to get a matrix to apply Eye Position Offsets
619 sgMat4 VIEW_UP; // L0 forward L1 right L2 up
620 sgCopyVec4(VIEW_UP[0], LOCAL[1]);
621 sgCopyVec4(VIEW_UP[1], LOCAL[2]);
622 sgCopyVec4(VIEW_UP[2], LOCAL[0]);
623 sgZeroVec4(VIEW_UP[3]);
625 // Eye Position Offsets to vector
626 sgSetVec3( position_offset, _x_offset_m, _y_offset_m, _z_offset_m );
627 sgXformVec3( position_offset, position_offset, VIEW_UP);
629 // add the offsets including rotations to the translation vector
630 sgAddVec3( _view_pos, position_offset );
632 // multiply the OFFSETS (for heading and pitch) into the VIEW
633 sgPostMultMat4(VIEW, VIEW_OFFSET);
635 // add the position data to the matrix
636 sgSetVec4(VIEW[3], _view_pos[0], _view_pos[1], _view_pos[2],SG_ONE);
641 FGViewer::recalcLookAt ()
643 sgVec3 right, forward;
644 sgVec3 eye_pos, at_pos;
645 sgVec3 position_offset; // eye position offsets (xyz)
646 sgVec3 target_position_offset; // target position offsets (xyz)
648 // The position vectors originate from the view point or target location
649 // depending on the type of view.
653 // Update location data for target...
655 // update or data from model location
656 updateAtModelLocation(_target_location);
658 // if not model then calculate our own target position...
659 recalcOurOwnLocation( _target_location, _target_lon_deg, _target_lat_deg, _target_alt_ft,
660 _target_roll_deg, _target_pitch_deg, _target_heading_deg );
662 // calculate the "at" target object positon relative to eye or view's tile center...
663 SGVec3d center = globals->get_scenery()->get_center();
665 sgdSetVec3(dVec3, center[0], center[1], center[2]);
666 sgdSubVec3(dVec3, _target_location->get_absolute_view_pos(), dVec3 );
667 sgSetVec3(at_pos, dVec3[0], dVec3[1], dVec3[2]);
669 // Update location data for eye...
671 // update or data from model location
672 updateFromModelLocation(_location);
674 // update from our own data, just the rotation here...
675 recalcOurOwnLocation( _location, _lon_deg, _lat_deg, _alt_ft,
676 _roll_deg, _pitch_deg, _heading_deg );
678 // save the eye positon...
679 sgCopyVec3(eye_pos, _location->get_view_pos(center));
681 // copy data from location class to local items...
684 // make sg vectors view up, right and forward vectors from LOCAL
685 sgSetVec3( _view_up, LOCAL[2][0], LOCAL[2][1], LOCAL[2][2] );
686 sgSetVec3( right, LOCAL[1][0], LOCAL[1][1], LOCAL[1][2] );
687 sgSetVec3( forward, -LOCAL[0][0], -LOCAL[0][1], -LOCAL[0][2] );
689 // rotate model or local matrix to get a matrix to apply Eye Position Offsets
690 sgMat4 VIEW_UP; // L0 forward L1 right L2 up
691 sgCopyVec4(VIEW_UP[0], LOCAL[1]);
692 sgCopyVec4(VIEW_UP[1], LOCAL[2]);
693 sgCopyVec4(VIEW_UP[2], LOCAL[0]);
694 sgZeroVec4(VIEW_UP[3]);
696 // get Orientation Offsets matrix
697 MakeVIEW_OFFSET( VIEW_OFFSET,
698 (_heading_offset_deg - 180) * SG_DEGREES_TO_RADIANS, _view_up,
699 _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right,
700 _roll_offset_deg * SG_DEGREES_TO_RADIANS, forward );
702 // add in the position offsets
703 sgSetVec3( position_offset, _y_offset_m, _x_offset_m, _z_offset_m );
704 sgXformVec3( position_offset, position_offset, VIEW_UP);
706 // apply the Orientation offsets
707 sgXformVec3( position_offset, position_offset, VIEW_OFFSET );
709 // add the Position offsets from object to the eye position
710 sgAddVec3( eye_pos, eye_pos, position_offset );
712 // add target offsets to at_position...
713 sgSetVec3(target_position_offset, _target_z_offset_m, _target_x_offset_m,
714 _target_y_offset_m );
715 sgXformVec3(target_position_offset, target_position_offset, ATLOCAL);
716 sgAddVec3( at_pos, at_pos, target_position_offset);
718 sgAddVec3( eye_pos, eye_pos, target_position_offset);
720 // Make the VIEW matrix for a "LOOKAT".
721 sgMakeLookAtMat4( VIEW, eye_pos, at_pos, _view_up );
725 // copy results from location class to viewer...
726 // FIXME: some of these should be changed to reference directly to SGLocation...
728 FGViewer::copyLocationData()
730 SGVec3d center = globals->get_scenery()->get_center();
731 // Get our friendly vectors from the eye location...
732 sgdCopyVec3(_absolute_view_pos, _location->get_absolute_view_pos());
733 sgCopyVec3(_relative_view_pos, _location->get_view_pos(center));
734 sgCopyMat4(UP, _location->getCachedUpMatrix());
735 sgCopyVec3(_world_up, _location->get_world_up());
736 // these are the vectors that the sun and moon code like to get...
737 sgCopyVec3(_surface_east, _location->get_surface_east());
738 sgCopyVec3(_surface_south, _location->get_surface_south());
740 // Update viewer's postion data for the eye location...
741 _lon_deg = _location->getLongitude_deg();
742 _lat_deg = _location->getLatitude_deg();
743 _alt_ft = _location->getAltitudeASL_ft();
744 _roll_deg = _location->getRoll_deg();
745 _pitch_deg = _location->getPitch_deg();
746 _heading_deg = _location->getHeading_deg();
748 // Update viewer's postion data for the target (at object) location
749 if (_type == FG_LOOKAT) {
750 _target_lon_deg = _target_location->getLongitude_deg();
751 _target_lat_deg = _target_location->getLatitude_deg();
752 _target_alt_ft = _target_location->getAltitudeASL_ft();
753 _target_roll_deg = _target_location->getRoll_deg();
754 _target_pitch_deg = _target_location->getPitch_deg();
755 _target_heading_deg = _target_location->getHeading_deg();
758 // copy coordinates to outputs for viewer...
759 sgCopyVec3(_zero_elev, _relative_view_pos);
760 sgAddScaledVec3(_zero_elev, _world_up, -_alt_ft*SG_FEET_TO_METER);
761 sgCopyVec3(_view_pos, _relative_view_pos);
765 FGViewer::dampEyeData (double &roll_deg, double &pitch_deg, double &heading_deg)
767 const double interval = 0.01;
769 static FGViewer *last_view = 0;
770 if (last_view != this) {
772 _damped_roll_deg = roll_deg;
773 _damped_pitch_deg = pitch_deg;
774 _damped_heading_deg = heading_deg;
779 if (_damp_sync < interval) {
780 if (_damp_roll > 0.0)
781 roll_deg = _damped_roll_deg;
782 if (_damp_pitch > 0.0)
783 pitch_deg = _damped_pitch_deg;
784 if (_damp_heading > 0.0)
785 heading_deg = _damped_heading_deg;
789 while (_damp_sync >= interval) {
790 _damp_sync -= interval;
793 if (_damp_roll > 0.0) {
794 d = _damped_roll_deg - roll_deg;
796 _damped_roll_deg -= 360.0;
798 _damped_roll_deg += 360.0;
799 roll_deg = _damped_roll_deg = roll_deg * _damp_roll + _damped_roll_deg * (1 - _damp_roll);
802 if (_damp_pitch > 0.0) {
803 d = _damped_pitch_deg - pitch_deg;
805 _damped_pitch_deg -= 360.0;
807 _damped_pitch_deg += 360.0;
808 pitch_deg = _damped_pitch_deg = pitch_deg * _damp_pitch + _damped_pitch_deg * (1 - _damp_pitch);
811 if (_damp_heading > 0.0) {
812 d = _damped_heading_deg - heading_deg;
814 _damped_heading_deg -= 360.0;
816 _damped_heading_deg += 360.0;
817 heading_deg = _damped_heading_deg = heading_deg * _damp_heading + _damped_heading_deg * (1 - _damp_heading);
823 FGViewer::get_h_fov()
825 switch (_scaling_type) {
826 case FG_SCALING_WIDTH: // h_fov == fov
829 if (_aspect_ratio < 1.0) {
835 atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
836 / (_aspect_ratio*_aspect_ratio_multiplier))
837 * SG_RADIANS_TO_DEGREES * 2;
848 FGViewer::get_v_fov()
850 switch (_scaling_type) {
851 case FG_SCALING_WIDTH: // h_fov == fov
853 atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
854 * (_aspect_ratio*_aspect_ratio_multiplier))
855 * SG_RADIANS_TO_DEGREES * 2;
857 if (_aspect_ratio < 1.0) {
860 atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
861 * (_aspect_ratio*_aspect_ratio_multiplier))
862 * SG_RADIANS_TO_DEGREES * 2;
874 FGViewer::update (double dt)
879 int dt_ms = int(dt * 1000);
880 for ( i = 0; i < dt_ms; i++ ) {
881 if ( fabs( _goal_heading_offset_deg - _heading_offset_deg) < 1 ) {
882 setHeadingOffset_deg( _goal_heading_offset_deg );
885 // move current_view.headingoffset towards
886 // current_view.goal_view_offset
887 if ( _goal_heading_offset_deg > _heading_offset_deg )
889 if ( _goal_heading_offset_deg - _heading_offset_deg < 180 ){
890 incHeadingOffset_deg( 0.5 );
892 incHeadingOffset_deg( -0.5 );
895 if ( _heading_offset_deg - _goal_heading_offset_deg < 180 ){
896 incHeadingOffset_deg( -0.5 );
898 incHeadingOffset_deg( 0.5 );
901 if ( _heading_offset_deg > 360 ) {
902 incHeadingOffset_deg( -360 );
903 } else if ( _heading_offset_deg < 0 ) {
904 incHeadingOffset_deg( 360 );
909 for ( i = 0; i < dt_ms; i++ ) {
910 if ( fabs( _goal_pitch_offset_deg - _pitch_offset_deg ) < 1 ) {
911 setPitchOffset_deg( _goal_pitch_offset_deg );
914 // move current_view.pitch_offset_deg towards
915 // current_view.goal_pitch_offset
916 if ( _goal_pitch_offset_deg > _pitch_offset_deg )
918 incPitchOffset_deg( 1.0 );
920 incPitchOffset_deg( -1.0 );
922 if ( _pitch_offset_deg > 90 ) {
923 setPitchOffset_deg(90);
924 } else if ( _pitch_offset_deg < -90 ) {
925 setPitchOffset_deg( -90 );
931 for ( i = 0; i < dt_ms; i++ ) {
932 if ( fabs( _goal_roll_offset_deg - _roll_offset_deg ) < 1 ) {
933 setRollOffset_deg( _goal_roll_offset_deg );
936 // move current_view.roll_offset_deg towards
937 // current_view.goal_roll_offset
938 if ( _goal_roll_offset_deg > _roll_offset_deg )
940 incRollOffset_deg( 1.0 );
942 incRollOffset_deg( -1.0 );
944 if ( _roll_offset_deg > 90 ) {
945 setRollOffset_deg(90);
946 } else if ( _roll_offset_deg < -90 ) {
947 setRollOffset_deg( -90 );