1 // views.hxx -- data structures and routines for managing and view parameters.
3 // Written by Curtis Olson, started August 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
29 # error This library requires C++
32 #include <Include/compiler.h>
36 #include <sg.h> // plib include
38 #include <FDM/flight.hxx>
39 #include <Math/point3d.hxx>
40 #include <Time/fg_time.hxx>
41 #include <Time/light.hxx>
43 #include "options.hxx"
48 // used in views.cxx and tilemgr.cxx
49 #define USE_FAST_FOV_CLIP
52 // Define a structure containing view information
57 // the current offset from forward for viewing
60 // the goal view offset for viewing (used for smooth view changes)
61 double goal_view_offset;
63 // flag forcing update of fov related stuff
66 // fov of view is specified in the y direction, win_ratio is used to
67 // calculate the fov in the X direction = width/height
70 // width & height of window
71 int winWidth, winHeight;
73 // sin and cos of (fov / 2) in Y axis
74 double sin_fov_y, cos_fov_y;
75 double sinlon, coslon;
77 // slope of view frustum edge in eye space Y axis
80 // sin and cos of (fov / 2) in X axis
81 double sin_fov_x, cos_fov_x;
83 // slope of view frustum edge in eye space X axis
86 #if defined( USE_FAST_FOV_CLIP )
87 double fov_x_clip, fov_y_clip;
88 #endif // USE_FAST_FOV_CLIP
90 // View frustum cull ratio (% of tiles culled ... used for
91 // reporting purposes)
94 // Number of triangles rendered;
98 // absolute view position
101 // view position translated to scenery.center
104 // cartesion coordinates of current lon/lat if at sea level
105 // translated to scenery.center
106 Point3D cur_zero_elev;
108 // vector in cartesian coordinates from current position to the
109 // postion on the earth's surface the sun is directly over
112 // surface direction to go to head towards sun
113 sgVec3 surface_to_sun;
115 // vector in cartesian coordinates from current position to the
116 // postion on the earth's surface the moon is directly over
119 // surface direction to go to head towards moon
120 sgVec3 surface_to_moon;
122 // surface vector heading south
123 sgVec3 surface_south;
125 // surface vector heading east (used to unambiguously align sky
129 // local up vector (normal to the plane tangent to the earth's
130 // surface at the spot we are directly above
133 // up vector for the view (usually point straight up through the
134 // top of the aircraft
137 // the vector pointing straight out the nose of the aircraft
140 // Transformation matrix for eye coordinates to aircraft coordinates
143 // Transformation matrix for the view direction offset relative to
144 // the AIRCRAFT matrix
147 // Current model view matrix;
148 GLfloat MODEL_VIEW[16];
150 // sg versions of our friendly matrices
151 sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
161 // Initialize a view class
164 // Update the view volume, position, and orientation
165 void UpdateViewParams( const FGInterface& f );
167 // Flag to request that UpdateFOV() be called next time
168 // UpdateViewMath() is run.
169 inline void force_update_fov_math() { update_fov = true; }
171 // Update the view parameters
172 void UpdateViewMath( const FGInterface& f );
174 // Update the field of view coefficients
175 void UpdateFOV( const fgOPTIONS& o );
177 // accessor functions
178 inline double get_view_offset() const { return view_offset; }
179 inline void set_view_offset( double a ) { view_offset = a; }
180 inline void inc_view_offset( double amt ) { view_offset += amt; }
181 inline double get_goal_view_offset() const { return goal_view_offset; }
182 inline void set_goal_view_offset( double a) { goal_view_offset = a; }
183 inline double get_win_ratio() const { return win_ratio; }
184 inline void set_win_ratio( double r ) { win_ratio = r; }
185 inline int get_winWidth() const { return winWidth; }
186 inline void set_winWidth( int w ) { winWidth = w; }
187 inline int get_winHeight() const { return winHeight; }
188 inline void set_winHeight( int h ) { winHeight = h; }
189 inline double get_slope_y() const { return slope_y; }
190 inline double get_slope_x() const { return slope_x; }
191 #if defined( USE_FAST_FOV_CLIP )
192 inline double get_fov_x_clip() const { return fov_x_clip; }
193 inline double get_fov_y_clip() const { return fov_y_clip; }
194 #endif // USE_FAST_FOV_CLIP
195 inline double get_vfc_ratio() const { return vfc_ratio; }
196 inline void set_vfc_ratio(double r) { vfc_ratio = r; }
197 inline int get_tris_rendered() const { return tris_rendered; }
198 inline void set_tris_rendered( int tris) { tris_rendered = tris; }
199 inline int get_tris_culled() const { return tris_culled; }
200 inline void set_tris_culled( int tris) { tris_culled = tris; }
201 inline Point3D get_abs_view_pos() const { return abs_view_pos; }
202 inline Point3D get_view_pos() const { return view_pos; }
203 inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
204 inline float *get_to_sun() { return to_sun; }
205 inline void set_to_sun( float x, float y, float z) {
206 sgSetVec3( to_sun, x, y, z );
208 inline float *get_surface_to_sun() { return surface_to_sun; }
209 inline void set_surface_to_sun( float x, float y, float z) {
210 sgSetVec3( surface_to_sun, x, y, z );
212 inline float *get_to_moon() { return to_moon; }
213 inline void set_to_moon( float x, float y, float z) {
214 sgSetVec3( to_moon, x, y, z );
216 inline float *get_surface_to_moon() { return surface_to_moon; }
217 inline void set_surface_to_moon( float x, float y, float z) {
218 sgSetVec3( surface_to_moon, x, y, z );
220 inline float *get_surface_south() { return surface_south; }
221 inline float *get_surface_east() { return surface_east; }
222 inline float *get_local_up() { return local_up; }
223 inline float *get_view_forward() { return view_forward; }
224 inline GLfloat *get_MODEL_VIEW() { return MODEL_VIEW; }
228 extern FGView pilot_view;
229 extern FGView current_view;