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>
34 #include <simgear/math/point3d.hxx>
35 #include <simgear/timing/sg_time.hxx>
39 #include <plib/sg.h> // plib include
41 #include <FDM/flight.hxx>
42 #include <Time/light.hxx>
48 #define FG_FOV_MIN 0.1
49 #define FG_FOV_MAX 179.9
52 // Define a structure containing view information
57 // flag forcing a recalc of derived view parameters
60 // the current view offset angle from forward (rotated about the
64 // the goal view offset angle (used for smooth view changes)
65 double goal_view_offset;
67 // geodetic view position
68 Point3D geod_view_pos;
70 // radius to sea level from center of the earth (m)
71 double sea_level_radius;
73 // absolute view position in earth coordinates
76 // view position in opengl world coordinates (this is the
77 // abs_view_pos translated to scenery.center)
80 // pilot offset from center of gravity. The X axis is positive
81 // out the tail, Y is out the right wing, and Z is positive up.
82 // Distances in meters of course.
85 // view orientation (heading, pitch, roll)
88 // cartesion coordinates of current lon/lat if at sea level
89 // translated to scenery.center
90 Point3D cur_zero_elev;
92 // vector in cartesian coordinates from current position to the
93 // postion on the earth's surface the sun is directly over
96 // surface direction to go to head towards sun
97 sgVec3 surface_to_sun;
99 // vector in cartesian coordinates from current position to the
100 // postion on the earth's surface the moon is directly over
103 // surface direction to go to head towards moon
104 sgVec3 surface_to_moon;
106 // surface vector heading south
107 sgVec3 surface_south;
109 // surface vector heading east (used to unambiguously align sky
113 // local up vector (normal to the plane tangent to the earth's
114 // surface at the spot we are directly above
117 // up vector for the view (usually point straight up through the
118 // top of the aircraft
121 // the vector pointing straight out the nose of the aircraft
124 // Transformation matrix for the view direction offset relative to
125 // the AIRCRAFT matrix
128 // sg versions of our friendly matrices
129 sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
131 // Update the view volume, position, and orientation
142 // Initialize a view class
145 // Transform a vector from world coordinates to the local plane
146 void CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src);
148 //////////////////////////////////////////////////////////////////////
150 //////////////////////////////////////////////////////////////////////
151 inline void set_geod_view_pos( double lon, double lat, double alt ) {
152 // data should be in radians and meters asl
154 // cout << "set_geod_view_pos = " << lon << ", " << lat << ", " << alt
156 geod_view_pos = Point3D( lon, lat, alt );
158 inline void set_sea_level_radius( double r ) {
159 // data should be in meters from the center of the earth
161 sea_level_radius = r;
163 inline void set_hpr( double h, double p, double r ) {
164 // data should be in radians
166 sgSetVec3( hpr, h, p, r );
168 inline void set_pilot_offset( float x, float y, float z ) {
170 sgSetVec3( pilot_offset, x, y, z );
172 inline void set_view_offset( double a ) {
176 inline void inc_view_offset( double amt ) {
180 inline void set_goal_view_offset( double a) {
182 goal_view_offset = a;
185 //////////////////////////////////////////////////////////////////////
186 // accessor functions
187 //////////////////////////////////////////////////////////////////////
188 inline double get_view_offset() const { return view_offset; }
189 inline double get_goal_view_offset() const { return goal_view_offset; }
190 inline float *get_pilot_offset() { return pilot_offset; }
191 inline double get_sea_level_radius() const { return sea_level_radius; }
192 inline float *get_hpr() { return hpr; }
194 //////////////////////////////////////////////////////////////////////
195 // derived values accessor functions
196 //////////////////////////////////////////////////////////////////////
197 inline Point3D get_abs_view_pos() {
198 if ( dirty ) { update(); }
201 inline Point3D get_view_pos() {
202 if ( dirty ) { update(); }
205 inline Point3D get_cur_zero_elev() {
206 if ( dirty ) { update(); }
207 return cur_zero_elev;
209 inline float *get_surface_south() {
210 if ( dirty ) { update(); }
211 return surface_south;
213 inline float *get_surface_east() {
214 if ( dirty ) { update(); }
217 inline float *get_local_up() {
218 if ( dirty ) { update(); }
221 inline float *get_view_forward() {
222 if ( dirty ) { update(); }
225 inline const sgVec4 *get_VIEW() {
226 if ( dirty ) { update(); }
229 inline const sgVec4 *get_VIEW_ROT() {
230 if ( dirty ) { update(); }
234 //////////////////////////////////////////////////////////////////////
236 //////////////////////////////////////////////////////////////////////
237 inline float *get_to_sun() { return to_sun; }
238 inline void set_to_sun( float x, float y, float z ) {
239 sgSetVec3( to_sun, x, y, z );
241 inline float *get_surface_to_sun() { return surface_to_sun; }
242 inline void set_surface_to_sun( float x, float y, float z) {
243 sgSetVec3( surface_to_sun, x, y, z );
245 inline float *get_to_moon() { return to_moon; }
246 inline void set_to_moon( float x, float y, float z) {
247 sgSetVec3( to_moon, x, y, z );
249 inline float *get_surface_to_moon() { return surface_to_moon; }
250 inline void set_surface_to_moon( float x, float y, float z) {
251 sgSetVec3( surface_to_moon, x, y, z );
256 #endif // _VIEWER_HXX