2002-02-23 21:20:00 +00:00
|
|
|
|
// 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
|
|
|
|
|
|
2002-02-26 00:10:06 +00:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
SG_USING_STD(vector);
|
|
|
|
|
|
2002-04-20 14:07:34 +00:00
|
|
|
|
#include <plib/sg.h>
|
2002-08-07 01:34:49 +00:00
|
|
|
|
#include <plib/ssg.h>
|
2002-04-20 14:07:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Don't pull in the headers, since we don't need them here.
|
2002-04-20 17:07:47 +00:00
|
|
|
|
class ssgBranch;
|
2002-05-03 21:09:14 +00:00
|
|
|
|
class ssgCutout;
|
2002-04-20 14:07:34 +00:00
|
|
|
|
class ssgEntity;
|
|
|
|
|
class ssgRangeSelector;
|
|
|
|
|
class ssgSelector;
|
|
|
|
|
class ssgTransform;
|
|
|
|
|
|
|
|
|
|
class SGPropertyNode;
|
|
|
|
|
class SGInterpTable;
|
|
|
|
|
class FGCondition;
|
|
|
|
|
class FGLocation;
|
|
|
|
|
|
2002-02-23 21:20:00 +00:00
|
|
|
|
|
2002-03-27 13:00:25 +00:00
|
|
|
|
// Has anyone done anything *really* stupid, like making min and max macros?
|
|
|
|
|
#ifdef min
|
|
|
|
|
#undef min
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef max
|
|
|
|
|
#undef max
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-06-10 13:20:26 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Load a 3D model with or without XML wrapper.
|
|
|
|
|
*
|
|
|
|
|
* If the path ends in ".xml", then it will be used as a property-
|
|
|
|
|
* list wrapper to add animations to the model.
|
|
|
|
|
*
|
|
|
|
|
* Subsystems should not normally invoke this function directly;
|
|
|
|
|
* instead, they should use the FGModelLoader declared in loader.hxx.
|
|
|
|
|
*/
|
|
|
|
|
ssgBranch * fgLoad3DModel (const string &path);
|
2002-02-23 21:20:00 +00:00
|
|
|
|
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Animation classes
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2002-04-05 03:19:34 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Abstract base class for all animations.
|
|
|
|
|
*/
|
|
|
|
|
class Animation : public ssgBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
Animation (SGPropertyNode_ptr props, ssgBranch * branch);
|
2002-04-20 14:07:34 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
virtual ~Animation ();
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2002-08-07 01:34:49 +00:00
|
|
|
|
* Get the SSG branch holding the animation.
|
2002-03-30 21:24:19 +00:00
|
|
|
|
*/
|
2002-08-07 01:34:49 +00:00
|
|
|
|
virtual ssgBranch * getBranch () { return _branch; }
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Update the animation.
|
|
|
|
|
*/
|
|
|
|
|
virtual void update () = 0;
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
protected:
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
ssgBranch * _branch;
|
2002-02-26 00:10:06 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
};
|
2002-02-26 00:10:06 +00:00
|
|
|
|
|
2002-04-01 14:00:08 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* A no-op animation.
|
|
|
|
|
*/
|
|
|
|
|
class NullAnimation : public Animation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
NullAnimation (SGPropertyNode_ptr props);
|
|
|
|
|
virtual ~NullAnimation ();
|
|
|
|
|
virtual void update ();
|
|
|
|
|
};
|
2002-04-13 12:10:20 +00:00
|
|
|
|
|
2002-04-01 14:00:08 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* A range, or level-of-detail (LOD) animation.
|
|
|
|
|
*/
|
|
|
|
|
class RangeAnimation : public Animation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
RangeAnimation (SGPropertyNode_ptr props);
|
|
|
|
|
virtual ~RangeAnimation ();
|
|
|
|
|
virtual void update ();
|
|
|
|
|
};
|
2002-05-03 21:09:14 +00:00
|
|
|
|
|
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Animation to turn and face the screen.
|
|
|
|
|
*/
|
|
|
|
|
class BillboardAnimation : public Animation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
BillboardAnimation (SGPropertyNode_ptr props);
|
|
|
|
|
virtual ~BillboardAnimation ();
|
|
|
|
|
virtual void update ();
|
|
|
|
|
};
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
2002-02-23 21:20:00 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Animation to select alternative versions of the same object.
|
|
|
|
|
*/
|
|
|
|
|
class SelectAnimation : public Animation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SelectAnimation (SGPropertyNode_ptr props);
|
|
|
|
|
virtual ~SelectAnimation ();
|
|
|
|
|
virtual void update ();
|
|
|
|
|
private:
|
|
|
|
|
FGCondition * _condition;
|
|
|
|
|
};
|
2002-02-23 21:20:00 +00:00
|
|
|
|
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Animation to spin an object around a center point.
|
|
|
|
|
*
|
|
|
|
|
* This animation rotates at a specific velocity.
|
|
|
|
|
*/
|
|
|
|
|
class SpinAnimation : public Animation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SpinAnimation (SGPropertyNode_ptr props);
|
|
|
|
|
virtual ~SpinAnimation ();
|
|
|
|
|
virtual void update ();
|
|
|
|
|
private:
|
|
|
|
|
SGPropertyNode * _prop;
|
|
|
|
|
double _factor;
|
|
|
|
|
double _position_deg;
|
|
|
|
|
double _last_time_sec;
|
|
|
|
|
sgMat4 _matrix;
|
|
|
|
|
sgVec3 _center;
|
|
|
|
|
sgVec3 _axis;
|
|
|
|
|
};
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Animation to rotate an object around a center point.
|
|
|
|
|
*
|
|
|
|
|
* This animation rotates to a specific position.
|
|
|
|
|
*/
|
|
|
|
|
class RotateAnimation : public Animation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
RotateAnimation (SGPropertyNode_ptr props);
|
|
|
|
|
virtual ~RotateAnimation ();
|
|
|
|
|
virtual void update ();
|
|
|
|
|
private:
|
|
|
|
|
SGPropertyNode * _prop;
|
|
|
|
|
double _offset_deg;
|
|
|
|
|
double _factor;
|
|
|
|
|
SGInterpTable * _table;
|
|
|
|
|
bool _has_min;
|
|
|
|
|
double _min_deg;
|
|
|
|
|
bool _has_max;
|
|
|
|
|
double _max_deg;
|
|
|
|
|
double _position_deg;
|
|
|
|
|
sgMat4 _matrix;
|
|
|
|
|
sgVec3 _center;
|
|
|
|
|
sgVec3 _axis;
|
|
|
|
|
};
|
2002-02-23 21:20:00 +00:00
|
|
|
|
|
2002-05-03 21:09:14 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Animation to slide along an axis.
|
|
|
|
|
*/
|
|
|
|
|
class TranslateAnimation : public Animation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TranslateAnimation (SGPropertyNode_ptr props);
|
|
|
|
|
virtual ~TranslateAnimation ();
|
|
|
|
|
virtual void update ();
|
|
|
|
|
private:
|
|
|
|
|
SGPropertyNode * _prop;
|
|
|
|
|
double _offset_m;
|
|
|
|
|
double _factor;
|
|
|
|
|
SGInterpTable * _table;
|
|
|
|
|
bool _has_min;
|
|
|
|
|
double _min_m;
|
|
|
|
|
bool _has_max;
|
|
|
|
|
double _max_m;
|
|
|
|
|
double _position_m;
|
|
|
|
|
sgMat4 _matrix;
|
|
|
|
|
sgVec3 _axis;
|
2002-02-23 21:20:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-06-10 13:20:26 +00:00
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Model placement.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A wrapper for a model with a definite placement.
|
|
|
|
|
*/
|
2002-06-10 13:20:26 +00:00
|
|
|
|
class FGModelPlacement
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
FGModelPlacement ();
|
|
|
|
|
virtual ~FGModelPlacement ();
|
|
|
|
|
|
|
|
|
|
virtual void init (const string &path);
|
2002-08-07 01:34:49 +00:00
|
|
|
|
virtual void update ();
|
2002-06-10 13:20:26 +00:00
|
|
|
|
|
|
|
|
|
virtual ssgEntity * getSceneGraph () { return (ssgEntity *)_selector; }
|
|
|
|
|
|
|
|
|
|
virtual FGLocation * getFGLocation () { return _location; }
|
|
|
|
|
|
|
|
|
|
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,
|
2002-08-07 01:34:49 +00:00
|
|
|
|
double heading_deg);
|
2002-06-10 13:20:26 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
// Geodetic position
|
2002-06-10 13:20:26 +00:00
|
|
|
|
double _lon_deg;
|
|
|
|
|
double _lat_deg;
|
|
|
|
|
double _elev_ft;
|
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
// Orientation
|
2002-06-10 13:20:26 +00:00
|
|
|
|
double _roll_deg;
|
|
|
|
|
double _pitch_deg;
|
|
|
|
|
double _heading_deg;
|
|
|
|
|
|
|
|
|
|
ssgSelector * _selector;
|
|
|
|
|
ssgTransform * _position;
|
|
|
|
|
|
2002-08-07 01:34:49 +00:00
|
|
|
|
// Location
|
2002-06-10 13:20:26 +00:00
|
|
|
|
FGLocation * _location;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2002-02-23 21:20:00 +00:00
|
|
|
|
#endif // __MODEL_HXX
|
|
|
|
|
|
2002-04-11 04:25:30 +00:00
|
|
|
|
|
|
|
|
|
|