]> git.mxchange.org Git - flightgear.git/blob - src/Model/model.hxx
Add support for interpolation tables for non-linear animations.
[flightgear.git] / src / Model / model.hxx
1 // model.hxx - manage a 3D aircraft model.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifndef __MODEL_HXX
7 #define __MODEL_HXX 1
8
9 #ifndef __cplusplus
10 # error This library requires C++
11 #endif
12
13 #include <vector>
14
15 SG_USING_STD(vector);
16
17 #include <plib/sg.h>
18
19
20 // Don't pull in the headers, since we don't need them here.
21 class ssgEntity;
22 class ssgRangeSelector;
23 class ssgSelector;
24 class ssgTransform;
25
26 class SGPropertyNode;
27 class SGInterpTable;
28 class FGCondition;
29 class FGLocation;
30
31
32 // Has anyone done anything *really* stupid, like making min and max macros?
33 #ifdef min
34 #undef min
35 #endif
36 #ifdef max
37 #undef max
38 #endif
39
40 class FG3DModel
41 {
42 public:
43
44   FG3DModel ();
45   virtual ~FG3DModel ();
46
47   virtual void init (const string &path);
48   virtual void update (int dt);
49
50   virtual bool getVisible () const;
51   virtual void setVisible (bool visible);
52
53   virtual double getLongitudeDeg () const { return _lon_deg; }
54   virtual double getLatitudeDeg () const { return _lat_deg; }
55   virtual double getElevationFt () const { return _elev_ft; }
56
57   virtual void setLongitudeDeg (double lon_deg);
58   virtual void setLatitudeDeg (double lat_deg);
59   virtual void setElevationFt (double elev_ft);
60   virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
61
62   virtual double getRollDeg () const { return _roll_deg; }
63   virtual double getPitchDeg () const { return _pitch_deg; }
64   virtual double getHeadingDeg () const { return _heading_deg; }
65
66   virtual void setRollDeg (double roll_deg);
67   virtual void setPitchDeg (double pitch_deg);
68   virtual void setHeadingDeg (double heading_deg);
69   virtual void setOrientation (double roll_deg, double pitch_deg,
70                                double heading_deg);
71
72   virtual ssgEntity * getSceneGraph () const { return (ssgEntity *)_selector; }
73
74   virtual FGLocation * getFGLocation () const { return _location; }
75
76 private:
77
78   class Animation;
79   Animation * make_animation (const char * object_name, SGPropertyNode * node);
80
81                                 // Geodetic position
82   double _lon_deg;
83   double _lat_deg;
84   double _elev_ft;
85
86                                 // Orientation
87   double _roll_deg;
88   double _pitch_deg;
89   double _heading_deg;
90
91                                 // Animations
92
93   vector <Animation *> _animations;
94
95
96                                 // Scene graph
97   ssgEntity * _model;
98   ssgSelector * _selector;
99   ssgTransform * _position;
100
101                                 // Location
102   FGLocation * _location;
103
104
105   \f
106   //////////////////////////////////////////////////////////////////////
107   // Internal classes for individual animations.
108   //////////////////////////////////////////////////////////////////////
109
110   /**
111    * Abstract base class for all animations.
112    */
113   class Animation
114   {
115   public:
116
117     Animation ();
118
119     virtual ~Animation ();
120
121     /**
122      * Initialize the animation.
123      *
124      * @param object The object to animate.
125      * @param props The property node with configuration information.
126      */
127     virtual void init (ssgEntity * object, SGPropertyNode * props) = 0;
128
129
130     /**
131      * Update the animation.
132      *
133      * @param dt The elapsed time in milliseconds since the last call.
134      */
135     virtual void update (int dt) = 0;
136
137   };
138
139
140   /**
141    * A no-op animation.
142    */
143   class NullAnimation : public Animation
144   {
145   public:
146     NullAnimation ();
147     virtual ~NullAnimation ();
148     virtual void init (ssgEntity * object, SGPropertyNode * props);
149     virtual void update (int dt);
150   private:
151     ssgBranch * _branch;
152   };
153
154   
155   /**
156    * A range, or level-of-detail (LOD) animation.
157    */
158   class RangeAnimation : public Animation
159   {
160   public:
161     RangeAnimation ();
162     virtual ~RangeAnimation ();
163     virtual void init (ssgEntity * object, SGPropertyNode * props);
164     virtual void update (int dt);
165   private:
166     ssgRangeSelector * _branch;
167   };
168
169
170   /**
171    * Animation to select alternative versions of the same object.
172    */
173   class SelectAnimation : public Animation
174   {
175   public:
176     SelectAnimation ();
177     virtual ~SelectAnimation ();
178     virtual void init (ssgEntity * object, SGPropertyNode * props);
179     virtual void update (int dt);
180   private:
181     FGCondition * _condition;
182     ssgSelector * _selector;
183   };
184
185
186   /**
187    * Animation to spin an object around a center point.
188    *
189    * This animation rotates at a specific velocity.
190    */
191   class SpinAnimation : public Animation
192   {
193   public:
194     SpinAnimation ();
195     virtual ~SpinAnimation ();
196     virtual void init (ssgEntity * object, SGPropertyNode * props);
197     virtual void update (int dt);
198   private:
199     SGPropertyNode * _prop;
200     double _factor;
201     double _position_deg;
202     sgMat4 _matrix;
203     sgVec3 _center;
204     sgVec3 _axis;
205     ssgTransform * _transform;
206   };
207
208
209   /**
210    * Animation to rotate an object around a center point.
211    *
212    * This animation rotates to a specific position.
213    */
214   class RotateAnimation : public Animation
215   {
216   public:
217     RotateAnimation ();
218     virtual ~RotateAnimation ();
219     virtual void init (ssgEntity * object, SGPropertyNode * props);
220     virtual void update (int dt);
221   private:
222     SGPropertyNode * _prop;
223     double _offset_deg;
224     double _factor;
225     SGInterpTable * _table;
226     bool _has_min;
227     double _min_deg;
228     bool _has_max;
229     double _max_deg;
230     double _position_deg;
231     sgMat4 _matrix;
232     sgVec3 _center;
233     sgVec3 _axis;
234     ssgTransform * _transform;
235   };
236
237
238   /**
239    * Animation to slide along an axis.
240    */
241   class TranslateAnimation : public Animation
242   {
243   public:
244     TranslateAnimation ();
245     virtual ~TranslateAnimation ();
246     virtual void init (ssgEntity * object, SGPropertyNode * props);
247     virtual void update (int dt);
248   private:
249     SGPropertyNode * _prop;
250     double _offset_m;
251     double _factor;
252     SGInterpTable * _table;
253     bool _has_min;
254     double _min_m;
255     bool _has_max;
256     double _max_m;
257     double _position_m;
258     sgMat4 _matrix;
259     sgVec3 _axis;
260     ssgTransform * _transform;
261   };
262
263 };
264
265 #endif // __MODEL_HXX
266
267
268