This is a small fix for what turned out to be a major bug. Ground elevation was calculated incorrectly when distant from one of the view locations. This resulted in several problems including bizarre gear trimming, mid air "crashes" (as in thinking we hit the ground) and so on when close to or on the ground. Unfortunately it does require a second ssg traversal when in tower view (only), but the increased load isn't all that noticable. For the time being this really is the best solution. In a future update I will be eliminating the unecessary per frame traversals for the static views (without having to maintain multiple ssgRoots). When we go to multiple FDM instances we will perhaps need to put the ssg traversal and ground elevation queries for the FDMs into an event timer that updates the FDMs ground elevation in a round robin fashion (maybe every 1/n seconds where n is the number of FDM instances running).
185 lines
6.7 KiB
C++
185 lines
6.7 KiB
C++
// location.hxx -- class for determining model location in the flightgear world.
|
|
//
|
|
// Written by Jim Wilson, David Megginson, started April 2002.
|
|
//
|
|
// Copyright (C) 2002 Jim Wilson, David Megginson
|
|
//
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License as
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
//
|
|
// $Id$
|
|
|
|
|
|
#ifndef _LOCATION_HXX
|
|
#define _LOCATION_HXX
|
|
|
|
|
|
#ifndef __cplusplus
|
|
# error This library requires C++
|
|
#endif
|
|
|
|
#include <simgear/compiler.h>
|
|
#include <simgear/constants.h>
|
|
#include <simgear/bucket/newbucket.hxx>
|
|
#include <simgear/math/point3d.hxx>
|
|
|
|
#include <plib/sg.h> // plib include
|
|
|
|
#include "fgfs.hxx"
|
|
|
|
|
|
// Define a structure containing view information
|
|
class FGLocation
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructor
|
|
FGLocation( void );
|
|
|
|
// Destructor
|
|
virtual ~FGLocation( void );
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Part 1: standard FGSubsystem implementation.
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
virtual void init ();
|
|
virtual void bind ();
|
|
virtual void unbind ();
|
|
void update (int dt);
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Part 2: user settings.
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Geodetic position of model...
|
|
virtual double getLongitude_deg () const { return _lon_deg; }
|
|
virtual double getLatitude_deg () const { return _lat_deg; }
|
|
virtual double getAltitudeASL_ft () const { return _alt_ft; }
|
|
virtual void setPosition (double lon_deg, double lat_deg, double alt_ft);
|
|
|
|
|
|
// Reference orientation rotations...
|
|
// These are rotations that represent the plane attitude effect on
|
|
// the view (in Pilot view). IE The view frustrum rotates as the plane
|
|
// turns, pitches, and rolls.
|
|
// In model view (lookat/chaseview) these end up changing the angle that
|
|
// the eye is looking at the ojbect (ie the model).
|
|
// FIXME: the FGModel class should have its own version of these so that
|
|
// it can generate it's own model rotations.
|
|
virtual double getRoll_deg () const { return _roll_deg; }
|
|
virtual double getPitch_deg () const {return _pitch_deg; }
|
|
virtual double getHeading_deg () const {return _heading_deg; }
|
|
virtual void setOrientation (double roll_deg, double pitch_deg, double heading_deg);
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Part 3: output vectors and matrices in FlightGear coordinates.
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Vectors and positions...
|
|
|
|
// Get zero view_pos
|
|
virtual float * get_view_pos() { return _relative_view_pos; }
|
|
// Get the absolute view position in fgfs coordinates.
|
|
virtual double * get_absolute_view_pos ();
|
|
// Get zero elev
|
|
virtual float * get_zero_elev() { return _zero_elev_view_pos; }
|
|
// Get world up vector
|
|
virtual float *get_world_up() { return _world_up; }
|
|
// Get the relative (to scenery center) view position in fgfs coordinates.
|
|
virtual float * getRelativeViewPos ();
|
|
// Get the absolute zero-elevation view position in fgfs coordinates.
|
|
virtual float * getZeroElevViewPos ();
|
|
// Get surface east vector
|
|
virtual float *get_surface_east() { return _surface_east; }
|
|
// Get surface south vector
|
|
virtual float *get_surface_south() { return _surface_south; }
|
|
// Elevation of ground under location (based on scenery output)...
|
|
void set_cur_elev_m ( double elev ) { _cur_elev_m = elev; }
|
|
inline double get_cur_elev_m () { return _cur_elev_m; }
|
|
// Interface to current buckets for use with tilemgr...
|
|
void set_current_bucket ( SGBucket current_bucket ) { _current_bucket = current_bucket; }
|
|
inline SGBucket get_current_bucket () { return _current_bucket; }
|
|
void set_previous_bucket ( SGBucket previous_bucket ) { _previous_bucket = previous_bucket; }
|
|
inline SGBucket get_previous_bucket () { return _previous_bucket; }
|
|
void set_tile_center ( Point3D tile_center ) { _tile_center = tile_center; }
|
|
inline Point3D get_tile_center () { return _tile_center; }
|
|
|
|
// Matrices...
|
|
virtual const sgVec4 * getTransformMatrix() { if ( _dirty ) { recalc(); } return TRANS; }
|
|
virtual const sgVec4 * getCachedTransformMatrix() { return TRANS; }
|
|
virtual const sgVec4 * getUpMatrix() { if ( _dirty ) { recalc(); } return UP; }
|
|
virtual const sgVec4 * getCachedUpMatrix() { return UP; }
|
|
|
|
|
|
private:
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
// private data //
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// flag forcing a recalc of derived view parameters
|
|
bool _dirty;
|
|
|
|
mutable sgdVec3 _absolute_view_pos;
|
|
mutable sgVec3 _relative_view_pos;
|
|
mutable sgVec3 _zero_elev_view_pos;
|
|
|
|
double _lon_deg;
|
|
double _lat_deg;
|
|
double _alt_ft;
|
|
|
|
double _roll_deg;
|
|
double _pitch_deg;
|
|
double _heading_deg;
|
|
|
|
// elevation of ground under this location...
|
|
double _cur_elev_m;
|
|
// current and previous scenery buckets to be saved for use in
|
|
// getting current elevation from tilemgr.
|
|
SGBucket _previous_bucket;
|
|
SGBucket _current_bucket;
|
|
Point3D _tile_center;
|
|
|
|
// surface vector heading south
|
|
sgVec3 _surface_south;
|
|
|
|
// surface vector heading east (used to unambiguously align sky
|
|
// with sun)
|
|
sgVec3 _surface_east;
|
|
|
|
// world up vector (normal to the plane tangent to the earth's
|
|
// surface at the spot we are directly above
|
|
sgVec3 _world_up;
|
|
|
|
// sg versions of our friendly matrices
|
|
sgMat4 TRANS, UP;
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
// private functions //
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
void recalc ();
|
|
void recalcPosition (double lon_deg, double lat_deg, double alt_ft) const;
|
|
|
|
inline void set_dirty() { _dirty = true; }
|
|
inline void set_clean() { _dirty = false; }
|
|
|
|
};
|
|
|
|
|
|
#endif // _LOCATION_HXX
|