1
0
Fork 0
flightgear/src/Model/model.hxx

240 lines
5.2 KiB
C++
Raw Normal View History

// model.hxx - manage a 3D aircraft model.
// Written by David Megginson, started 2002.
//
// This file is in the Public Domain, and comes with no warranty.
#ifndef __MODEL_HXX
#define __MODEL_HXX 1
#ifndef __cplusplus
# error This library requires C++
#endif
#include <vector>
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 you can expect that the data that viewmgr is writing to the property tree 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:25:30 +00:00
#include <plib/ssg.h>
SG_USING_STD(vector);
#include <Main/fg_props.hxx>
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 you can expect that the data that viewmgr is writing to the property tree 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:25:30 +00:00
#include <Main/location.hxx>
// Has anyone done anything *really* stupid, like making min and max macros?
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
class FG3DModel
{
public:
FG3DModel ();
virtual ~FG3DModel ();
virtual void init (const string &path);
virtual void update (int dt);
virtual bool getVisible () const;
virtual void setVisible (bool visible);
virtual double getLongitudeDeg () const { return _lon_deg; }
virtual double getLatitudeDeg () const { return _lat_deg; }
virtual double getElevationFt () const { return _elev_ft; }
virtual void setLongitudeDeg (double lon_deg);
virtual void setLatitudeDeg (double lat_deg);
virtual void setElevationFt (double elev_ft);
virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
virtual double getRollDeg () const { return _roll_deg; }
virtual double getPitchDeg () const { return _pitch_deg; }
virtual double getHeadingDeg () const { return _heading_deg; }
virtual void setRollDeg (double roll_deg);
virtual void setPitchDeg (double pitch_deg);
virtual void setHeadingDeg (double heading_deg);
virtual void setOrientation (double roll_deg, double pitch_deg,
double heading_deg);
virtual ssgEntity * getSceneGraph () const { return _selector; }
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 you can expect that the data that viewmgr is writing to the property tree 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:25:30 +00:00
virtual FGLocation * getFGLocation () const { return _location; }
private:
class Animation;
Animation * make_animation (const char * object_name, SGPropertyNode * node);
// Geodetic position
double _lon_deg;
double _lat_deg;
double _elev_ft;
// Orientation
double _roll_deg;
double _pitch_deg;
double _heading_deg;
// Animations
vector <Animation *> _animations;
// Scene graph
ssgEntity * _model;
ssgSelector * _selector;
ssgTransform * _position;
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 you can expect that the data that viewmgr is writing to the property tree 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:25:30 +00:00
// Location
FGLocation * _location;
//////////////////////////////////////////////////////////////////////
// Internal classes for individual animations.
//////////////////////////////////////////////////////////////////////
/**
* Abstract base class for all animations.
*/
class Animation
{
public:
2002-03-26 03:14:20 +00:00
Animation ();
2002-03-26 03:14:20 +00:00
virtual ~Animation ();
/**
* Initialize the animation.
*
* @param object The object to animate.
* @param props The property node with configuration information.
*/
virtual void init (ssgEntity * object, SGPropertyNode * props) = 0;
/**
* Update the animation.
*
* @param dt The elapsed time in milliseconds since the last call.
*/
virtual void update (int dt) = 0;
};
/**
* A no-op animation.
*/
class NullAnimation : public Animation
{
public:
NullAnimation ();
virtual ~NullAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
private:
ssgBranch * _branch;
};
/**
* Animation to select alternative versions of the same object.
*/
class SelectAnimation : public Animation
{
public:
SelectAnimation ();
virtual ~SelectAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
private:
FGCondition * _condition;
ssgSelector * _selector;
};
/**
* Animation to spin an object around a center point.
*
* This animation rotates at a specific velocity.
*/
class SpinAnimation : public Animation
{
public:
SpinAnimation ();
virtual ~SpinAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
private:
SGPropertyNode * _prop;
double _factor;
double _position_deg;
sgMat4 _matrix;
sgVec3 _center;
sgVec3 _axis;
ssgTransform * _transform;
};
/**
* Animation to rotate an object around a center point.
*
* This animation rotates to a specific position.
*/
class RotateAnimation : public Animation
{
public:
RotateAnimation ();
virtual ~RotateAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
private:
SGPropertyNode * _prop;
double _offset_deg;
double _factor;
bool _has_min;
double _min_deg;
bool _has_max;
double _max_deg;
double _position_deg;
sgMat4 _matrix;
sgVec3 _center;
sgVec3 _axis;
ssgTransform * _transform;
};
/**
* Animation to slide along an axis.
*/
class TranslateAnimation : public Animation
{
public:
TranslateAnimation ();
virtual ~TranslateAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
private:
SGPropertyNode * _prop;
double _offset_m;
double _factor;
bool _has_min;
double _min_m;
bool _has_max;
double _max_m;
double _position_m;
sgMat4 _matrix;
sgVec3 _axis;
ssgTransform * _transform;
};
};
#endif // __MODEL_HXX
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 you can expect that the data that viewmgr is writing to the property tree 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:25:30 +00:00