]> git.mxchange.org Git - flightgear.git/blob - Main/views.hxx
Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
[flightgear.git] / 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@infoplane.com
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 // (Log is kept at end of this file)
23
24
25 #ifndef _VIEWS_HXX
26 #define _VIEWS_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33
34 #include <FDM/flight.hxx>
35 #include <Math/mat3.h>
36 #include <Math/point3d.hxx>
37 #include <Time/fg_time.hxx>
38 #include <Time/light.hxx>
39
40 #include "options.hxx"
41
42
43 // used in views.cxx and tilemgr.cxx
44 #define USE_FAST_FOV_CLIP 
45
46
47 // Define a structure containing view information
48 class FGView {
49
50     // the current offset from forward for viewing
51     double view_offset;
52
53     // the goal view offset for viewing (used for smooth view changes)
54     double goal_view_offset;
55
56     // flag forcing update of fov related stuff
57     bool update_fov;
58         
59     // fov of view is specified in the y direction, win_ratio is used to
60     // calculate the fov in the X direction = width/height
61     double win_ratio;
62
63     // width & height of window
64     int winWidth, winHeight;
65
66     // sin and cos of (fov / 2) in Y axis
67     double sin_fov_y, cos_fov_y;
68     double sinlon, coslon;
69
70     // slope of view frustum edge in eye space Y axis
71     double slope_y;
72
73     // sin and cos of (fov / 2) in X axis
74     double sin_fov_x, cos_fov_x;
75
76     // slope of view frustum edge in eye space X axis
77     double slope_x;
78
79 #if defined( USE_FAST_FOV_CLIP )
80     double fov_x_clip, fov_y_clip;
81 #endif // USE_FAST_FOV_CLIP
82
83     // View frustum cull ratio (% of tiles culled ... used for
84     // reporting purposes)
85     double vfc_ratio;
86
87     // Number of triangles rendered;
88     int tris_rendered;
89
90     // absolute view position
91     Point3D abs_view_pos;
92
93     // view position translated to scenery.center
94     Point3D view_pos;
95
96     // cartesion coordinates of current lon/lat if at sea level
97     // translated to scenery.center*/
98     Point3D cur_zero_elev;
99
100     // vector in cartesian coordinates from current position to the
101     // postion on the earth's surface the sun is directly over
102     MAT3vec to_sun;
103     
104     // surface direction to go to head towards sun
105     MAT3vec surface_to_sun;
106
107     // surface vector heading south
108     MAT3vec surface_south;
109
110     // surface vector heading east (used to unambiguously align sky
111     // with sun)
112     MAT3vec surface_east;
113
114     // local up vector (normal to the plane tangent to the earth's
115     // surface at the spot we are directly above
116     MAT3vec local_up;
117
118     // up vector for the view (usually point straight up through the
119     // top of the aircraft
120     MAT3vec view_up;
121
122     // the vector pointing straight out the nose of the aircraft
123     MAT3vec view_forward;
124
125     // Transformation matrix for eye coordinates to aircraft coordinates
126     MAT3mat AIRCRAFT;
127
128     // Transformation matrix for the view direction offset relative to
129     // the AIRCRAFT matrix
130     MAT3mat VIEW_OFFSET;
131
132     // Transformation matrix for aircraft coordinates to world
133     // coordinates
134     MAT3mat WORLD;
135
136     // Combined transformation from eye coordinates to world coordinates
137     MAT3mat EYE_TO_WORLD;
138
139     // Inverse of EYE_TO_WORLD which is a transformation from world
140     // coordinates to eye coordinates
141     MAT3mat WORLD_TO_EYE;
142
143     // Current model view matrix;
144     GLdouble MODEL_VIEW[16];
145
146 public:
147
148     // Constructor
149     FGView( void );
150
151     // Destructor
152     ~FGView( void );
153
154     // Initialize a view class
155     void Init( void );
156
157     // Basically, this is a modified version of the Mesa gluLookAt()
158     // function that's been modified slightly so we can capture the
159     // result (and use it later) otherwise this all gets calculated in
160     // OpenGL land and we don't have access to the results.
161     void LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
162                  GLdouble centerx, GLdouble centery, GLdouble centerz,
163                  GLdouble upx, GLdouble upy, GLdouble upz );
164
165     // Update the view volume, position, and orientation
166     void UpdateViewParams( void );
167
168     // Flag to request that UpdateFOV() be called next time
169     // UpdateViewMath() is run.
170     inline void force_update_fov_math() { update_fov = true; }
171
172     // Update the view parameters
173     void UpdateViewMath( FGState *f );
174
175     // Update the "World to Eye" transformation matrix
176     void UpdateWorldToEye( FGState *f );
177
178     // Update the field of view coefficients
179     void UpdateFOV( const fgOPTIONS& o );
180
181     // accessor functions
182     inline double get_view_offset() const { return view_offset; }
183     inline void set_view_offset( double a ) { view_offset = a; }
184     inline void inc_view_offset( double amt ) { view_offset += amt; }
185     inline double get_goal_view_offset() const { return goal_view_offset; }
186     inline void set_goal_view_offset( double a) { goal_view_offset = a; }
187     inline double get_win_ratio() const { return win_ratio; }
188     inline void set_win_ratio( double r ) { win_ratio = r; }
189     inline int get_winWidth() const { return winWidth; }
190     inline void set_winWidth( int w ) { winWidth = w; }
191     inline int get_winHeight() const { return winHeight; }
192     inline void set_winHeight( int h ) { winHeight = h; }
193     inline double get_slope_y() const { return slope_y; }
194     inline double get_slope_x() const { return slope_x; }
195 #if defined( USE_FAST_FOV_CLIP )
196     inline double get_fov_x_clip() const { return fov_x_clip; }
197     inline double get_fov_y_clip() const { return fov_y_clip; }
198 #endif // USE_FAST_FOV_CLIP
199     inline double get_vfc_ratio() const { return vfc_ratio; }
200     inline void set_vfc_ratio(double r) { vfc_ratio = r; }
201     inline int get_tris_rendered() const { return tris_rendered; }
202     inline void set_tris_rendered( int tris) { tris_rendered = tris; }
203     inline Point3D get_abs_view_pos() const { return abs_view_pos; }
204     inline Point3D get_view_pos() const { return view_pos; }
205     inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
206     inline double *get_to_sun() { return to_sun; }
207     inline void set_to_sun( double x, double y, double z) {
208         to_sun[0] = x;
209         to_sun[1] = y;
210         to_sun[2] = z;
211     }
212     inline double *get_surface_to_sun() { return surface_to_sun; }
213     inline void set_surface_to_sun( double x, double y, double z) {
214         surface_to_sun[0] = x;
215         surface_to_sun[1] = y;
216         surface_to_sun[2] = z;
217     }
218     inline double *get_surface_south() { return surface_south; }
219     inline double *get_surface_east() { return surface_east; }
220     inline double *get_local_up() { return local_up; }
221     inline MAT3mat *get_WORLD_TO_EYE() const { return &WORLD_TO_EYE; }
222     inline GLdouble *get_MODEL_VIEW() { return MODEL_VIEW; }
223 };
224
225
226 extern FGView current_view;
227
228
229 #endif // _VIEWS_HXX
230
231
232 // $Log$
233 // Revision 1.19  1999/02/01 21:33:36  curt
234 // Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
235 // Jon accepted my offer to do this and thought it was a good idea.
236 //
237 // Revision 1.18  1998/12/11 20:26:30  curt
238 // Fixed view frustum culling accuracy bug so we can look out the sides and
239 // back without tri-stripes dropping out.
240 //
241 // Revision 1.17  1998/12/09 18:50:29  curt
242 // Converted "class fgVIEW" to "class FGView" and updated to make data
243 // members private and make required accessor functions.
244 //
245 // Revision 1.16  1998/12/05 15:54:25  curt
246 // Renamed class fgFLIGHT to class FGState as per request by JSB.
247 //
248 // Revision 1.15  1998/10/16 23:27:56  curt
249 // C++-ifying.
250 //
251 // Revision 1.14  1998/10/16 00:54:04  curt
252 // Converted to Point3D class.
253 //
254 // Revision 1.13  1998/09/08 15:04:36  curt
255 // Optimizations by Norman Vine.
256 //
257 // Revision 1.12  1998/08/24 20:11:15  curt
258 // Added i/I to toggle full vs. minimal HUD.
259 // Added a --hud-tris vs --hud-culled option.
260 // Moved options accessor funtions to options.hxx.
261 //
262 // Revision 1.11  1998/08/20 20:32:35  curt
263 // Reshuffled some of the code in and around views.[ch]xx
264 //
265 // Revision 1.10  1998/07/08 14:45:09  curt
266 // polar3d.h renamed to polar3d.hxx
267 // vector.h renamed to vector.hxx
268 // updated audio support so it waits to create audio classes (and tie up
269 //   /dev/dsp) until the mpg123 player is finished.
270 //
271 // Revision 1.9  1998/07/04 00:52:27  curt
272 // Add my own version of gluLookAt() (which is nearly identical to the
273 // Mesa/glu version.)  But, by calculating the Model View matrix our selves
274 // we can save this matrix without having to read it back in from the video
275 // card.  This hopefully allows us to save a few cpu cycles when rendering
276 // out the fragments because we can just use glLoadMatrixd() with the
277 // precalculated matrix for each tile rather than doing a push(), translate(),
278 // pop() for every fragment.
279 //
280 // Panel status defaults to off for now until it gets a bit more developed.
281 //
282 // Extract OpenGL driver info on initialization.
283 //
284 // Revision 1.8  1998/05/27 02:24:06  curt
285 // View optimizations by Norman Vine.
286 //
287 // Revision 1.7  1998/05/17 16:59:04  curt
288 // First pass at view frustum culling now operational.
289 //
290 // Revision 1.6  1998/05/16 13:08:37  curt
291 // C++ - ified views.[ch]xx
292 // Shuffled some additional view parameters into the fgVIEW class.
293 // Changed tile-radius to tile-diameter because it is a much better
294 //   name.
295 // Added a WORLD_TO_EYE transformation to views.cxx.  This allows us
296 //  to transform world space to eye space for view frustum culling.
297 //
298 // Revision 1.5  1998/05/02 01:51:02  curt
299 // Updated polartocart conversion routine.
300 //
301 // Revision 1.4  1998/04/28 01:20:24  curt
302 // Type-ified fgTIME and fgVIEW.
303 // Added a command line option to disable textures.
304 //
305 // Revision 1.3  1998/04/25 22:06:31  curt
306 // Edited cvs log messages in source files ... bad bad bad!
307 //
308 // Revision 1.2  1998/04/24 00:49:22  curt
309 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
310 // Trying out some different option parsing code.
311 // Some code reorganization.
312 //
313 // Revision 1.1  1998/04/22 13:25:46  curt
314 // C++ - ifing the code.
315 // Starting a bit of reorganization of lighting code.
316 //
317 // Revision 1.11  1998/04/21 17:02:42  curt
318 // Prepairing for C++ integration.
319 //
320 // Revision 1.10  1998/02/07 15:29:45  curt
321 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
322 // <chotchkiss@namg.us.anritsu.com>
323 //
324 // Revision 1.9  1998/01/29 00:50:29  curt
325 // Added a view record field for absolute x, y, z position.
326 //
327 // Revision 1.8  1998/01/27 00:47:58  curt
328 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
329 // system and commandline/config file processing code.
330 //
331 // Revision 1.7  1998/01/22 02:59:38  curt
332 // Changed #ifdef FILE_H to #ifdef _FILE_H
333 //
334 // Revision 1.6  1998/01/19 19:27:10  curt
335 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
336 // This should simplify things tremendously.
337 //
338 // Revision 1.5  1997/12/22 04:14:32  curt
339 // Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
340 //
341 // Revision 1.4  1997/12/17 23:13:36  curt
342 // Began working on rendering a sky.
343 //
344 // Revision 1.3  1997/12/15 23:54:51  curt
345 // Add xgl wrappers for debugging.
346 // Generate terrain normals on the fly.
347 //
348 // Revision 1.2  1997/12/10 22:37:48  curt
349 // Prepended "fg" on the name of all global structures that didn't have it yet.
350 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
351 //
352 // Revision 1.1  1997/08/27 21:31:18  curt
353 // Initial revision.
354 //