]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation.hxx
Add a blend animation
[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_ptr props);
103   virtual ~SGRangeAnimation ();
104 };
105
106
107 /**
108  * Animation to turn and face the screen.
109  */
110 class SGBillboardAnimation : public SGAnimation
111 {
112 public:
113   SGBillboardAnimation (SGPropertyNode_ptr props);
114   virtual ~SGBillboardAnimation ();
115 };
116
117
118 /**
119  * Animation to select alternative versions of the same object.
120  */
121 class SGSelectAnimation : public SGAnimation
122 {
123 public:
124   SGSelectAnimation( SGPropertyNode *prop_root,
125                    SGPropertyNode_ptr props );
126   virtual ~SGSelectAnimation ();
127   virtual void update();
128 private:
129   SGCondition * _condition;
130 };
131
132
133 /**
134  * Animation to spin an object around a center point.
135  *
136  * This animation rotates at a specific velocity.
137  */
138 class SGSpinAnimation : public SGAnimation
139 {
140 public:
141   SGSpinAnimation( SGPropertyNode *prop_root,
142                  SGPropertyNode_ptr props,
143                  double sim_time_sec );
144   virtual ~SGSpinAnimation ();
145   virtual void update();
146 private:
147   SGPropertyNode_ptr _prop;
148   double _factor;
149   double _position_deg;
150   double _last_time_sec;
151   sgMat4 _matrix;
152   sgVec3 _center;
153   sgVec3 _axis;
154 };
155
156
157 /**
158  * Animation to draw objects for a specific amount of time each.
159  */
160 class SGTimedAnimation : public SGAnimation
161 {
162 public:
163     SGTimedAnimation (SGPropertyNode_ptr props);
164     virtual ~SGTimedAnimation ();
165     virtual void update();
166 private:
167     double _duration_sec;
168     double _last_time_sec;
169     int _step;
170 };
171
172
173 /**
174  * Animation to rotate an object around a center point.
175  *
176  * This animation rotates to a specific position.
177  */
178 class SGRotateAnimation : public SGAnimation
179 {
180 public:
181   SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
182   virtual ~SGRotateAnimation ();
183   virtual void update();
184 private:
185   SGPropertyNode_ptr _prop;
186   double _offset_deg;
187   double _factor;
188   SGInterpTable * _table;
189   bool _has_min;
190   double _min_deg;
191   bool _has_max;
192   double _max_deg;
193   double _position_deg;
194   sgMat4 _matrix;
195   sgVec3 _center;
196   sgVec3 _axis;
197 };
198
199
200 /**
201  * Animation to slide along an axis.
202  */
203 class SGTranslateAnimation : public SGAnimation
204 {
205 public:
206   SGTranslateAnimation( SGPropertyNode *prop_root,
207                       SGPropertyNode_ptr props );
208   virtual ~SGTranslateAnimation ();
209   virtual void update();
210 private:
211   SGPropertyNode_ptr _prop;
212   double _offset_m;
213   double _factor;
214   SGInterpTable * _table;
215   bool _has_min;
216   double _min_m;
217   bool _has_max;
218   double _max_m;
219   double _position_m;
220   sgMat4 _matrix;
221   sgVec3 _axis;
222 };
223
224 /**
225  * Animation to blend an object.
226  */
227 class SGBlendAnimation : public SGAnimation
228 {
229 public:
230   SGBlendAnimation( SGPropertyNode *prop_root,
231                       SGPropertyNode_ptr props );
232   virtual ~SGBlendAnimation ();
233   virtual void update();
234 private:
235   SGPropertyNode_ptr _prop;
236   SGInterpTable * _table;
237   double _prev_value;
238   double _offset;
239   double _factor;
240   bool _has_min;
241   double _min;
242   bool _has_max;
243   double _max;
244 };
245
246 /**
247  * Animation to scale an object.
248  */
249 class SGScaleAnimation : public SGAnimation
250 {
251 public:
252   SGScaleAnimation( SGPropertyNode *prop_root,
253                         SGPropertyNode_ptr props );
254   virtual ~SGScaleAnimation ();
255   virtual void update();
256 private:
257   SGPropertyNode_ptr _prop;
258   double _x_factor;
259   double _y_factor;
260   double _z_factor;
261   double _x_offset;
262   double _y_offset;
263   double _z_offset;
264   SGInterpTable * _table;
265   bool _has_min_x;
266   bool _has_min_y;
267   bool _has_min_z;
268   double _min_x;
269   double _min_y;
270   double _min_z;
271   bool _has_max_x;
272   bool _has_max_y;
273   bool _has_max_z;
274   double _max_x;
275   double _max_y;
276   double _max_z;
277   double _x_scale;
278   double _y_scale;
279   double _z_scale;
280   sgMat4 _matrix;
281 };
282
283 /**
284  * Animation to rotate texture mappings around a center point.
285  *
286  * This animation rotates to a specific position.
287  */
288 class SGTexRotateAnimation : public SGAnimation
289 {
290 public:
291   SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
292   virtual ~SGTexRotateAnimation ();
293   virtual void update();
294 private:
295   SGPropertyNode_ptr _prop;
296   double _offset_deg;
297   double _factor;
298   SGInterpTable * _table;
299   bool _has_min;
300   double _min_deg;
301   bool _has_max;
302   double _max_deg;
303   double _position_deg;
304   sgMat4 _matrix;
305   sgVec3 _center;
306   sgVec3 _axis;
307 };
308
309
310 /**
311  * Animation to slide texture mappings along an axis.
312  */
313 class SGTexTranslateAnimation : public SGAnimation
314 {
315 public:
316   SGTexTranslateAnimation( SGPropertyNode *prop_root,
317                       SGPropertyNode_ptr props );
318   virtual ~SGTexTranslateAnimation ();
319   virtual void update();
320 private:
321   SGPropertyNode_ptr _prop;
322   double _offset;
323   double _factor;
324   double _step;
325   double _scroll;
326   SGInterpTable * _table;
327   bool _has_min;
328   double _min;
329   bool _has_max;
330   double _max;
331   double _position;
332   sgMat4 _matrix;
333   sgVec3 _axis;
334 };
335
336
337
338 /**
339  * Classes for handling multiple types of Texture translations on one object
340  */
341
342 class SGTexMultipleAnimation : public SGAnimation
343 {
344 public:
345   SGTexMultipleAnimation( SGPropertyNode *prop_root,
346                       SGPropertyNode_ptr props );
347   virtual ~SGTexMultipleAnimation ();
348   virtual void update();
349 private:
350   class TexTransform
351     {
352     public:
353     SGPropertyNode_ptr prop;
354     int subtype; //  0=translation, 1=rotation
355     double offset;
356     double factor;
357     double step;
358     double scroll;
359     SGInterpTable * table;
360     bool has_min;
361     double min;
362     bool has_max;
363     double max;
364     double position;
365     sgMat4 matrix;
366     sgVec3 center;
367     sgVec3 axis;
368   };
369   SGPropertyNode_ptr _prop;
370   TexTransform* _transform;
371   int _num_transforms;
372 };
373
374
375 #endif // _SG_ANIMATION_HXX