]> git.mxchange.org Git - flightgear.git/blobdiff - Main/views.hxx
Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
[flightgear.git] / Main / views.hxx
index c4b3358785bdbb32e58ab498717f9a0620980f75..60520ad6931999e616592e6583a7f00c7d5933fc 100644 (file)
@@ -1,4 +1,3 @@
-//
 // views.hxx -- data structures and routines for managing and view parameters.
 //
 // Written by Curtis Olson, started August 1997.
 #endif                                   
 
 
-#include <Include/fg_types.h>
-#include <Flight/flight.h>
+#include <FDM/flight.hxx>
 #include <Math/mat3.h>
+#include <Math/point3d.hxx>
 #include <Time/fg_time.hxx>
 #include <Time/light.hxx>
 
 #include "options.hxx"
 
-#ifndef BOOL
-#define BOOL int
-#endif
 
-#ifndef TRUE
-#define FALSE 0
-#define TRUE 1
-#endif
+// used in views.cxx and tilemgr.cxx
+#define USE_FAST_FOV_CLIP 
 
-// Define a structure containing view information
-class fgVIEW {
 
-public:
+// Define a structure containing view information
+class FGView {
 
     // the current offset from forward for viewing
     double view_offset;
@@ -61,7 +54,7 @@ public:
     double goal_view_offset;
 
     // flag forcing update of fov related stuff
-    BOOL update_fov;
+    bool update_fov;
        
     // fov of view is specified in the y direction, win_ratio is used to
     // calculate the fov in the X direction = width/height
@@ -72,6 +65,7 @@ public:
 
     // sin and cos of (fov / 2) in Y axis
     double sin_fov_y, cos_fov_y;
+    double sinlon, coslon;
 
     // slope of view frustum edge in eye space Y axis
     double slope_y;
@@ -82,19 +76,26 @@ public:
     // slope of view frustum edge in eye space X axis
     double slope_x;
 
+#if defined( USE_FAST_FOV_CLIP )
+    double fov_x_clip, fov_y_clip;
+#endif // USE_FAST_FOV_CLIP
+
     // View frustum cull ratio (% of tiles culled ... used for
     // reporting purposes)
     double vfc_ratio;
 
+    // Number of triangles rendered;
+    int tris_rendered;
+
     // absolute view position
-    fgCartesianPoint3d abs_view_pos;
+    Point3D abs_view_pos;
 
     // view position translated to scenery.center
-    fgCartesianPoint3d view_pos;
+    Point3D view_pos;
 
     // cartesion coordinates of current lon/lat if at sea level
     // translated to scenery.center*/
-    fgCartesianPoint3d cur_zero_elev;
+    Point3D cur_zero_elev;
 
     // vector in cartesian coordinates from current position to the
     // postion on the earth's surface the sun is directly over
@@ -124,6 +125,10 @@ public:
     // Transformation matrix for eye coordinates to aircraft coordinates
     MAT3mat AIRCRAFT;
 
+    // Transformation matrix for the view direction offset relative to
+    // the AIRCRAFT matrix
+    MAT3mat VIEW_OFFSET;
+
     // Transformation matrix for aircraft coordinates to world
     // coordinates
     MAT3mat WORLD;
@@ -135,33 +140,147 @@ public:
     // coordinates to eye coordinates
     MAT3mat WORLD_TO_EYE;
 
+    // Current model view matrix;
+    GLdouble MODEL_VIEW[16];
+
+public:
+
     // Constructor
-    fgVIEW( void );
+    FGView( void );
+
+    // Destructor
+    ~FGView( void );
 
     // Initialize a view class
     void Init( void );
 
+    // Basically, this is a modified version of the Mesa gluLookAt()
+    // function that's been modified slightly so we can capture the
+    // result (and use it later) otherwise this all gets calculated in
+    // OpenGL land and we don't have access to the results.
+    void LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
+                GLdouble centerx, GLdouble centery, GLdouble centerz,
+                GLdouble upx, GLdouble upy, GLdouble upz );
+
+    // Update the view volume, position, and orientation
+    void UpdateViewParams( void );
+
+    // 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 Update( fgFLIGHT *f );
+    void UpdateViewMath( FGState *f );
 
     // Update the "World to Eye" transformation matrix
-    void UpdateWorldToEye(  fgFLIGHT *f );
-
-    // Update the field of view parameters
-    void UpdateFOV( fgOPTIONS *o );
-       
-    // Destructor
-    ~fgVIEW( void );
+    void UpdateWorldToEye( FGState *f );
+
+    // Update the field of view coefficients
+    void UpdateFOV( const fgOPTIONS& o );
+
+    // accessor functions
+    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 double get_slope_y() const { return slope_y; }
+    inline double get_slope_x() const { return slope_x; }
+#if defined( USE_FAST_FOV_CLIP )
+    inline double get_fov_x_clip() const { return fov_x_clip; }
+    inline double get_fov_y_clip() const { return fov_y_clip; }
+#endif // USE_FAST_FOV_CLIP
+    inline double get_vfc_ratio() const { return vfc_ratio; }
+    inline void set_vfc_ratio(double r) { vfc_ratio = r; }
+    inline int get_tris_rendered() const { return tris_rendered; }
+    inline void set_tris_rendered( int tris) { tris_rendered = tris; }
+    inline Point3D get_abs_view_pos() const { return abs_view_pos; }
+    inline Point3D get_view_pos() const { return view_pos; }
+    inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
+    inline double *get_to_sun() { return to_sun; }
+    inline void set_to_sun( double x, double y, double z) {
+       to_sun[0] = x;
+       to_sun[1] = y;
+       to_sun[2] = z;
+    }
+    inline double *get_surface_to_sun() { return surface_to_sun; }
+    inline void set_surface_to_sun( double x, double y, double z) {
+       surface_to_sun[0] = x;
+       surface_to_sun[1] = y;
+       surface_to_sun[2] = z;
+    }
+    inline double *get_surface_south() { return surface_south; }
+    inline double *get_surface_east() { return surface_east; }
+    inline double *get_local_up() { return local_up; }
+    inline MAT3mat *get_WORLD_TO_EYE() const { return &WORLD_TO_EYE; }
+    inline GLdouble *get_MODEL_VIEW() { return MODEL_VIEW; }
 };
 
 
