]> git.mxchange.org Git - flightgear.git/blob - src/Model/model.hxx
Added a new 'billboard' animation type. This animation takes one
[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 ssgBranch;
22 class ssgCutout;
23 class ssgEntity;
24 class ssgRangeSelector;
25 class ssgSelector;
26 class ssgTransform;
27
28 class SGPropertyNode;
29 class SGInterpTable;
30 class FGCondition;
31 class FGLocation;
32
33
34 // Has anyone done anything *really* stupid, like making min and max macros?
35 #ifdef min
36 #undef min
37 #endif
38 #ifdef max
39 #undef max
40 #endif
41
42 class FG3DModel
43 {
44 public:
45
46   FG3DModel ();
47   virtual ~FG3DModel ();
48
49   virtual void init (const string &path);
50   virtual void update (int dt);
51
52   virtual bool getVisible () const;
53   virtual void setVisible (bool visible);
54
55   virtual double getLongitudeDeg () const { return _lon_deg; }
56   virtual double getLatitudeDeg () const { return _lat_deg; }
57   virtual double getElevationFt () const { return _elev_ft; }
58
59   virtual void setLongitudeDeg (double lon_deg);
60   virtual void setLatitudeDeg (double lat_deg);
61   virtual void setElevationFt (double elev_ft);
62   virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
63
64   virtual double getRollDeg () const { return _roll_deg; }
65   virtual double getPitchDeg () const { return _pitch_deg; }
66   virtual double getHeadingDeg () const { return _heading_deg; }
67
68   virtual void setRollDeg (double roll_deg);
69   virtual void setPitchDeg (double pitch_deg);
70   virtual void setHeadingDeg (double heading_deg);
71   virtual void setOrientation (double roll_deg, double pitch_deg,
72                                double heading_deg);
73
74   virtual ssgEntity * getSceneGraph () const { return (ssgEntity *)_selector; }
75
76   virtual FGLocation * getFGLocation () const { return _location; }
77
78 private:
79
80   class Animation;
81   Animation * make_animation (const char * object_name, SGPropertyNode * node);
82
83                                 // Geodetic position
84   double _lon_deg;
85   double _lat_deg;
86   double _elev_ft;
87
88                                 // Orientation
89   double _roll_deg;
90   double _pitch_deg;
91   double _heading_deg;
92
93                                 // Animations
94   vector <Animation *> _animations;
95
96                                 // Scene graph
97   ssgBranch * _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 turn and face the screen.
172    */
173   class BillboardAnimation : public Animation
174   {
175   public:
176     BillboardAnimation ();
177     virtual ~BillboardAnimation ();
178     virtual void init (ssgEntity * object, SGPropertyNode * props);
179     virtual void update (int dt);
180   private:
181     ssgCutout * _branch;
182   };
183
184
185   /**
186    * Animation to select alternative versions of the same object.
187    */
188   class SelectAnimation : public Animation
189   {
190   public:
191     SelectAnimation ();
192     virtual ~SelectAnimation ();
193     virtual void init (ssgEntity * object, SGPropertyNode * props);
194     virtual void update (int dt);
195   private:
196     FGCondition * _condition;
197     ssgSelector * _selector;
198   };
199
200
201   /**
202    * Animation to spin an object around a center point.
203    *
204    * This animation rotates at a specific velocity.
205    */
206   class SpinAnimation : public Animation
207   {
208   public:
209     SpinAnimation ();
210     virtual ~SpinAnimation ();
211     virtual void init (ssgEntity * object, SGPropertyNode * props);
212     virtual void update (int dt);
213   private:
214     SGPropertyNode * _prop;
215     double _factor;
216     double _position_deg;
217     sgMat4 _matrix;
218     sgVec3 _center;
219     sgVec3 _axis;
220     ssgTransform * _transform;
221   };
222
223
224   /**
225    * Animation to rotate an object around a center point.
226    *
227    * This animation rotates to a specific position.
228    */
229   class RotateAnimation : public Animation
230   {
231   public:
232     RotateAnimation ();
233     virtual ~RotateAnimation ();
234     virtual void init (ssgEntity * object, SGPropertyNode * props);
235     virtual void update (int dt);
236   private:
237     SGPropertyNode * _prop;
238     double _offset_deg;
239     double _factor;
240     SGInterpTable * _table;
241     bool _has_min;
242     double _min_deg;
243     bool _has_max;
244     double _max_deg;
245     double _position_deg;
246     sgMat4 _matrix;
247     sgVec3 _center;
248     sgVec3 _axis;
249     ssgTransform * _transform;
250   };
251
252
253   /**
254    * Animation to slide along an axis.
255    */
256   class TranslateAnimation : public Animation
257   {
258   public:
259     TranslateAnimation ();
260     virtual ~TranslateAnimation ();
261     virtual void init (ssgEntity * object, SGPropertyNode * props);
262     virtual void update (int dt);
263   private:
264     SGPropertyNode * _prop;
265     double _offset_m;
266     double _factor;
267     SGInterpTable * _table;
268     bool _has_min;
269     double _min_m;
270     bool _has_max;
271     double _max_m;
272     double _position_m;
273     sgMat4 _matrix;
274     sgVec3 _axis;
275     ssgTransform * _transform;
276   };
277
278
279 };
280
281 #endif // __MODEL_HXX
282
283
284