]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation.hxx
Frederic Bouvier:
[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 int update();
69
70   /**
71    * Restore the state after the animation.
72    */
73   virtual void restore();
74
75   /**
76    * Set the value of sim_time_sec.  This needs to be called every
77    * frame in order for the time based animations to work correctly.
78    */
79   static void set_sim_time_sec( double val ) { sim_time_sec = val; }
80
81 protected:
82
83   static double sim_time_sec;
84
85   ssgBranch * _branch;
86
87 };
88
89
90 /**
91  * A no-op animation.
92  */
93 class SGNullAnimation : public SGAnimation
94 {
95 public:
96   SGNullAnimation (SGPropertyNode_ptr props);
97   virtual ~SGNullAnimation ();
98 };
99
100
101 /**
102  * A range, or level-of-detail (LOD) animation.
103  */
104 class SGRangeAnimation : public SGAnimation
105 {
106 public:
107   SGRangeAnimation (SGPropertyNode *prop_root,
108                     SGPropertyNode_ptr props);
109   virtual ~SGRangeAnimation ();
110   virtual int update();
111 private:
112   SGPropertyNode_ptr _min_prop;
113   SGPropertyNode_ptr _max_prop;
114   float _min;
115   float _max;
116   float _min_factor;
117   float _max_factor;
118 };
119
120
121 /**
122  * Animation to turn and face the screen.
123  */
124 class SGBillboardAnimation : public SGAnimation
125 {
126 public:
127   SGBillboardAnimation (SGPropertyNode_ptr props);
128   virtual ~SGBillboardAnimation ();
129 };
130
131
132 /**
133  * Animation to select alternative versions of the same object.
134  */
135 class SGSelectAnimation : public SGAnimation
136 {
137 public:
138   SGSelectAnimation( SGPropertyNode *prop_root,
139                    SGPropertyNode_ptr props );
140   virtual ~SGSelectAnimation ();
141   virtual int update();
142 private:
143   SGCondition * _condition;
144 };
145
146
147 /**
148  * Animation to spin an object around a center point.
149  *
150  * This animation rotates at a specific velocity.
151  */
152 class SGSpinAnimation : public SGAnimation
153 {
154 public:
155   SGSpinAnimation( SGPropertyNode *prop_root,
156                  SGPropertyNode_ptr props,
157                  double sim_time_sec );
158   virtual ~SGSpinAnimation ();
159   virtual int update();
160 private:
161   SGPropertyNode_ptr _prop;
162   double _factor;
163   double _position_deg;
164   double _last_time_sec;
165   sgMat4 _matrix;
166   sgVec3 _center;
167   sgVec3 _axis;
168 };
169
170
171 /**
172  * Animation to draw objects for a specific amount of time each.
173  */
174 class SGTimedAnimation : public SGAnimation
175 {
176 public:
177     SGTimedAnimation (SGPropertyNode_ptr props);
178     virtual ~SGTimedAnimation ();
179     virtual int update();
180 private:
181     double _duration_sec;
182     double _last_time_sec;
183     int _step;
184 };
185
186
187 /**
188  * Animation to rotate an object around a center point.
189  *
190  * This animation rotates to a specific position.
191  */
192 class SGRotateAnimation : public SGAnimation
193 {
194 public:
195   SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
196   virtual ~SGRotateAnimation ();
197   virtual int update();
198 private:
199   SGPropertyNode_ptr _prop;
200   double _offset_deg;
201   double _factor;
202   SGInterpTable * _table;
203   bool _has_min;
204   double _min_deg;
205   bool _has_max;
206   double _max_deg;
207   double _position_deg;
208   sgMat4 _matrix;
209   sgVec3 _center;
210   sgVec3 _axis;
211 };
212
213
214 /**
215  * Animation to slide along an axis.
216  */
217 class SGTranslateAnimation : public SGAnimation
218 {
219 public:
220   SGTranslateAnimation( SGPropertyNode *prop_root,
221                       SGPropertyNode_ptr props );
222   virtual ~SGTranslateAnimation ();
223   virtual int update();
224 private:
225   SGPropertyNode_ptr _prop;
226   double _offset_m;
227   double _factor;
228   SGInterpTable * _table;
229   bool _has_min;
230   double _min_m;
231   bool _has_max;
232   double _max_m;
233   double _position_m;
234   sgMat4 _matrix;
235   sgVec3 _axis;
236 };
237
238 /**
239  * Animation to blend an object.
240  */
241 class SGBlendAnimation : public SGAnimation
242 {
243 public:
244   SGBlendAnimation( SGPropertyNode *prop_root,
245                       SGPropertyNode_ptr props );
246   virtual ~SGBlendAnimation ();
247   virtual int update();
248 private:
249   SGPropertyNode_ptr _prop;
250   SGInterpTable * _table;
251   double _prev_value;
252   double _offset;
253   double _factor;
254   bool _has_min;
255   double _min;
256   bool _has_max;
257   double _max;
258 };
259
260 /**
261  * Animation to scale an object.
262  */
263 class SGScaleAnimation : public SGAnimation
264 {
265 public:
266   SGScaleAnimation( SGPropertyNode *prop_root,
267                         SGPropertyNode_ptr props );
268   virtual ~SGScaleAnimation ();
269   virtual int update();
270 private:
271   SGPropertyNode_ptr _prop;
272   double _x_factor;
273   double _y_factor;
274   double _z_factor;
275   double _x_offset;
276   double _y_offset;
277   double _z_offset;
278   SGInterpTable * _table;
279   bool _has_min_x;
280   bool _has_min_y;
281   bool _has_min_z;
282   double _min_x;
283   double _min_y;
284   double _min_z;
285   bool _has_max_x;
286   bool _has_max_y;
287   bool _has_max_z;
288   double _max_x;
289   double _max_y;
290   double _max_z;
291   double _x_scale;
292   double _y_scale;
293   double _z_scale;
294   sgMat4 _matrix;
295 };
296
297 /**
298  * Animation to rotate texture mappings around a center point.
299  *
300  * This animation rotates to a specific position.
301  */
302 class SGTexRotateAnimation : public SGAnimation
303 {
304 public:
305   SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
306   virtual ~SGTexRotateAnimation ();
307   virtual int update();
308 private:
309   SGPropertyNode_ptr _prop;
310   double _offset_deg;
311   double _factor;
312   SGInterpTable * _table;
313   bool _has_min;
314   double _min_deg;
315   bool _has_max;
316   double _max_deg;
317   double _position_deg;
318   sgMat4 _matrix;
319   sgVec3 _center;
320   sgVec3 _axis;
321 };
322
323
324 /**
325  * Animation to slide texture mappings along an axis.
326  */
327 class SGTexTranslateAnimation : public SGAnimation
328 {
329 public:
330   SGTexTranslateAnimation( SGPropertyNode *prop_root,
331                       SGPropertyNode_ptr props );
332   virtual ~SGTexTranslateAnimation ();
333   virtual int update();
334 private:
335   SGPropertyNode_ptr _prop;
336   double _offset;
337   double _factor;
338   double _step;
339   double _scroll;
340   SGInterpTable * _table;
341   bool _has_min;
342   double _min;
343   bool _has_max;
344   double _max;
345   double _position;
346   sgMat4 _matrix;
347   sgVec3 _axis;
348 };
349
350
351
352 /**
353  * Classes for handling multiple types of Texture translations on one object
354  */
355
356 class SGTexMultipleAnimation : public SGAnimation
357 {
358 public:
359   SGTexMultipleAnimation( SGPropertyNode *prop_root,
360                       SGPropertyNode_ptr props );
361   virtual ~SGTexMultipleAnimation ();
362   virtual int update();
363 private:
364   class TexTransform
365     {
366     public:
367     SGPropertyNode_ptr prop;
368     int subtype; //  0=translation, 1=rotation
369     double offset;
370     double factor;
371     double step;
372     double scroll;
373     SGInterpTable * table;
374     bool has_min;
375     double min;
376     bool has_max;
377     double max;
378     double position;
379     sgMat4 matrix;
380     sgVec3 center;
381     sgVec3 axis;
382   };
383   SGPropertyNode_ptr _prop;
384   TexTransform* _transform;
385   int _num_transforms;
386 };
387
388
389 /**
390  * An "animation" to enable the alpha test 
391  */
392 class SGAlphaTestAnimation : public SGAnimation
393 {
394 public:
395   SGAlphaTestAnimation(SGPropertyNode_ptr props);
396   virtual ~SGAlphaTestAnimation ();
397   virtual void init();
398 private:
399   void setAlphaClampToBranch(ssgBranch *b, float clamp);
400   float _alpha_clamp;
401 };
402
403
404 /**
405  * An "animation" that compute a scale according to 
406  * the angle between an axis and the view direction
407  */
408 class SGFlashAnimation : public SGAnimation
409 {
410 public:
411   SGFlashAnimation(SGPropertyNode_ptr props);
412   virtual ~SGFlashAnimation ();
413 };
414
415
416 #endif // _SG_ANIMATION_HXX