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.
6 // Copyright (C) 1997 - 2000 Curtis L. Olson - curt@flightgear.org
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <simgear/compiler.h>
31 #include <simgear/debug/logstream.hxx>
32 #include <simgear/constants.h>
38 FGViewer::FGViewer( void ):
41 goal_view_offset(0.0),
45 sgSetVec3( pilot_offset, 0.0, 0.0, 0.0 );
46 sgdZeroVec3(geod_view_pos);
47 sgdZeroVec3(abs_view_pos);
48 sea_level_radius = SG_EQUATORIAL_RADIUS_M;
49 //a reasonable guess for init, so that the math doesn't blow up
53 // Update the view parameters
54 void FGViewer::update() {
55 SG_LOG( SG_VIEW, SG_ALERT, "Shouldn't ever see this" );
60 FGViewer::~FGViewer( void ) {
79 FGViewer::update (int dt)
81 for ( int i = 0; i < dt; i++ ) {
82 if ( fabs(get_goal_view_offset() - get_view_offset()) < 0.05 ) {
83 set_view_offset( get_goal_view_offset() );
86 // move current_view.view_offset towards
87 // current_view.goal_view_offset
88 if ( get_goal_view_offset() > get_view_offset() )
90 if ( get_goal_view_offset() - get_view_offset() < SGD_PI ){
91 inc_view_offset( 0.01 );
93 inc_view_offset( -0.01 );
96 if ( get_view_offset() - get_goal_view_offset() < SGD_PI ){
97 inc_view_offset( -0.01 );
99 inc_view_offset( 0.01 );
102 if ( get_view_offset() > SGD_2PI ) {
103 inc_view_offset( -SGD_2PI );
104 } else if ( get_view_offset() < 0 ) {
105 inc_view_offset( SGD_2PI );
110 for ( int i = 0; i < dt; i++ ) {
111 if ( fabs(get_goal_view_tilt() - get_view_tilt()) < 0.05 ) {
112 set_view_tilt( get_goal_view_tilt() );
115 // move current_view.view_tilt towards
116 // current_view.goal_view_tilt
117 if ( get_goal_view_tilt() > get_view_tilt() )
119 if ( get_goal_view_tilt() - get_view_tilt() < SGD_PI ){
120 inc_view_tilt( 0.01 );
122 inc_view_tilt( -0.01 );
125 if ( get_view_tilt() - get_goal_view_tilt() < SGD_PI ){
126 inc_view_tilt( -0.01 );
128 inc_view_tilt( 0.01 );
131 if ( get_view_tilt() > SGD_2PI ) {
132 inc_view_tilt( -SGD_2PI );
133 } else if ( get_view_tilt() < 0 ) {
134 inc_view_tilt( SGD_2PI );