#endif
#include <simgear/compiler.h>
-#include <simgear/math/point3d.hxx>
-#include <simgear/timing/sg_time.hxx>
-
-#include <list>
+#include <simgear/constants.h>
#include <plib/sg.h> // plib include
-#include <FDM/flight.hxx>
-#include <Time/light.hxx>
-
-
-FG_USING_STD(list);
+#include "fgfs.hxx"
#define FG_FOV_MIN 0.1
#define FG_FOV_MAX 179.9
+/**
+ * Representation of a single viewpoint in the FlightGear world.
+ */
+class FGViewPoint
+{
+public:
+ FGViewPoint ();
+ virtual ~FGViewPoint ();
+
+ /**
+ * Set the geodetic position for the view point.
+ */
+ virtual void setPosition (double lon_deg, double lat_deg, double alt_ft);
+
+
+ /**
+ * Get the longitude in degrees.
+ */
+ virtual double getLongitude_deg () const { return _lon_deg; }
+
+ /**
+ * Get the latitude in degrees.
+ */
+ virtual double getLatitude_deg () const { return _lat_deg; }
+
+ /**
+ * Get the altitude in feet ASL.
+ */
+ virtual double getAltitudeASL_ft () const { return _alt_ft; }
+
+ /**
+ * Get the absolute view position in fgfs coordinates.
+ */
+ virtual const double * getAbsoluteViewPos () const;
+
+
+ /**
+ * Get the relative view position in fgfs coordinates.
+ *
+ * The position is relative to the scenery centre.
+ */
+ virtual const float * getRelativeViewPos () const;
+
+
+ /**
+ * Get the absolute zero-elevation view position in fgfs coordinates.
+ */
+ virtual const float * getZeroElevViewPos () const;
+
+private:
+
+ void recalc () const;
+
+ mutable sgdVec3 _absolute_view_pos;
+ mutable sgVec3 _relative_view_pos;
+ mutable sgVec3 _zero_elev_view_pos;
+
+ bool _dirty;
+ double _lon_deg;
+ double _lat_deg;
+ double _alt_ft;
+
+};
+
+
// Define a structure containing view information
class FGViewer {
+public:
+
+ enum fgViewType {
+ FG_RPH = 0,
+ FG_LOOKAT = 1,
+ FG_HPR = 2
+ };
+
+ enum fgScalingType { // nominal Field Of View actually applies to ...
+ FG_SCALING_WIDTH, // window width
+ FG_SCALING_MAX, // max(width, height)
+ // FG_SCALING_G_MEAN, // geometric_mean(width, height)
+ // FG_SCALING_INDEPENDENT // whole screen
+ };
+
private:
// flag forcing a recalc of derived view parameters
bool dirty;
-
+
+protected:
+
+ fgViewType _type;
+ fgScalingType scalingType;
+
+ FGViewPoint view_point;
+
+ // the nominal field of view (angle, in degrees)
+ double fov;
+
+ // ratio of window width and height; height = width * aspect_ratio
+ double aspect_ratio;
+
// the current view offset angle from forward (rotated about the
// view_up vector)
double view_offset;
+ bool reverse_view_offset;
// the goal view offset angle (used for smooth view changes)
double goal_view_offset;
+ // the view tilt angles
+ double view_tilt;
+ double goal_view_tilt;
+
// geodetic view position
sgdVec3 geod_view_pos;
- // radius to sea level from center of the earth (m)
- double sea_level_radius;
-
// absolute view position in earth coordinates
sgdVec3 abs_view_pos;
// abs_view_pos translated to scenery.center)
sgVec3 view_pos;
- // 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;
-
- // view orientation (roll, pitch, heading)
- sgVec3 rph;
+ // 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
- 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;
+ sgVec3 zero_elev;
- // surface direction to go to head towards sun
- sgVec3 surface_to_sun;
+ // height ASL of the terrain for our current view position
+ // (future?) double ground_elev;
- // vector in cartesian coordinates from current position to the
- // postion on the earth's surface the moon is directly over
- sgVec3 to_moon;
-
- // surface direction to go to head towards moon
- sgVec3 surface_to_moon;
+ // 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;
// surface vector heading south
sgVec3 surface_south;
// 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;
-
- // 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 the view direction offset relative to
- // the AIRCRAFT matrix
- sgMat4 VIEW_OFFSET;
+ sgVec3 world_up;
// sg versions of our friendly matrices
- sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
+ sgMat4 VIEW, VIEW_ROT, UP;
+
+ inline void set_dirty() { dirty = true; }
+ inline void set_clean() { dirty = false; }
// Update the view volume, position, and orientation
- void update();
+ virtual void update() = 0;
public:
FGViewer( void );
// Destructor
- ~FGViewer( void );
+ virtual ~FGViewer( void );
- // Initialize a view class
- void init( void );
-
- // Transform a vector from world coordinates to the local plane
- void CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src);
+ virtual void init ();
+ virtual void bind ();
+ virtual void unbind ();
+ virtual void update (int dt);
//////////////////////////////////////////////////////////////////////
// setter functions
//////////////////////////////////////////////////////////////////////
- inline void set_geod_view_pos( double lon, double lat, double alt ) {
- // data should be in radians and meters asl
- dirty = true;
- // cout << "set_geod_view_pos = " << lon << ", " << lat << ", " << alt
- // << endl;
- sgdSetVec3( geod_view_pos, lon, lat, alt );
- }
- inline void set_sea_level_radius( double r ) {
- // data should be in meters from the center of the earth
- dirty = true;
- sea_level_radius = r;
- }
- inline void set_rph( double r, double p, double h ) {
- // data should be in radians
- dirty = true;
- sgSetVec3( rph, r, p, h );
+
+ inline void set_fov( double fov_deg ) {
+ fov = fov_deg;
}
- inline void set_pilot_offset( float x, float y, float z ) {
- dirty = true;
- sgSetVec3( pilot_offset, x, y, z );
+
+ inline void set_aspect_ratio( double r ) {
+ aspect_ratio = r;
}
inline void set_view_offset( double a ) {
- dirty = true;
+ set_dirty();
view_offset = a;
}
inline void inc_view_offset( double amt ) {
- dirty = true;
+ set_dirty();
view_offset += amt;
}
inline void set_goal_view_offset( double a) {
- dirty = true;
+ set_dirty();
goal_view_offset = a;
+ while ( goal_view_offset < 0.0 ) {
+ goal_view_offset += SGD_2PI;
+ }
+ while ( goal_view_offset > SGD_2PI ) {
+ goal_view_offset -= SGD_2PI;
+ }
+ }
+ inline void set_reverse_view_offset( bool val ) {
+ reverse_view_offset = val;
+ }
+ inline void set_view_tilt( double a ) {
+ set_dirty();
+ view_tilt = a;
+ }
+ inline void inc_view_tilt( double amt ) {
+ set_dirty();
+ view_tilt += amt;
+ }
+ inline void set_goal_view_tilt( double a) {
+ set_dirty();
+ goal_view_tilt = a;
+ while ( goal_view_tilt < 0 ) {
+ goal_view_tilt += 360.0;
+ }
+ while ( goal_view_tilt > 360.0 ) {
+ goal_view_tilt -= 360.0;
+ }
+ }
+ 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 int get_type() const { return _type ; }
+ inline int is_a( int t ) const { return get_type() == t ; }
+ inline bool is_dirty() const { return dirty; }
+ inline double get_fov() const { return fov; }
+ inline double get_aspect_ratio() const { return aspect_ratio; }
inline double get_view_offset() const { return view_offset; }
+ inline bool get_reverse_view_offset() const { return reverse_view_offset; }
inline double get_goal_view_offset() const { return goal_view_offset; }
+ inline double get_view_tilt() const { return view_tilt; }
+ inline double get_goal_view_tilt() const { return goal_view_tilt; }
+ inline double *get_geod_view_pos() { return geod_view_pos; }
inline float *get_pilot_offset() { return pilot_offset; }
inline double get_sea_level_radius() const { return sea_level_radius; }
- inline float *get_rph() { return rph; }
+ // Get horizontal field of view angle, in degrees.
+ double get_h_fov();
+ // Get vertical field of view angle, in degrees.
+ double get_v_fov();
//////////////////////////////////////////////////////////////////////
// derived values accessor functions
if ( dirty ) { update(); }
return view_pos;
}
- inline Point3D get_cur_zero_elev() {
+ inline float *get_zero_elev() {
if ( dirty ) { update(); }
- return cur_zero_elev;
+ return zero_elev;
}
+ // (future?)
+ // inline double get_ground_elev() {
+ // if ( dirty ) { update(); }
+ // return ground_elev;
+ // }
inline float *get_surface_south() {
if ( dirty ) { update(); }
return surface_south;
if ( dirty ) { update(); }
return surface_east;
}
- inline float *get_local_up() {
- if ( dirty ) { update(); }
- return local_up;
- }
- inline float *get_view_forward() {
+ inline float *get_world_up() {
if ( dirty ) { update(); }
- return view_forward;
+ return world_up;
}
inline const sgVec4 *get_VIEW() {
if ( dirty ) { update(); }
if ( dirty ) { update(); }
return VIEW_ROT;
}
-
- //////////////////////////////////////////////////////////////////////
- // 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 );
- }
- inline float *get_surface_to_sun() { return surface_to_sun; }
- inline void set_surface_to_sun( float x, float y, float z) {
- sgSetVec3( surface_to_sun, x, y, z );
- }
- inline float *get_to_moon() { return to_moon; }
- inline void set_to_moon( float x, float y, float z) {
- sgSetVec3( to_moon, x, y, z );
- }
- inline float *get_surface_to_moon() { return surface_to_moon; }
- inline void set_surface_to_moon( float x, float y, float z) {
- sgSetVec3( surface_to_moon, x, y, z );
+ inline const sgVec4 *get_UP() {
+ if ( dirty ) { update(); }
+ return UP;
}
};