1 // viewer.hxx -- class for managing a viewer in the flightgear world.
3 // Written by Curtis Olson, started August 1997.
4 // overhaul started October 2000.
6 // Copyright (C) 1997 - 2000 Curtis L. Olson - curt@flightgear.org
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 # error This library requires C++
33 #include <simgear/compiler.h>
35 #include <plib/sg.h> // plib include
38 #define FG_FOV_MIN 0.1
39 #define FG_FOV_MAX 179.9
42 // Define a structure containing view information
55 // flag forcing a recalc of derived view parameters
62 // the field of view in the x (width) direction
65 // ratio of x and y fov's; fov(y) = fov(x) * win_ratio
68 // the current view offset angle from forward (rotated about the
71 bool reverse_view_offset;
73 // the goal view offset angle (used for smooth view changes)
74 double goal_view_offset;
76 // geodetic view position
77 sgdVec3 geod_view_pos;
79 // absolute view position in earth coordinates
82 // view position in opengl world coordinates (this is the
83 // abs_view_pos translated to scenery.center)
86 // radius to sea level from center of the earth (m)
87 double sea_level_radius;
89 // cartesion coordinates of current lon/lat if at sea level
90 // translated to scenery.center
93 // height ASL of the terrain for our current view position
94 // (future?) double ground_elev;
96 // pilot offset from center of gravity. The X axis is positive
97 // out the tail, Y is out the right wing, and Z is positive up.
98 // Distances in meters of course.
101 // surface vector heading south
102 sgVec3 surface_south;
104 // surface vector heading east (used to unambiguously align sky
108 // world up vector (normal to the plane tangent to the earth's
109 // surface at the spot we are directly above
112 // sg versions of our friendly matrices
113 sgMat4 VIEW, VIEW_ROT, UP;
115 inline void set_dirty() { dirty = true; }
116 inline void set_clean() { dirty = false; }
118 // Update the view volume, position, and orientation
119 virtual void update();
127 virtual ~FGViewer( void );
129 //////////////////////////////////////////////////////////////////////
131 //////////////////////////////////////////////////////////////////////
132 inline void set_fov( double amount ) { fov = amount; }
133 inline void set_win_ratio( double r ) { win_ratio = r; }
134 inline void set_view_offset( double a ) {
138 inline void inc_view_offset( double amt ) {
142 inline void set_goal_view_offset( double a) {
144 goal_view_offset = a;
146 inline void set_reverse_view_offset( bool val ) {
147 reverse_view_offset = val;
149 inline void set_geod_view_pos( double lon, double lat, double alt ) {
150 // data should be in radians and meters asl
152 // cout << "set_geod_view_pos = " << lon << ", " << lat << ", " << alt
154 sgdSetVec3( geod_view_pos, lon, lat, alt );
156 inline void set_pilot_offset( float x, float y, float z ) {
158 sgSetVec3( pilot_offset, x, y, z );
160 inline void set_sea_level_radius( double r ) {
161 // data should be in meters from the center of the earth
163 sea_level_radius = r;
166 //////////////////////////////////////////////////////////////////////
167 // accessor functions
168 //////////////////////////////////////////////////////////////////////
169 inline int get_type() const { return _type ; }
170 inline int is_a( int t ) const { return get_type() == t ; }
171 inline bool is_dirty() const { return dirty; }
172 inline double get_fov() const { return fov; }
173 inline double get_win_ratio() const { return win_ratio; }
174 inline double get_view_offset() const { return view_offset; }
175 inline bool get_reverse_view_offset() const { return reverse_view_offset; }
176 inline double get_goal_view_offset() const { return goal_view_offset; }
177 inline double *get_geod_view_pos() { return geod_view_pos; }
178 inline float *get_pilot_offset() { return pilot_offset; }
179 inline double get_sea_level_radius() const { return sea_level_radius; }
181 //////////////////////////////////////////////////////////////////////
182 // derived values accessor functions
183 //////////////////////////////////////////////////////////////////////
184 inline double *get_abs_view_pos() {
185 if ( dirty ) { update(); }
188 inline float *get_view_pos() {
189 if ( dirty ) { update(); }
192 inline float *get_zero_elev() {
193 if ( dirty ) { update(); }
197 // inline double get_ground_elev() {
198 // if ( dirty ) { update(); }
199 // return ground_elev;
201 inline float *get_surface_south() {
202 if ( dirty ) { update(); }
203 return surface_south;
205 inline float *get_surface_east() {
206 if ( dirty ) { update(); }
209 inline float *get_world_up() {
210 if ( dirty ) { update(); }
213 inline const sgVec4 *get_VIEW() {
214 if ( dirty ) { update(); }
217 inline const sgVec4 *get_VIEW_ROT() {
218 if ( dirty ) { update(); }
221 inline const sgVec4 *get_UP() {
222 if ( dirty ) { update(); }
228 #endif // _VIEWER_HXX