]> git.mxchange.org Git - flightgear.git/blob - src/Model/model.hxx
Timed animations now working again.
[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 #include <plib/ssg.h>
19
20 #include <simgear/math/point3d.hxx>
21 #include <simgear/props/props.hxx>
22
23
24 // Don't pull in the headers, since we don't need them here.
25 class ssgBranch;
26 class ssgCutout;
27 class ssgEntity;
28 class ssgRangeSelector;
29 class ssgSelector;
30 class ssgTransform;
31
32 class SGInterpTable;
33 class FGCondition;
34 class FGLocation;
35
36
37 // Has anyone done anything *really* stupid, like making min and max macros?
38 #ifdef min
39 #undef min
40 #endif
41 #ifdef max
42 #undef max
43 #endif
44
45
46 /**
47  * Load a 3D model with or without XML wrapper.
48  *
49  * If the path ends in ".xml", then it will be used as a property-
50  * list wrapper to add animations to the model.
51  *
52  * Subsystems should not normally invoke this function directly;
53  * instead, they should use the FGModelLoader declared in loader.hxx.
54  */
55 ssgBranch * fgLoad3DModel( const string& fg_root, const string &path,
56                            SGPropertyNode *prop_root, double sim_time_sec );
57
58
59 \f
60 //////////////////////////////////////////////////////////////////////
61 // Animation classes
62 //////////////////////////////////////////////////////////////////////
63
64 /**
65  * Abstract base class for all animations.
66  */
67 class Animation :  public ssgBase
68 {
69 public:
70
71   Animation (SGPropertyNode_ptr props, ssgBranch * branch);
72
73   virtual ~Animation ();
74
75   /**
76    * Get the SSG branch holding the animation.
77    */
78   virtual ssgBranch * getBranch () { return _branch; }
79
80   /**
81    * Initialize the animation, after children have been added.
82    */
83   virtual void init ();
84
85   /**
86    * Update the animation.
87    */
88   virtual void update();
89
90   /**
91    * Set the value of sim_time_sec.  This needs to be called every
92    * frame in order for the time based animations to work correctly.
93    */
94   static void set_sim_time_sec( double val ) { sim_time_sec = val; }
95
96 protected:
97
98   static double sim_time_sec;
99
100   ssgBranch * _branch;
101
102 };
103
104
105 /**
106  * A no-op animation.
107  */
108 class NullAnimation : public Animation
109 {
110 public:
111   NullAnimation (SGPropertyNode_ptr props);
112   virtual ~NullAnimation ();
113 };
114
115
116 /**
117  * A range, or level-of-detail (LOD) animation.
118  */
119 class RangeAnimation : public Animation
120 {
121 public:
122   RangeAnimation (SGPropertyNode_ptr props);
123   virtual ~RangeAnimation ();
124 };
125
126
127 /**
128  * Animation to turn and face the screen.
129  */
130 class BillboardAnimation : public Animation
131 {
132 public:
133   BillboardAnimation (SGPropertyNode_ptr props);
134   virtual ~BillboardAnimation ();
135 };
136
137
138 /**
139  * Animation to select alternative versions of the same object.
140  */
141 class SelectAnimation : public Animation
142 {
143 public:
144   SelectAnimation( SGPropertyNode *prop_root,
145                    SGPropertyNode_ptr props );
146   virtual ~SelectAnimation ();
147   virtual void update();
148 private:
149   FGCondition * _condition;
150 };
151
152
153 /**
154  * Animation to spin an object around a center point.
155  *
156  * This animation rotates at a specific velocity.
157  */
158 class SpinAnimation : public Animation
159 {
160 public:
161   SpinAnimation( SGPropertyNode *prop_root,
162                  SGPropertyNode_ptr props,
163                  double sim_time_sec );
164   virtual ~SpinAnimation ();
165   virtual void update();
166 private:
167   SGPropertyNode_ptr _prop;
168   double _factor;
169   double _position_deg;
170   double _last_time_sec;
171   sgMat4 _matrix;
172   sgVec3 _center;
173   sgVec3 _axis;
174 };
175
176
177 /**
178  * Animation to draw objects for a specific amount of time each.
179  */
180 class TimedAnimation : public Animation
181 {
182 public:
183     TimedAnimation (SGPropertyNode_ptr props);
184     virtual ~TimedAnimation ();
185     virtual void update();
186 private:
187     double _duration_sec;
188     double _last_time_sec;
189     int _step;
190 };
191
192
193 /**
194  * Animation to rotate an object around a center point.
195  *
196  * This animation rotates to a specific position.
197  */
198 class RotateAnimation : public Animation
199 {
200 public:
201   RotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
202   virtual ~RotateAnimation ();
203   virtual void update();
204 private:
205   SGPropertyNode_ptr _prop;
206   double _offset_deg;
207   double _factor;
208   SGInterpTable * _table;
209   bool _has_min;
210   double _min_deg;
211   bool _has_max;
212   double _max_deg;
213   double _position_deg;
214   sgMat4 _matrix;
215   sgVec3 _center;
216   sgVec3 _axis;
217 };
218
219
220 /**
221  * Animation to slide along an axis.
222  */
223 class TranslateAnimation : public Animation
224 {
225 public:
226   TranslateAnimation( SGPropertyNode *prop_root,
227                       SGPropertyNode_ptr props );
228   virtual ~TranslateAnimation ();
229   virtual void update();
230 private:
231   SGPropertyNode_ptr _prop;
232   double _offset_m;
233   double _factor;
234   SGInterpTable * _table;
235   bool _has_min;
236   double _min_m;
237   bool _has_max;
238   double _max_m;
239   double _position_m;
240   sgMat4 _matrix;
241   sgVec3 _axis;
242 };
243
244
245
246 ////////////////////////////////////////////////////////////////////////
247 // Model placement.
248 ////////////////////////////////////////////////////////////////////////
249
250 /**
251  * A wrapper for a model with a definite placement.
252  */
253 class FGModelPlacement
254 {
255 public:
256
257   FGModelPlacement ();
258   virtual ~FGModelPlacement ();
259
260   virtual void init( const string &fg_root,
261                      const string &path,
262                      SGPropertyNode *prop_root,
263                      double sim_time_sec );
264   virtual void update( const Point3D scenery_center );
265
266   virtual ssgEntity * getSceneGraph () { return (ssgEntity *)_selector; }
267
268   virtual FGLocation * getFGLocation () { return _location; }
269
270   virtual bool getVisible () const;
271   virtual void setVisible (bool visible);
272
273   virtual double getLongitudeDeg () const { return _lon_deg; }
274   virtual double getLatitudeDeg () const { return _lat_deg; }
275   virtual double getElevationFt () const { return _elev_ft; }
276
277   virtual void setLongitudeDeg (double lon_deg);
278   virtual void setLatitudeDeg (double lat_deg);
279   virtual void setElevationFt (double elev_ft);
280   virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
281
282   virtual double getRollDeg () const { return _roll_deg; }
283   virtual double getPitchDeg () const { return _pitch_deg; }
284   virtual double getHeadingDeg () const { return _heading_deg; }
285
286   virtual void setRollDeg (double roll_deg);
287   virtual void setPitchDeg (double pitch_deg);
288   virtual void setHeadingDeg (double heading_deg);
289   virtual void setOrientation (double roll_deg, double pitch_deg,
290                                double heading_deg);
291   
292   // Addition by Diarmuid Tyson for Multiplayer Support
293   // Allows multiplayer to get players position transform
294   virtual const sgVec4 *get_POS() { return POS; }
295
296 private:
297
298                                 // Geodetic position
299   double _lon_deg;
300   double _lat_deg;
301   double _elev_ft;
302
303                                 // Orientation
304   double _roll_deg;
305   double _pitch_deg;
306   double _heading_deg;
307
308   ssgSelector * _selector;
309   ssgTransform * _position;
310
311                                 // Location
312   FGLocation * _location;
313
314
315   // Addition by Diarmuid Tyson for Multiplayer Support
316   // Moved from update method
317   // POS for transformation Matrix
318   sgMat4 POS;
319
320 };
321
322 #endif // __MODEL_HXX