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