]> git.mxchange.org Git - flightgear.git/blob - src/Main/viewer.cxx
Variable "i" was multiply defined in two for loops.
[flightgear.git] / src / Main / viewer.cxx
1 // viewer.cxx -- class for managing a viewer in the flightgear world.
2 //
3 // Written by Curtis Olson, started August 1997.
4 //                          overhaul started October 2000.
5 //
6 // Copyright (C) 1997 - 2000  Curtis L. Olson  - curt@flightgear.org
7 //
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.
12 //
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.
17 //
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.
21 //
22 // $Id$
23
24
25 #include <simgear/compiler.h>
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #include <simgear/debug/logstream.hxx>
32 #include <simgear/constants.h>
33
34 #include "viewer.hxx"
35
36
37 // Constructor
38 FGViewer::FGViewer( void ):
39     fov(55.0),
40     view_offset(0.0),
41     goal_view_offset(0.0),
42     view_tilt(0.0),
43     goal_view_tilt(0.0)
44 {
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
50 }
51
52
53 // Update the view parameters
54 void FGViewer::update() {
55     SG_LOG( SG_VIEW, SG_ALERT, "Shouldn't ever see this" );
56 }
57
58
59 // Destructor
60 FGViewer::~FGViewer( void ) {
61 }
62
63 void
64 FGViewer::init ()
65 {
66 }
67
68 void
69 FGViewer::bind ()
70 {
71 }
72
73 void
74 FGViewer::unbind ()
75 {
76 }
77
78 void
79 FGViewer::update (int dt)
80 {
81   int i;
82   for ( i = 0; i < dt; i++ ) {
83     if ( fabs(get_goal_view_offset() - get_view_offset()) < 0.05 ) {
84       set_view_offset( get_goal_view_offset() );
85       break;
86     } else {
87       // move current_view.view_offset towards
88       // current_view.goal_view_offset
89       if ( get_goal_view_offset() > get_view_offset() )
90         {
91           if ( get_goal_view_offset() - get_view_offset() < SGD_PI ){
92             inc_view_offset( 0.01 );
93           } else {
94             inc_view_offset( -0.01 );
95           }
96         } else {
97           if ( get_view_offset() - get_goal_view_offset() < SGD_PI ){
98             inc_view_offset( -0.01 );
99           } else {
100             inc_view_offset( 0.01 );
101           }
102         }
103       if ( get_view_offset() > SGD_2PI ) {
104         inc_view_offset( -SGD_2PI );
105       } else if ( get_view_offset() < 0 ) {
106         inc_view_offset( SGD_2PI );
107       }
108     }
109   }
110
111   for ( i = 0; i < dt; i++ ) {
112     if ( fabs(get_goal_view_tilt() - get_view_tilt()) < 0.05 ) {
113       set_view_tilt( get_goal_view_tilt() );
114       break;
115     } else {
116       // move current_view.view_tilt towards
117       // current_view.goal_view_tilt
118       if ( get_goal_view_tilt() > get_view_tilt() )
119         {
120           if ( get_goal_view_tilt() - get_view_tilt() < SGD_PI ){
121             inc_view_tilt( 0.01 );
122           } else {
123             inc_view_tilt( -0.01 );
124           }
125         } else {
126           if ( get_view_tilt() - get_goal_view_tilt() < SGD_PI ){
127             inc_view_tilt( -0.01 );
128           } else {
129             inc_view_tilt( 0.01 );
130           }
131         }
132       if ( get_view_tilt() > SGD_2PI ) {
133         inc_view_tilt( -SGD_2PI );
134       } else if ( get_view_tilt() < 0 ) {
135         inc_view_tilt( SGD_2PI );
136       }
137     }
138   }
139 }