]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation.hxx
Add the ability to set three levels of detail for static scenery using the property...
[simgear.git] / simgear / scene / model / animation.hxx
1
2 // animation.hxx - classes to manage model animation.
3 // Written by David Megginson, started 2002.
4 //
5 // This file is in the Public Domain, and comes with no warranty.
6
7 #ifndef _SG_ANIMATION_HXX
8 #define _SG_ANIMATION_HXX 1
9
10 #ifndef __cplusplus
11 # error This library requires C++
12 #endif
13
14 #include <vector>
15
16 SG_USING_STD(vector);
17
18 #include <plib/sg.h>
19 #include <plib/ssg.h>
20
21 #include <simgear/math/point3d.hxx>
22 #include <simgear/props/props.hxx>
23
24
25 // Don't pull in the headers, since we don't need them here.
26 class SGInterpTable;
27 class SGCondition;
28
29
30 // Has anyone done anything *really* stupid, like making min and max macros?
31 #ifdef min
32 #undef min
33 #endif
34 #ifdef max
35 #undef max
36 #endif
37
38
39 \f
40 //////////////////////////////////////////////////////////////////////
41 // Animation classes
42 //////////////////////////////////////////////////////////////////////
43
44 /**
45  * Abstract base class for all animations.
46  */
47 class SGAnimation :  public ssgBase
48 {
49 public:
50
51   SGAnimation (SGPropertyNode_ptr props, ssgBranch * branch);
52
53   virtual ~SGAnimation ();
54
55   /**
56    * Get the SSG branch holding the animation.
57    */
58   virtual ssgBranch * getBranch () { return _branch; }
59
60   /**
61    * Initialize the animation, after children have been added.
62    */
63   virtual void init ();
64
65   /**
66    * Update the animation.
67    */
68   virtual void update();
69
70   /**
71    * Set the value of sim_time_sec.  This needs to be called every
72    * frame in order for the time based animations to work correctly.
73    */
74   static void set_sim_time_sec( double val ) { sim_time_sec = val; }
75
76 protected:
77
78   static double sim_time_sec;
79
80   ssgBranch * _branch;
81
82 };
83
84
85 /**
86  * A no-op animation.
87  */
88 class SGNullAnimation : public SGAnimation
89 {
90 public:
91   SGNullAnimation (SGPropertyNode_ptr props);
92   virtual ~SGNullAnimation ();
93 };
94
95
96 /**
97  * A range, or level-of-detail (LOD) animation.
98  */
99 class SGRangeAnimation : public SGAnimation
100 {
101 public:
102   SGRangeAnimation (SGPropertyNode *prop_root,
103                     SGPropertyNode_ptr props);
104   virtual ~SGRangeAnimation ();
105   virtual void update();
106 private:
107   SGPropertyNode_ptr _min_prop;
108   SGPropertyNode_ptr _max_prop;
109   float _min;
110   float _max;
111 };
112
113
114 /**
115  * Animation to turn and face the screen.
116  */
117 class SGBillboardAnimation : public SGAnimation
118 {
119 public:
120   SGBillboardAnimation (SGPropertyNode_ptr props);
121   virtual ~SGBillboardAnimation ();
122 };
123
124
125 /**
126  * Animation to select alternative versions of the same object.
127  */
128 class SGSelectAnimation : public SGAnimation
129 {
130 public:
131   SGSelectAnimation( SGPropertyNode *prop_root,
132                    SGPropertyNode_ptr props );
133   virtual ~SGSelectAnimation ();
134   virtual void update();
135 private:
136   SGCondition * _condition;
137 };
138
139
140 /**
141  * Animation to spin an object around a center point.
142  *
143  * This animation rotates at a specific velocity.
144  */
145 class SGSpinAnimation : public SGAnimation
146 {
147 public:
148   SGSpinAnimation( SGPropertyNode *prop_root,
149                  SGPropertyNode_ptr props,
150                  double sim_time_sec );
151   virtual ~SGSpinAnimation ();
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 SGTimedAnimation : public SGAnimation
168 {
169 public:
170     SGTimedAnimation (SGPropertyNode_ptr props);
171     virtual ~SGTimedAnimation ();
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 SGRotateAnimation : public SGAnimation
186 {
187 public:
188   SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
189   virtual ~SGRotateAnimation ();
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 SGTranslateAnimation : public SGAnimation
211 {
212 public:
213   SGTranslateAnimation( SGPropertyNode *prop_root,
214                       SGPropertyNode_ptr props );
215   virtual ~SGTranslateAnimation ();
216   virtual void update();
217 private:
218   SGPropertyNode_ptr _prop;
219   double _offset_m;
220   double _factor;
221   SGInterpTable * _table;
222   bool _has_min;
223   double _min_m;
224   bool _has_max;
225   double _max_m;
226   double _position_m;
227   sgMat4 _matrix;
228   sgVec3 _axis;
229 };
230
231 /**
232  * Animation to blend an object.
233  */
234 class SGBlendAnimation : public SGAnimation
235 {
236 public:
237   SGBlendAnimation( SGPropertyNode *prop_root,
238                       SGPropertyNode_ptr props );
239   virtual ~SGBlendAnimation ();
240   virtual void update();
241 private:
242   SGPropertyNode_ptr _prop;
243   SGInterpTable * _table;
244   double _prev_value;
245   double _offset;
246   double _factor;
247   bool _has_min;
248   double _min;
249   bool _has_max;
250   double _max;
251 };
252
253 /**
254  * Animation to scale an object.
255  */
256 class SGScaleAnimation : public SGAnimation
257 {
258 public:
259   SGScaleAnimation( SGPropertyNode *prop_root,
260                         SGPropertyNode_ptr props );
261   virtual ~SGScaleAnimation ();
262   virtual void update();
263 private:
264   SGPropertyNode_ptr _prop;
265   double _x_factor;
266   double _y_factor;
267   double _z_factor;
268   double _x_offset;
269   double _y_offset;
270   double _z_offset;
271   SGInterpTable * _table;
272   bool _has_min_x;
273   bool _has_min_y;
274   bool _has_min_z;
275   double _min_x;
276   double _min_y;
277   double _min_z;
278   bool _has_max_x;
279   bool _has_max_y;
280   bool _has_max_z;
281   double _max_x;
282   double _max_y;
283   double _max_z;
284   double _x_scale;
285   double _y_scale;
286   double _z_scale;
287   sgMat4 _matrix;
288 };
289
290 /**
291  * Animation to rotate texture mappings around a center point.
292  *
293  * This animation rotates to a specific position.
294  */
295 class SGTexRotateAnimation : public SGAnimation
296 {
297 public:
298   SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
299   virtual ~SGTexRotateAnimation ();
300   virtual void update();
301 private:
302   SGPropertyNode_ptr _prop;
303   double _offset_deg;
304   double _factor;
305   SGInterpTable * _table;
306   bool _has_min;
307   double _min_deg;
308   bool _has_max;
309   double _max_deg;
310   double _position_deg;
311   sgMat4 _matrix;
312   sgVec3 _center;
313   sgVec3 _axis;
314 };
315
316
317 /**
318  * Animation to slide texture mappings along an axis.
319  */
320 class SGTexTranslateAnimation : public SGAnimation
321 {
322 public:
323   SGTexTranslateAnimation( SGPropertyNode *prop_root,
324                       SGPropertyNode_ptr props );
325   virtual ~SGTexTranslateAnimation ();
326   virtual void update();
327 private:
328   SGPropertyNode_ptr _prop;
329   double _offset;
330   double _factor;
331   double _step;
332   double _scroll;
333   SGInterpTable * _table;
334   bool _has_min;
335   double _min;
336   bool _has_max;
337   double _max;
338   double _position;
339   sgMat4 _matrix;
340   sgVec3 _axis;
341 };
342
343
344
345 /**
346  * Classes for handling multiple types of Texture translations on one object
347  */
348
349 class SGTexMultipleAnimation : public SGAnimation
350 {
351 public:
352   SGTexMultipleAnimation( SGPropertyNode *prop_root,
353                       SGPropertyNode_ptr props );
354   virtual ~SGTexMultipleAnimation ();
355   virtual void update();
356 private:
357   class TexTransform
358     {
359     public:
360     SGPropertyNode_ptr prop;
361     int subtype; //  0=translation, 1=rotation
362     double offset;
363     double factor;
364     double step;
365     double scroll;
366     SGInterpTable * table;
367     bool has_min;
368     double min;
369     bool has_max;
370     double max;
371     double position;
372     sgMat4 matrix;
373     sgVec3 center;
374     sgVec3 axis;
375   };
376   SGPropertyNode_ptr _prop;
377   TexTransform* _transform;
378   int _num_transforms;
379 };
380
381
382 #endif // _SG_ANIMATION_HXX