1
0
Fork 0
flightgear/src/Main/location.hxx

164 lines
5 KiB
C++
Raw Normal View History

This patch includes the FGLocation class, a few fixes, cleanup in viewer code. Synced to CVS 19:36 EDT 2002-04-10 (after this evenings JSMsim and Base package updates). Description: Added FGLocation class which is new home for calculating matrix rotations. Viewer can now be configured to access rotations created by the model rather than repeating the same calculations again. Changed model initialization for the time being so that its location data is available for the viewer (currently required by other subsystems). At some point we can move this back to fg_init along with the viewer initialization. Seperated the update from the draw function in the model code. The viewer code needs the same matrix data, and moving the update portion at this time does not increase the number of matrix math iterations. Moved the model draw so that it always appears "in front" of lights and clouds. Reogranized viewer update routine for using the FGLocation class and simplified some more tasks. The routine is fairly easy to follow now, with the steps ordered and spelled out in comments. Viewmgr only updates the current (visible) view now, with the exception of an old reference to "chase view" that will be corrected in forthcoming changes. Also will be doing some work on the viewmgr outputs. Model is now clears the z-buffer in all modes. This will be changed with the next viewmgr update. The only side effect is that models always disappear when over 5km distant from the eye point (can't really see them anyway:-)). Other than a flag to indicate "internal" view I don't anticipate the configuration interface for viewmgr/views will be changed a lot for now. It is close to done. The next viewmgr update will however rework the outputs so may change location. This code will run with the previous version of preferences.xml, but will run faster with the newer version. I am attaching a preferences.xml that should not be commited before the code. All the changes are in the /sim/view section and should show a simpler view configuration that references model locations. Note that I've added a 2nd tower view in "lookfrom" mode for illustration purposes. You can look around using the mouse. You may want to remove that or comment it out.
2002-04-11 04:26:07 +00:00
// location.hxx -- class for determining model location in the flightgear world.
//
// Written by Jim Wilson, David Megginson, started April 2002.
// overhaul started October 2000.
//
// This file is in the Public Domain, and comes with no warranty.
#ifndef _LOCATION_HXX
#define _LOCATION_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <simgear/compiler.h>
#include <simgear/constants.h>
#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; }
// Matrices...
virtual const sgMat4 &getTransformMatrix() { if ( _dirty ) { recalc(); } return TRANS; }
virtual const sgMat4 &getCachedTransformMatrix() { return TRANS; }
virtual const sgMat4 &getUpMatrix() { if ( _dirty ) { recalc(); } return UP; }
virtual const sgMat4 &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;
// 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