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