]> git.mxchange.org Git - flightgear.git/blob - src/Main/viewer.hxx
087b59c75dd23b5d528178b4e0aadba3b5cd2e5b
[flightgear.git] / src / Main / viewer.hxx
1 // viewer.hxx -- 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 #ifndef _VIEWER_HXX
26 #define _VIEWER_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33 #include <simgear/compiler.h>
34
35 #include <plib/sg.h>            // plib include
36
37
38 // Define a structure containing view information
39 class FGViewer {
40
41 public:
42
43     enum fgViewType {
44         FG_RPH = 0,
45         FG_LOOKAT = 1,
46         FG_HPR = 2
47     };
48
49 private:
50
51     // flag forcing a recalc of derived view parameters
52     bool dirty;
53
54 protected:
55
56     fgViewType _type;
57
58     // the current view offset angle from forward (rotated about the
59     // view_up vector)
60     double view_offset;
61
62     // the goal view offset angle  (used for smooth view changes)
63     double goal_view_offset;
64
65     // geodetic view position
66     sgdVec3 geod_view_pos;
67
68     // absolute view position in earth coordinates
69     sgdVec3 abs_view_pos;
70
71     // view position in opengl world coordinates (this is the
72     // abs_view_pos translated to scenery.center)
73     sgVec3 view_pos;
74
75     // radius to sea level from center of the earth (m)
76     double sea_level_radius;
77
78     // cartesion coordinates of current lon/lat if at sea level
79     // translated to scenery.center
80     sgVec3 zero_elev;
81
82     // pilot offset from center of gravity.  The X axis is positive
83     // out the tail, Y is out the right wing, and Z is positive up.
84     // Distances in meters of course.
85     sgVec3 pilot_offset;
86
87     // surface vector heading south
88     sgVec3 surface_south;
89
90     // surface vector heading east (used to unambiguously align sky
91     // with sun)
92     sgVec3 surface_east;
93
94     // world up vector (normal to the plane tangent to the earth's
95     // surface at the spot we are directly above
96     sgVec3 world_up;
97
98     // sg versions of our friendly matrices
99     sgMat4 VIEW, VIEW_ROT, UP;
100
101     inline void set_dirty() { dirty = true; }
102     inline void set_clean() { dirty = false; }
103
104     // Update the view volume, position, and orientation
105     virtual void update();
106
107 public:
108
109     // Constructor
110     FGViewer( void );
111
112     // Destructor
113     virtual ~FGViewer( void );
114
115     //////////////////////////////////////////////////////////////////////
116     // setter functions
117     //////////////////////////////////////////////////////////////////////
118     inline void set_view_offset( double a ) {
119         set_dirty();
120         view_offset = a;
121     }
122     inline void inc_view_offset( double amt ) {
123         set_dirty();
124         view_offset += amt;
125     }
126     inline void set_goal_view_offset( double a) {
127         set_dirty();
128         goal_view_offset = a;
129     }
130     inline void set_geod_view_pos( double lon, double lat, double alt ) {
131         // data should be in radians and meters asl
132         set_dirty();
133         // cout << "set_geod_view_pos = " << lon << ", " << lat << ", " << alt
134         //      << endl;
135         sgdSetVec3( geod_view_pos, lon, lat, alt );
136     }
137     inline void set_pilot_offset( float x, float y, float z ) {
138         set_dirty();
139         sgSetVec3( pilot_offset, x, y, z );
140     }
141     inline void set_sea_level_radius( double r ) {
142         // data should be in meters from the center of the earth
143         set_dirty();
144         sea_level_radius = r;
145     }
146
147     //////////////////////////////////////////////////////////////////////
148     // accessor functions
149     //////////////////////////////////////////////////////////////////////
150     inline int get_type() const { return _type ; }
151     inline int is_a( int t ) const { return get_type() == t ; }
152     inline bool is_dirty() const { return dirty; }
153     inline double get_view_offset() const { return view_offset; }
154     inline double get_goal_view_offset() const { return goal_view_offset; }
155     inline double *get_geod_view_pos() { return geod_view_pos; }
156     inline float *get_pilot_offset() { return pilot_offset; }
157     inline double get_sea_level_radius() const { return sea_level_radius; }
158
159     //////////////////////////////////////////////////////////////////////
160     // derived values accessor functions
161     //////////////////////////////////////////////////////////////////////
162     inline double *get_abs_view_pos() {
163         if ( dirty ) { update(); }
164         return abs_view_pos;
165     }
166     inline float *get_view_pos() {
167         if ( dirty ) { update(); }
168         return view_pos;
169     }
170     inline float *get_zero_elev() {
171         if ( dirty ) { update(); }
172         return zero_elev;
173     }
174     inline float *get_surface_south() {
175         if ( dirty ) { update(); }
176         return surface_south;
177     }
178     inline float *get_surface_east() {
179         if ( dirty ) { update(); }
180         return surface_east;
181     }
182     inline float *get_world_up() {
183         if ( dirty ) { update(); }
184         return world_up;
185     }
186     inline const sgVec4 *get_VIEW() {
187         if ( dirty ) { update(); }
188         return VIEW;
189     }
190     inline const sgVec4 *get_VIEW_ROT() {
191         if ( dirty ) { update(); }
192         return VIEW_ROT;
193     }
194     inline const sgVec4 *get_UP() {
195         if ( dirty ) { update(); }
196         return UP;
197     }
198 };
199
200
201 #endif // _VIEWER_HXX
202
203