]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/viewer.hxx
Added a viewmgr system and made corresponding changes to support it.
[flightgear.git] / src / Main / viewer.hxx
index 19d5f2563c0500f92a3eb44170888b83270d15b9..0253dc459345f6ce7775e926adf452d66c80383f 100644 (file)
 #endif                                   
 
 #include <simgear/compiler.h>
-#include <simgear/math/point3d.hxx>
-#include <simgear/timing/sg_time.hxx>
-
-#include <list>
 
 #include <plib/sg.h>           // plib include
 
-#include <FDM/flight.hxx>
-#include <Time/light.hxx>
-
-
-FG_USING_STD(list);
-
-
-#define FG_FOV_MIN 0.1
-#define FG_FOV_MAX 179.9
-
 
 // Define a structure containing view information
 class FGViewer {
 
 private:
 
+    // flag forcing a recalc of derived view parameters
+    bool dirty;
+
+protected:
+
     // the current view offset angle from forward (rotated about the
     // view_up vector)
     double view_offset;
@@ -61,32 +52,28 @@ private:
     // the goal view offset angle  (used for smooth view changes)
     double goal_view_offset;
 
-    // flag forcing update of fov related stuff
-    bool update_fov;
-       
-    // fov of view is specified in the X direction, win_ratio is used to
-    // calculate the fov in the Y direction.  fov(y) = fov(x) * win_ratio
-    double win_ratio;
-
-    // width & height of window
-    // int winWidth, winHeight;
+    // geodetic view position
+    sgdVec3 geod_view_pos;
 
     // absolute view position in earth coordinates
-    Point3D abs_view_pos;
+    sgdVec3 abs_view_pos;
 
     // view position in opengl world coordinates (this is the
     // abs_view_pos translated to scenery.center)
-    Point3D view_pos;
+    sgVec3 view_pos;
+
+    // radius to sea level from center of the earth (m)
+    double sea_level_radius;
+
+    // cartesion coordinates of current lon/lat if at sea level
+    // translated to scenery.center
+    sgVec3 zero_elev;
 
     // pilot offset from center of gravity.  The X axis is positive
     // out the tail, Y is out the right wing, and Z is positive up.
     // Distances in meters of course.
     sgVec3 pilot_offset;
 
-    // cartesion coordinates of current lon/lat if at sea level
-    // translated to scenery.center
-    Point3D cur_zero_elev;
-
     // vector in cartesian coordinates from current position to the
     // postion on the earth's surface the sun is directly over
     sgVec3 to_sun;
@@ -108,26 +95,18 @@ private:
     // with sun)
     sgVec3 surface_east;
 
-    // local up vector (normal to the plane tangent to the earth's
+    // world up vector (normal to the plane tangent to the earth's
     // surface at the spot we are directly above
-    sgVec3 local_up;
+    sgVec3 world_up;
 
-    // up vector for the view (usually point straight up through the
-    // top of the aircraft
-    sgVec3 view_up;
-
-    // the vector pointing straight out the nose of the aircraft
-    sgVec3 view_forward;
-
-    // Transformation matrix for eye coordinates to aircraft coordinates
-    // sgMat4 AIRCRAFT;
+    // sg versions of our friendly matrices
+    sgMat4 VIEW, VIEW_ROT, UP;
 
-    // Transformation matrix for the view direction offset relative to
-    // the AIRCRAFT matrix
-    sgMat4 VIEW_OFFSET;
+    inline void set_dirty() { dirty = true; }
+    inline void set_clean() { dirty = false; }
 
-    // sg versions of our friendly matrices
-    sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
+    // Update the view volume, position, and orientation
+    virtual void update();
 
 public:
 
@@ -135,46 +114,93 @@ public:
     FGViewer( void );
 
     // Destructor
-    ~FGViewer( void );
-
-    // Initialize a view class
-    void Init( void );
-
-    // Update the view volume, position, and orientation
-    void UpdateViewParams( const FGInterface& f );
-
-    // Flag to request that UpdateFOV() be called next time
-    // UpdateViewMath() is run.
-    inline void force_update_fov_math() { update_fov = true; }
-
-    // Update the view parameters
-    void UpdateViewMath( const FGInterface& f );
-
-    // Update the field of view coefficients
-    void UpdateFOV( const FGOptions *o );
-
-    // Transform a vector from world coordinates to the local plane
-    void CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src);
+    virtual ~FGViewer( void );
+
+    //////////////////////////////////////////////////////////////////////
+    // setter functions
+    //////////////////////////////////////////////////////////////////////
+    inline void set_view_offset( double a ) {
+       set_dirty();
+       view_offset = a;
+    }
+    inline void inc_view_offset( double amt ) {
+       set_dirty();
+       view_offset += amt;
+    }
+    inline void set_goal_view_offset( double a) {
+       set_dirty();
+       goal_view_offset = a;
+    }
+    inline void set_geod_view_pos( double lon, double lat, double alt ) {
+       // data should be in radians and meters asl
+       set_dirty();
+       // cout << "set_geod_view_pos = " << lon << ", " << lat << ", " << alt
+       //      << endl;
+       sgdSetVec3( geod_view_pos, lon, lat, alt );
+    }
+    inline void set_pilot_offset( float x, float y, float z ) {
+       set_dirty();
+       sgSetVec3( pilot_offset, x, y, z );
+    }
+    inline void set_sea_level_radius( double r ) {
+       // data should be in meters from the center of the earth
+       set_dirty();
+       sea_level_radius = r;
+    }
 
