]> git.mxchange.org Git - flightgear.git/blob - src/Main/viewer.hxx
288c9543ca3a32d38bd0fba169f04a7ce3274b06
[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 #include <simgear/timing/sg_time.hxx>
35
36 #include <plib/sg.h>            // plib include
37
38
39 // Define a structure containing view information
40 class FGViewer {
41
42 private:
43
44     // flag forcing a recalc of derived view parameters
45     bool dirty;
46
47 protected:
48
49     // the current view offset angle from forward (rotated about the
50     // view_up vector)
51     double view_offset;
52
53     // the goal view offset angle  (used for smooth view changes)
54     double goal_view_offset;
55
56     // absolute view position in earth coordinates
57     sgdVec3 abs_view_pos;
58
59     // view position in opengl world coordinates (this is the
60     // abs_view_pos translated to scenery.center)
61     sgVec3 view_pos;
62
63     // radius to sea level from center of the earth (m)
64     double sea_level_radius;
65
66     // cartesion coordinates of current lon/lat if at sea level
67     // translated to scenery.center
68     sgVec3 zero_elev;
69
70     // pilot offset from center of gravity.  The X axis is positive
71     // out the tail, Y is out the right wing, and Z is positive up.
72     // Distances in meters of course.
73     sgVec3 pilot_offset;
74
75     // vector in cartesian coordinates from current position to the
76     // postion on the earth's surface the sun is directly over
77     sgVec3 to_sun;
78
79     // surface direction to go to head towards sun
80     sgVec3 surface_to_sun;
81
82     // vector in cartesian coordinates from current position to the
83     // postion on the earth's surface the moon is directly over
84     sgVec3 to_moon;
85   
86     // surface direction to go to head towards moon
87     sgVec3 surface_to_moon;
88
89     // surface vector heading south
90     sgVec3 surface_south;
91
92     // surface vector heading east (used to unambiguously align sky
93     // with sun)
94     sgVec3 surface_east;
95
96     // local up vector (normal to the plane tangent to the earth's
97     // surface at the spot we are directly above
98     sgVec3 local_up;
99
100     // sg versions of our friendly matrices
101     sgMat4 VIEW, VIEW_ROT, UP;
102
103     inline void set_dirty() { dirty = true; }
104     inline void set_clean() { dirty = false; }
105
106     // Update the view volume, position, and orientation
107     virtual void update();
108
109 public:
110
111     // Constructor
112     FGViewer( void );
113
114     // Destructor
115     virtual ~FGViewer( void );
116
117     // Initialize a view class
118     virtual void init( void );
119
120     //////////////////////////////////////////////////////////////////////
121     // setter functions
122     //////////////////////////////////////////////////////////////////////
123     inline void set_view_offset( double a ) {
124         set_dirty();
125         view_offset = a;
126     }
127     inline void inc_view_offset( double amt ) {
128         set_dirty();
129         view_offset += amt;
130     }
131     inline void set_goal_view_offset( double a) {
132         set_dirty();
133         goal_view_offset = a;
134     }
135     inline void set_pilot_offset( float x, float y, float z ) {
136         set_dirty();
137         sgSetVec3( pilot_offset, x, y, z );
138     }
139     inline void set_sea_level_radius( double r ) {
140         // data should be in meters from the center of the earth
141         set_dirty();
142         sea_level_radius = r;
143     }
144
145     //////////////////////////////////////////////////////////////////////
146     // accessor functions
147     //////////////////////////////////////////////////////////////////////
148     inline bool is_dirty() const { return dirty; }
149     inline double get_view_offset() const { return view_offset; }
150     inline double get_goal_view_offset() const { return goal_view_offset; }
151     inline float *get_pilot_offset() { return pilot_offset; }
152     inline double get_sea_level_radius() const { return sea_level_radius; }
153
154     //////////////////////////////////////////////////////////////////////
155     // derived values accessor functions
156     //////////////////////////////////////////////////////////////////////
157     inline double *get_abs_view_pos() {
158         if ( dirty ) { update(); }
159         return abs_view_pos;
160     }
161     inline float *get_view_pos() {
162         if ( dirty ) { update(); }
163         return view_pos;
164     }
165     inline float *get_zero_elev() {
166         if ( dirty ) { update(); }
167         return zero_elev;
168     }
169     inline float *get_surface_south() {
170         if ( dirty ) { update(); }
171         return surface_south;
172     }
173     inline float *get_surface_east() {
174         if ( dirty ) { update(); }
175         return surface_east;
176     }
177     inline float *get_local_up() {
178         if ( dirty ) { update(); }
179         return local_up;
180     }
181     inline const sgVec4 *get_VIEW() {
182         if ( dirty ) { update(); }
183         return VIEW;
184     }
185     inline const sgVec4 *get_VIEW_ROT() {
186         if ( dirty ) { update(); }
187         return VIEW_ROT;
188     }
189     inline const sgVec4 *get_UP() {
190         if ( dirty ) { update(); }
191         return UP;
192     }
193
194     //////////////////////////////////////////////////////////////////////
195     // need to fix these
196     //////////////////////////////////////////////////////////////////////
197     inline float *get_to_sun() { return to_sun; }
198     inline void set_to_sun( float x, float y, float z ) {
199         sgSetVec3( to_sun, x, y, z );
200     }
201     inline float *get_surface_to_sun() { return surface_to_sun; }
202     inline void set_surface_to_sun( float x, float y, float z) {
203         sgSetVec3( surface_to_sun, x, y, z );
204     }
205     inline float *get_to_moon() { return to_moon; }
206     inline void set_to_moon( float x, float y, float z) {
207         sgSetVec3( to_moon, x, y, z );
208     }
209     inline float *get_surface_to_moon() { return surface_to_moon; }
210     inline void set_surface_to_moon( float x, float y, float z) {
211         sgSetVec3( surface_to_moon, x, y, z );
212     }
213 };
214
215
216 #endif // _VIEWER_HXX
217
218