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