+    //////////////////////////////////////////////////////////////////////
     // accessor functions
+    //////////////////////////////////////////////////////////////////////
+    inline bool is_dirty() const { return dirty; }
     inline double get_view_offset() const { return view_offset; }
-    inline void set_view_offset( double a ) { view_offset = a; }
-    inline void inc_view_offset( double amt ) { view_offset += amt; }
     inline double get_goal_view_offset() const { return goal_view_offset; }
-    inline void set_goal_view_offset( double a) { goal_view_offset = a; }
-    inline double get_win_ratio() const { return win_ratio; }
-    inline void set_win_ratio( double r ) { win_ratio = r; }
-    // inline int get_winWidth() const { return winWidth; }
-    // inline void set_winWidth( int w ) { winWidth = w; }
-    // inline int get_winHeight() const { return winHeight; }
-    // inline void set_winHeight( int h ) { winHeight = h; }
-    inline Point3D get_abs_view_pos() const { return abs_view_pos; }
-    inline Point3D get_view_pos() const { return view_pos; }
+    inline double *get_geod_view_pos() { return geod_view_pos; }
     inline float *get_pilot_offset() { return pilot_offset; }
-    inline void set_pilot_offset( float x, float y, float z ) {
-       sgSetVec3( pilot_offset, x, y, z );
+    inline double get_sea_level_radius() const { return sea_level_radius; }
+
+    //////////////////////////////////////////////////////////////////////
+    // derived values accessor functions
+    //////////////////////////////////////////////////////////////////////
+    inline double *get_abs_view_pos() {
+       if ( dirty ) { update(); }
+       return abs_view_pos;
+    }
+    inline float *get_view_pos() {
+       if ( dirty ) { update(); }
+       return view_pos;
+    }
+    inline float *get_zero_elev() {
+       if ( dirty ) { update(); }
+       return zero_elev;
+    }
+    inline float *get_surface_south() {
+       if ( dirty ) { update(); }
+       return surface_south;
+    }
+    inline float *get_surface_east() {
+       if ( dirty ) { update(); }
+       return surface_east;
+    }
+    inline float *get_world_up() {
+       if ( dirty ) { update(); }
+       return world_up;
     }
-    inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
+    inline const sgVec4 *get_VIEW() {
+       if ( dirty ) { update(); }
+       return VIEW;
+    }
+    inline const sgVec4 *get_VIEW_ROT() {
+       if ( dirty ) { update(); }
+       return VIEW_ROT;
+    }
+    inline const sgVec4 *get_UP() {
+       if ( dirty ) { update(); }
+       return UP;
+    }
+
+    //////////////////////////////////////////////////////////////////////
+    // need to fix these
+    //////////////////////////////////////////////////////////////////////
     inline float *get_to_sun() { return to_sun; }
     inline void set_to_sun( float x, float y, float z ) {
        sgSetVec3( to_sun, x, y, z );
@@ -191,15 +217,9 @@ public:
     inline void set_surface_to_moon( float x, float y, float z) {
        sgSetVec3( surface_to_moon, x, y, z );
     }
-    inline float *get_surface_south() { return surface_south; }
-    inline float *get_surface_east() { return surface_east; }
-    inline float *get_local_up() { return local_up; }
-    inline float *get_view_forward() { return view_forward; }
-
-    inline const sgVec4 *get_VIEW() { return VIEW; }
-    inline const sgVec4 *get_VIEW_ROT() { return VIEW_ROT; }
 };
 
+
 #endif // _VIEWER_HXX