]> git.mxchange.org Git - flightgear.git/blob - Simulator/Main/views.hxx
Removed in-src cvs logs.
[flightgear.git] / Simulator / 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
23
24 #ifndef _VIEWS_HXX
25 #define _VIEWS_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32
33 #include <FDM/flight.hxx>
34 #include <Math/mat3.h>
35 #include <Math/point3d.hxx>
36 #include <Time/fg_time.hxx>
37 #include <Time/light.hxx>
38
39 #include "options.hxx"
40
41
42 // used in views.cxx and tilemgr.cxx
43 #define USE_FAST_FOV_CLIP 
44
45
46 // Define a structure containing view information
47 class FGView {
48
49 public:
50
51     // the current offset from forward for viewing
52     double view_offset;
53
54     // the goal view offset for viewing (used for smooth view changes)
55     double goal_view_offset;
56
57     // flag forcing update of fov related stuff
58     bool update_fov;
59         
60     // fov of view is specified in the y direction, win_ratio is used to
61     // calculate the fov in the X direction = width/height
62     double win_ratio;
63
64     // width & height of window
65     int winWidth, winHeight;
66
67     // sin and cos of (fov / 2) in Y axis
68     double sin_fov_y, cos_fov_y;
69     double sinlon, coslon;
70
71     // slope of view frustum edge in eye space Y axis
72     double slope_y;
73
74     // sin and cos of (fov / 2) in X axis
75     double sin_fov_x, cos_fov_x;
76
77     // slope of view frustum edge in eye space X axis
78     double slope_x;
79
80 #if defined( USE_FAST_FOV_CLIP )
81     double fov_x_clip, fov_y_clip;
82 #endif // USE_FAST_FOV_CLIP
83
84     // View frustum cull ratio (% of tiles culled ... used for
85     // reporting purposes)
86     double vfc_ratio;
87
88     // Number of triangles rendered;
89     int tris_rendered;
90     int tris_culled;
91
92     // absolute view position
93     Point3D abs_view_pos;
94
95     // view position translated to scenery.center
96     Point3D view_pos;
97
98     // cartesion coordinates of current lon/lat if at sea level
99     // translated to scenery.center*/
100     Point3D cur_zero_elev;
101
102     // vector in cartesian coordinates from current position to the
103     // postion on the earth's surface the sun is directly over
104     MAT3vec to_sun;
105     
106     // surface direction to go to head towards sun
107     MAT3vec surface_to_sun;
108
109     // vector in cartesian coordinates from current position to the
110     // postion on the earth's surface the moon is directly over
111     MAT3vec to_moon;
112   
113     // surface direction to go to head towards moon
114     MAT3vec surface_to_moon;
115
116     // surface vector heading south
117     MAT3vec surface_south;
118
119     // surface vector heading east (used to unambiguously align sky
120     // with sun)
121     MAT3vec surface_east;
122
123     // local up vector (normal to the plane tangent to the earth's
124     // surface at the spot we are directly above
125     MAT3vec local_up;
126
127     // up vector for the view (usually point straight up through the
128     // top of the aircraft
129     MAT3vec view_up;
130
131     // the vector pointing straight out the nose of the aircraft
132     MAT3vec view_forward;
133
134     // Transformation matrix for eye coordinates to aircraft coordinates
135     MAT3mat AIRCRAFT;
136
137     // Transformation matrix for the view direction offset relative to
138     // the AIRCRAFT matrix
139     MAT3mat VIEW_OFFSET;
140
141     // Transformation matrix for aircraft coordinates to world
142     // coordinates
143     MAT3mat WORLD;
144
145     // Combined transformation from eye coordinates to world coordinates
146     MAT3mat EYE_TO_WORLD;
147
148     // Inverse of EYE_TO_WORLD which is a transformation from world
149     // coordinates to eye coordinates
150     MAT3mat WORLD_TO_EYE;
151
152     // Current model view matrix;
153     GLdouble MODEL_VIEW[16];
154
155 public:
156
157     // Constructor
158     FGView( void );
159
160     // Destructor
161     ~FGView( void );
162
163     // Initialize a view class
164     void Init( void );
165
166     // Basically, this is a modified version of the Mesa gluLookAt()
167     // function that's been modified slightly so we can capture the
168     // result (and use it later) otherwise this all gets calculated in
169     // OpenGL land and we don't have access to the results.
170     void LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
171                  GLdouble centerx, GLdouble centery, GLdouble centerz,
172                  GLdouble upx, GLdouble upy, GLdouble upz );
173
174     // Update the view volume, position, and orientation
175     void UpdateViewParams( void );
176
177     // Flag to request that UpdateFOV() be called next time
178     // UpdateViewMath() is run.
179     inline void force_update_fov_math() { update_fov = true; }
180
181     // Update the view parameters
182     void UpdateViewMath( FGInterface *f );
183
184     // Update the "World to Eye" transformation matrix
185     void UpdateWorldToEye( FGInterface *f );
186
187     // Update the field of view coefficients
188     void UpdateFOV( const fgOPTIONS& o );
189
190     // accessor functions
191     inline double get_view_offset() const { return view_offset; }
192     inline void set_view_offset( double a ) { view_offset = a; }
193     inline void inc_view_offset( double amt ) { view_offset += amt; }
194     inline double get_goal_view_offset() const { return goal_view_offset; }
195     inline void set_goal_view_offset( double a) { goal_view_offset = a; }
196     inline double get_win_ratio() const { return win_ratio; }
197     inline void set_win_ratio( double r ) { win_ratio = r; }
198     inline int get_winWidth() const { return winWidth; }
199     inline void set_winWidth( int w ) { winWidth = w; }
200     inline int get_winHeight() const { return winHeight; }
201     inline void set_winHeight( int h ) { winHeight = h; }
202     inline double get_slope_y() const { return slope_y; }
203     inline double get_slope_x() const { return slope_x; }
204 #if defined( USE_FAST_FOV_CLIP )
205     inline double get_fov_x_clip() const { return fov_x_clip; }
206     inline double get_fov_y_clip() const { return fov_y_clip; }
207 #endif // USE_FAST_FOV_CLIP
208     inline double get_vfc_ratio() const { return vfc_ratio; }
209     inline void set_vfc_ratio(double r) { vfc_ratio = r; }
210     inline int get_tris_rendered() const { return tris_rendered; }
211     inline void set_tris_rendered( int tris) { tris_rendered = tris; }
212     inline int get_tris_culled() const { return tris_culled; }
213     inline void set_tris_culled( int tris) { tris_culled = tris; }
214     inline Point3D get_abs_view_pos() const { return abs_view_pos; }
215     inline Point3D get_view_pos() const { return view_pos; }
216     inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
217     inline double *get_to_sun() { return to_sun; }
218     inline void set_to_sun( double x, double y, double z) {
219         to_sun[0] = x;
220         to_sun[1] = y;
221         to_sun[2] = z;
222     }
223     inline double *get_surface_to_sun() { return surface_to_sun; }
224     inline void set_surface_to_sun( double x, double y, double z) {
225         surface_to_sun[0] = x;
226         surface_to_sun[1] = y;
227         surface_to_sun[2] = z;
228     }
229     inline double *get_to_moon() { return to_moon; }
230     inline void set_to_moon( double x, double y, double z) {
231         to_moon[0] = x;
232         to_moon[1] = y;
233         to_moon[2] = z;
234     }
235     inline double *get_surface_to_moon() { return surface_to_moon; }
236     inline void set_surface_to_moon( double x, double y, double z) {
237         surface_to_moon[0] = x;
238         surface_to_moon[1] = y;
239         surface_to_moon[2] = z;
240     }
241     inline double *get_surface_south() { return surface_south; }
242     inline double *get_surface_east() { return surface_east; }
243     inline double *get_local_up() { return local_up; }
244     inline const MAT3mat *get_WORLD_TO_EYE() const { return &WORLD_TO_EYE; }
245     inline GLdouble *get_MODEL_VIEW() { return MODEL_VIEW; }
246 };
247
248
249 extern FGView current_view;
250
251
252 #endif // _VIEWS_HXX
253
254