-extern fgVIEW current_view;
+extern FGView current_view;
 
 
 #endif // _VIEWS_HXX
 
 
 // $Log$
+// Revision 1.19  1999/02/01 21:33:36  curt
+// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
+// Jon accepted my offer to do this and thought it was a good idea.
+//
+// Revision 1.18  1998/12/11 20:26:30  curt
+// Fixed view frustum culling accuracy bug so we can look out the sides and
+// back without tri-stripes dropping out.
+//
+// Revision 1.17  1998/12/09 18:50:29  curt
+// Converted "class fgVIEW" to "class FGView" and updated to make data
+// members private and make required accessor functions.
+//
+// Revision 1.16  1998/12/05 15:54:25  curt
+// Renamed class fgFLIGHT to class FGState as per request by JSB.
+//
+// Revision 1.15  1998/10/16 23:27:56  curt
+// C++-ifying.
+//
+// Revision 1.14  1998/10/16 00:54:04  curt
+// Converted to Point3D class.
+//
+// Revision 1.13  1998/09/08 15:04:36  curt
+// Optimizations by Norman Vine.
+//
+// Revision 1.12  1998/08/24 20:11:15  curt
+// Added i/I to toggle full vs. minimal HUD.
+// Added a --hud-tris vs --hud-culled option.
+// Moved options accessor funtions to options.hxx.
+//
+// Revision 1.11  1998/08/20 20:32:35  curt
+// Reshuffled some of the code in and around views.[ch]xx
+//
+// Revision 1.10  1998/07/08 14:45:09  curt
+// polar3d.h renamed to polar3d.hxx
+// vector.h renamed to vector.hxx
+// updated audio support so it waits to create audio classes (and tie up
+//   /dev/dsp) until the mpg123 player is finished.
+//
+// Revision 1.9  1998/07/04 00:52:27  curt
+// Add my own version of gluLookAt() (which is nearly identical to the
+// Mesa/glu version.)  But, by calculating the Model View matrix our selves
+// we can save this matrix without having to read it back in from the video
+// card.  This hopefully allows us to save a few cpu cycles when rendering
+// out the fragments because we can just use glLoadMatrixd() with the
+// precalculated matrix for each tile rather than doing a push(), translate(),
+// pop() for every fragment.
+//
+// Panel status defaults to off for now until it gets a bit more developed.
+//
+// Extract OpenGL driver info on initialization.
+//
 // Revision 1.8  1998/05/27 02:24:06  curt
 // View optimizations by Norman Vine.
 //