2 // animation.hxx - classes to manage model animation.
3 // Written by David Megginson, started 2002.
5 // This file is in the Public Domain, and comes with no warranty.
7 #ifndef _SG_ANIMATION_HXX
8 #define _SG_ANIMATION_HXX 1
11 # error This library requires C++
23 #include <simgear/math/point3d.hxx>
24 #include <simgear/props/props.hxx>
27 // Don't pull in the headers, since we don't need them here.
30 class SGPersonalityBranch;
33 // Has anyone done anything *really* stupid, like making min and max macros?
43 //////////////////////////////////////////////////////////////////////
45 //////////////////////////////////////////////////////////////////////
48 * Abstract base class for all animations.
50 class SGAnimation : public ssgBase
54 SGAnimation (SGPropertyNode_ptr props, ssgBranch * branch);
56 virtual ~SGAnimation ();
59 * Get the SSG branch holding the animation.
61 virtual ssgBranch * getBranch () { return _branch; }
64 * Initialize the animation, after children have been added.
69 * Update the animation.
74 * Restore the state after the animation.
76 virtual void restore();
79 * Set the value of sim_time_sec. This needs to be called every
80 * frame in order for the time based animations to work correctly.
82 static void set_sim_time_sec( double val ) { sim_time_sec = val; }
85 * Current personality branch : enable animation to behave differently
88 static SGPersonalityBranch *current_object;
92 static double sim_time_sec;
102 class SGNullAnimation : public SGAnimation
105 SGNullAnimation (SGPropertyNode_ptr props);
106 virtual ~SGNullAnimation ();
111 * A range, or level-of-detail (LOD) animation.
113 class SGRangeAnimation : public SGAnimation
116 SGRangeAnimation (SGPropertyNode *prop_root,
117 SGPropertyNode_ptr props);
118 virtual ~SGRangeAnimation ();
119 virtual int update();
121 SGPropertyNode_ptr _min_prop;
122 SGPropertyNode_ptr _max_prop;
127 SGCondition * _condition;
132 * Animation to turn and face the screen.
134 class SGBillboardAnimation : public SGAnimation
137 SGBillboardAnimation (SGPropertyNode_ptr props);
138 virtual ~SGBillboardAnimation ();
143 * Animation to select alternative versions of the same object.
145 class SGSelectAnimation : public SGAnimation
148 SGSelectAnimation( SGPropertyNode *prop_root,
149 SGPropertyNode_ptr props );
150 virtual ~SGSelectAnimation ();
151 virtual int update();
153 SGCondition * _condition;
158 * Animation to spin an object around a center point.
160 * This animation rotates at a specific velocity.
162 class SGSpinAnimation : public SGAnimation
165 SGSpinAnimation( SGPropertyNode *prop_root,
166 SGPropertyNode_ptr props,
167 double sim_time_sec );
168 virtual ~SGSpinAnimation ();
169 virtual int update();
171 SGPropertyNode_ptr _prop;
173 double _position_deg;
174 double _last_time_sec;
178 SGCondition * _condition;
183 * Animation to draw objects for a specific amount of time each.
185 class SGTimedAnimation : public SGAnimation
188 SGTimedAnimation (SGPropertyNode_ptr props);
189 virtual ~SGTimedAnimation ();
191 virtual int update();
193 bool _use_personality;
194 enum PersonalityVar { INIT, LAST_TIME_SEC, TOTAL_DURATION_SEC, BRANCH_DURATION_SEC, STEP };
195 double _duration_sec;
196 double _last_time_sec;
197 double _total_duration_sec;
199 struct DurationSpec {
200 DurationSpec( double m = 0.0 ) : _min(m), _max(m) {}
201 DurationSpec( double m1, double m2 ) : _min(m1), _max(m2) {}
204 vector<DurationSpec> _branch_duration_specs;
205 vector<double> _branch_duration_sec;
210 * Animation to rotate an object around a center point.
212 * This animation rotates to a specific position.
214 class SGRotateAnimation : public SGAnimation
217 SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
218 virtual ~SGRotateAnimation ();
219 virtual int update();
221 SGPropertyNode_ptr _prop;
224 SGInterpTable * _table;
229 double _position_deg;
233 SGCondition * _condition;
238 * Animation to slide along an axis.
240 class SGTranslateAnimation : public SGAnimation
243 SGTranslateAnimation( SGPropertyNode *prop_root,
244 SGPropertyNode_ptr props );
245 virtual ~SGTranslateAnimation ();
246 virtual int update();
248 SGPropertyNode_ptr _prop;
251 SGInterpTable * _table;
259 SGCondition * _condition;
263 * Animation to blend an object.
265 class SGBlendAnimation : public SGAnimation
268 SGBlendAnimation( SGPropertyNode *prop_root,
269 SGPropertyNode_ptr props );
270 virtual ~SGBlendAnimation ();
271 virtual int update();
273 SGPropertyNode_ptr _prop;
274 SGInterpTable * _table;
285 * Animation to scale an object.
287 class SGScaleAnimation : public SGAnimation
290 SGScaleAnimation( SGPropertyNode *prop_root,
291 SGPropertyNode_ptr props );
292 virtual ~SGScaleAnimation ();
293 virtual int update();
295 SGPropertyNode_ptr _prop;
302 SGInterpTable * _table;
322 * Animation to rotate texture mappings around a center point.
324 * This animation rotates to a specific position.
326 class SGTexRotateAnimation : public SGAnimation
329 SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
330 virtual ~SGTexRotateAnimation ();
331 virtual int update();
333 SGPropertyNode_ptr _prop;
336 SGInterpTable * _table;
341 double _position_deg;
349 * Animation to slide texture mappings along an axis.
351 class SGTexTranslateAnimation : public SGAnimation
354 SGTexTranslateAnimation( SGPropertyNode *prop_root,
355 SGPropertyNode_ptr props );
356 virtual ~SGTexTranslateAnimation ();
357 virtual int update();
359 SGPropertyNode_ptr _prop;
364 SGInterpTable * _table;
377 * Classes for handling multiple types of Texture translations on one object
380 class SGTexMultipleAnimation : public SGAnimation
383 SGTexMultipleAnimation( SGPropertyNode *prop_root,
384 SGPropertyNode_ptr props );
385 virtual ~SGTexMultipleAnimation ();
386 virtual int update();
391 SGPropertyNode_ptr prop;
392 int subtype; // 0=translation, 1=rotation
397 SGInterpTable * table;
407 SGPropertyNode_ptr _prop;
408 TexTransform* _transform;
414 * An "animation" to enable the alpha test
416 class SGAlphaTestAnimation : public SGAnimation
419 SGAlphaTestAnimation(SGPropertyNode_ptr props);
420 virtual ~SGAlphaTestAnimation ();
423 void setAlphaClampToBranch(ssgBranch *b, float clamp);
429 * An "animation" that compute a scale according to
430 * the angle between an axis and the view direction
432 class SGFlashAnimation : public SGAnimation
435 SGFlashAnimation(SGPropertyNode_ptr props);
436 virtual ~SGFlashAnimation ();
438 static void flashCallback( sgMat4 r, sgFrustum *f, sgMat4 m, void *d );
439 void flashCallback( sgMat4 r, sgFrustum *f, sgMat4 m );
442 sgVec3 _axis, _center;
443 float _power, _factor, _offset, _min_v, _max_v;
449 * An animation that compute a scale according to
450 * the distance from a point and the viewer
452 class SGDistScaleAnimation : public SGAnimation
455 SGDistScaleAnimation(SGPropertyNode_ptr props);
456 virtual ~SGDistScaleAnimation ();
458 static void distScaleCallback( sgMat4 r, sgFrustum *f, sgMat4 m, void *d );
459 void distScaleCallback( sgMat4 r, sgFrustum *f, sgMat4 m );
463 float _factor, _offset, _min_v, _max_v;
464 bool _has_min, _has_max;
465 SGInterpTable * _table;
469 #endif // _SG_ANIMATION_HXX