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>
|
2002-04-11 04:25:30 +00:00
|
|
|
|
#include <plib/ssg.h>
|
2002-02-26 00:10:06 +00:00
|
|
|
|
|
|
|
|
|
SG_USING_STD(vector);
|
|
|
|
|
|
2002-04-05 03:19:34 +00:00
|
|
|
|
#include <Main/fg_props.hxx>
|
2002-04-11 04:25:30 +00:00
|
|
|
|
#include <Main/location.hxx>
|
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-04-05 03:19:34 +00:00
|
|
|
|
class FG3DModel
|
2002-02-23 21:20:00 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2002-04-05 03:19:34 +00:00
|
|
|
|
FG3DModel ();
|
|
|
|
|
virtual ~FG3DModel ();
|
2002-02-23 21:20:00 +00:00
|
|
|
|
|
2002-04-05 03:19:34 +00:00
|
|
|
|
virtual void init (const string &path);
|
2002-02-23 21:20:00 +00:00
|
|
|
|
virtual void update (int dt);
|
|
|
|
|
|
2002-04-05 03:19:34 +00:00
|
|
|
|
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; }
|
|
|
|
|
|
2002-04-12 12:45:49 +00:00
|
|
|
|
virtual void setLongitudeDeg (double lon_deg);
|
|
|
|
|
virtual void setLatitudeDeg (double lat_deg);
|
|
|
|
|
virtual void setElevationFt (double elev_ft);
|
2002-04-05 03:19:34 +00:00
|
|
|
|
virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
|
|
|
|
|
|
2002-04-12 12:45:49 +00:00
|
|
|
|
virtual double getRollDeg () const { return _roll_deg; }
|
|
|
|
|
virtual double getPitchDeg () const { return _pitch_deg; }
|
|
|
|
|
virtual double getHeadingDeg () const { return _heading_deg; }
|
2002-04-05 03:19:34 +00:00
|
|
|
|
|
2002-04-12 12:45:49 +00:00
|
|
|
|
virtual void setRollDeg (double roll_deg);
|
|
|
|
|
virtual void setPitchDeg (double pitch_deg);
|
|
|
|
|
virtual void setHeadingDeg (double heading_deg);
|
2002-04-05 03:19:34 +00:00
|
|
|
|
virtual void setOrientation (double roll_deg, double pitch_deg,
|
|
|
|
|
double heading_deg);
|
|
|
|
|
|
|
|
|
|
virtual ssgEntity * getSceneGraph () const { return _selector; }
|
|
|
|
|
|
2002-04-11 04:25:30 +00:00
|
|
|
|
virtual FGLocation * getFGLocation () const { return _location; }
|
|
|
|
|
|
2002-02-23 21:20:00 +00:00
|
|
|
|
private:
|
|
|
|
|
|
2002-03-30 21:24:19 +00:00
|
|
|
|
class Animation;
|
|
|
|
|
Animation * make_animation (const char * object_name, SGPropertyNode * node);
|
|
|
|
|
|
2002-04-05 03:19:34 +00:00
|
|
|
|
// 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
|
2002-03-30 21:24:19 +00:00
|
|
|
|
ssgEntity * _model;
|
|
|
|
|
ssgSelector * _selector;
|
|
|
|
|
ssgTransform * _position;
|
|
|
|
|
|
2002-04-11 04:25:30 +00:00
|
|
|
|
// Location
|
|
|
|
|
FGLocation * _location;
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Internal classes for individual animations.
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Abstract base class for all animations.
|
|
|
|
|
*/
|
|
|
|
|
class Animation
|
2002-02-26 00:10:06 +00:00
|
|
|
|
{
|
2002-03-30 21:24:19 +00:00
|
|
|
|
public:
|
|
|
|
|
|
2002-03-26 03:14:20 +00:00
|
|
|
|
Animation ();
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
2002-03-26 03:14:20 +00:00
|
|
|
|
virtual ~Animation ();
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
2002-02-26 00:10:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2002-03-30 21:24:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* A no-op animation.
|
|
|
|
|
*/
|
|
|
|
|
class NullAnimation : public Animation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
NullAnimation ();
|
|
|
|
|
virtual ~NullAnimation ();
|
|
|
|
|
virtual void init (ssgEntity * object, SGPropertyNode * props);
|
|
|
|
|
virtual void update (int dt);
|
2002-04-01 14:00:08 +00:00
|
|
|
|
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;
|
2002-03-30 21:24:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-02-23 21:20:00 +00:00
|
|
|
|
|
2002-03-30 21:24:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
};
|
2002-02-23 21:20:00 +00:00
|
|
|
|
|
2002-03-30 21:24:19 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
};
|
2002-02-23 21:20:00 +00:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // __MODEL_HXX
|
|
|
|
|
|
2002-04-11 04:25:30 +00:00
|
|
|
|
|
|
|
|
|
|