]> git.mxchange.org Git - flightgear.git/blob - src/Main/viewer.cxx
c13e17806cd80f35813c9bb469890e574aa58357
[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 {
43     sgSetVec3( pilot_offset, 0.0, 0.0, 0.0 );
44     sgdZeroVec3(geod_view_pos);
45     sgdZeroVec3(abs_view_pos);
46     sea_level_radius = SG_EQUATORIAL_RADIUS_M; 
47     //a reasonable guess for init, so that the math doesn't blow up
48 }
49
50
51 // Update the view parameters
52 void FGViewer::update() {
53     SG_LOG( SG_VIEW, SG_ALERT, "Shouldn't ever see this" );
54 }
55
56
57 // Destructor
58 FGViewer::~FGViewer( void ) {
59 }
60
61 void
62 FGViewer::init ()
63 {
64 }
65
66 void
67 FGViewer::bind ()
68 {
69 }
70
71 void
72 FGViewer::unbind ()
73 {
74 }
75
76 void
77 FGViewer::update (int dt)
78 {
79   for ( int i = 0; i < dt; i++ ) {
80     if ( fabs(get_goal_view_offset() - get_view_offset()) < 0.05 ) {
81       set_view_offset( get_goal_view_offset() );
82       break;
83     } else {
84       // move current_view.view_offset towards
85       // current_view.goal_view_offset
86       if ( get_goal_view_offset() > get_view_offset() )
87         {
88           if ( get_goal_view_offset() - get_view_offset() < SGD_PI ){
89             inc_view_offset( 0.01 );
90           } else {
91             inc_view_offset( -0.01 );
92           }
93         } else {
94           if ( get_view_offset() - get_goal_view_offset() < SGD_PI ){
95             inc_view_offset( -0.01 );
96           } else {
97             inc_view_offset( 0.01 );
98           }
99         }
100       if ( get_view_offset() > SGD_2PI ) {
101         inc_view_offset( -SGD_2PI );
102       } else if ( get_view_offset() < 0 ) {
103         inc_view_offset( SGD_2PI );
104       }
105     }
106   }
107 }