]> git.mxchange.org Git - flightgear.git/blob - src/Main/views.hxx
From Tony Peden:
[flightgear.git] / src / Main / views.hxx
1 // views.hxx -- data structures and routines for managing and view parameters.
2 //
3 // Written by Curtis Olson, started August 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _VIEWS_HXX
25 #define _VIEWS_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32 #include <simgear/compiler.h>
33 #include <simgear/math/point3d.hxx>
34
35 #include <list>
36
37 #include <plib/sg.h>            // plib include
38
39 #include <FDM/flight.hxx>
40 #include <Time/fg_time.hxx>
41 #include <Time/light.hxx>
42
43 #include "options.hxx"
44
45 FG_USING_STD(list);
46
47
48 // used in views.cxx and tilemgr.cxx
49 #define USE_FAST_FOV_CLIP 
50 #define FG_FOV_MIN 0.1
51 #define FG_FOV_MAX 179.9
52
53
54 // Define a structure containing view information
55 class FGView {
56
57 public:
58
59     // the current offset from forward for viewing
60     double view_offset;
61
62     // the goal view offset for viewing (used for smooth view changes)
63     double goal_view_offset;
64
65     // flag forcing update of fov related stuff
66     bool update_fov;
67         
68     // fov of view is specified in the y direction, win_ratio is used to
69     // calculate the fov in the X direction = width/height
70     double win_ratio;
71
72     // width & height of window
73     int winWidth, winHeight;
74
75     // sin and cos of (fov / 2) in Y axis
76     double sin_fov_y, cos_fov_y;
77     double sinlon, coslon;
78
79     // slope of view frustum edge in eye space Y axis
80     double slope_y;
81
82     // sin and cos of (fov / 2) in X axis
83     double sin_fov_x, cos_fov_x;
84
85     // slope of view frustum edge in eye space X axis
86     double slope_x;
87
88 #if defined( USE_FAST_FOV_CLIP )
89     double fov_x_clip, fov_y_clip;
90 #endif // USE_FAST_FOV_CLIP
91
92     // View frustum cull ratio (% of tiles culled ... used for
93     // reporting purposes)
94     double vfc_ratio;
95
96     // Number of triangles rendered;
97     int tris_rendered;
98     int tris_culled;
99
100     // absolute view position
101     Point3D abs_view_pos;
102
103     // view position translated to scenery.center
104     Point3D view_pos;
105
106     // pilot offset from center of gravity.  The X axis is positive
107     // out the tail, Y is out the right wing, and Z is positive up.
108     // Distances in meters of course.
109     sgVec3 pilot_offset;
110
111     // cartesion coordinates of current lon/lat if at sea level
112     // translated to scenery.center
113     Point3D cur_zero_elev;
114
115     // vector in cartesian coordinates from current position to the
116     // postion on the earth's surface the sun is directly over
117     sgVec3 to_sun;
118
119     // surface direction to go to head towards sun
120     sgVec3 surface_to_sun;
121
122     // vector in cartesian coordinates from current position to the
123     // postion on the earth's surface the moon is directly over
124     sgVec3 to_moon;
125   
126     // surface direction to go to head towards moon
127     sgVec3 surface_to_moon;
128
129     // surface vector heading south
130     sgVec3 surface_south;
131
132     // surface vector heading east (used to unambiguously align sky
133     // with sun)
134     sgVec3 surface_east;
135
136     // local up vector (normal to the plane tangent to the earth's
137     // surface at the spot we are directly above
138     sgVec3 local_up;
139
140     // up vector for the view (usually point straight up through the
141     // top of the aircraft
142     sgVec3 view_up;
143
144     // the vector pointing straight out the nose of the aircraft
145     sgVec3 view_forward;
146
147     // Transformation matrix for eye coordinates to aircraft coordinates
148     // sgMat4 AIRCRAFT;
149
150     // Transformation matrix for the view direction offset relative to
151     // the AIRCRAFT matrix
152     sgMat4 VIEW_OFFSET;
153
154     // Current model view matrix;
155     GLfloat MODEL_VIEW[16];
156
157     // sg versions of our friendly matrices
158     sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
159
160 public:
161
162     // Constructor
163     FGView( void );
164
165     // Destructor
166     ~FGView( void );
167
168     // Initialize a view class
169     void Init( void );
170
171     // Update the view volume, position, and orientation
172     void UpdateViewParams( const FGInterface& f );
173
174     // Flag to request that UpdateFOV() be called next time
175     // UpdateViewMath() is run.
176     inline void force_update_fov_math() { update_fov = true; }
177
178     // Update the view parameters
179     void UpdateViewMath( const FGInterface& f );
180
181     // Update the field of view coefficients
182     void UpdateFOV( const fgOPTIONS& o );
183
184     // accessor functions
185     inline double get_view_offset() const { return view_offset; }
186     inline void set_view_offset( double a ) { view_offset = a; }
187     inline void inc_view_offset( double amt ) { view_offset += amt; }
188     inline double get_goal_view_offset() const { return goal_view_offset; }
189     inline void set_goal_view_offset( double a) { goal_view_offset = a; }
190     inline double get_win_ratio() const { return win_ratio; }
191     inline void set_win_ratio( double r ) { win_ratio = r; }
192     inline int get_winWidth() const { return winWidth; }
193     inline void set_winWidth( int w ) { winWidth = w; }
194     inline int get_winHeight() const { return winHeight; }
195     inline void set_winHeight( int h ) { winHeight = h; }
196     inline double get_slope_y() const { return slope_y; }
197     inline double get_slope_x() const { return slope_x; }
198 #if defined( USE_FAST_FOV_CLIP )
199     inline double get_fov_x_clip() const { return fov_x_clip; }
200     inline double get_fov_y_clip() const { return fov_y_clip; }
201 #endif // USE_FAST_FOV_CLIP
202     inline double get_vfc_ratio() const { return vfc_ratio; }
203     inline void set_vfc_ratio(double r) { vfc_ratio = r; }
204     inline int get_tris_rendered() const { return tris_rendered; }
205     inline void set_tris_rendered( int tris) { tris_rendered = tris; }
206     inline int get_tris_culled() const { return tris_culled; }
207     inline void set_tris_culled( int tris) { tris_culled = tris; }
208     inline Point3D get_abs_view_pos() const { return abs_view_pos; }
209     inline Point3D get_view_pos() const { return view_pos; }
210     inline float *get_pilot_offset() { return pilot_offset; }
211     inline void set_pilot_offset( float x, float y, float z ) {
212         sgSetVec3( pilot_offset, x, y, z );
213     }
214     inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
215     inline float *get_to_sun() { return to_sun; }
216     inline void set_to_sun( float x, float y, float z ) {
217         sgSetVec3( to_sun, x, y, z );
218     }
219     inline float *get_surface_to_sun() { return surface_to_sun; }
220     inline void set_surface_to_sun( float x, float y, float z) {
221         sgSetVec3( surface_to_sun, x, y, z );
222     }
223     inline float *get_to_moon() { return to_moon; }
224     inline void set_to_moon( float x, float y, float z) {
225         sgSetVec3( to_moon, x, y, z );
226     }
227     inline float *get_surface_to_moon() { return surface_to_moon; }
228     inline void set_surface_to_moon( float x, float y, float z) {
229         sgSetVec3( surface_to_moon, x, y, z );
230     }
231     inline float *get_surface_south() { return surface_south; }
232     inline float *get_surface_east() { return surface_east; }
233     inline float *get_local_up() { return local_up; }
234     inline float *get_view_forward() { return view_forward; }
235     inline GLfloat *get_MODEL_VIEW() { return MODEL_VIEW; }
236 };
237
238
239 extern FGView pilot_view;
240 extern FGView current_view;
241
242
243 #endif // _VIEWS_HXX
244
245