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