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