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