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
53 enum PersonalityVar { INIT_SPIN, LAST_TIME_SEC_SPIN, FACTOR_SPIN,
54 POSITION_DEG_SPIN, INIT_TIMED, LAST_TIME_SEC_TIMED,
55 TOTAL_DURATION_SEC_TIMED, BRANCH_DURATION_SEC_TIMED,
58 SGAnimation (SGPropertyNode_ptr props, ssgBranch * branch);
60 virtual ~SGAnimation ();
63 * Get the SSG branch holding the animation.
65 virtual ssgBranch * getBranch () { return _branch; }
68 * Initialize the animation, after children have been added.
73 * Update the animation.
78 * Restore the state after the animation.
80 virtual void restore();
83 * Set the value of sim_time_sec. This needs to be called every
84 * frame in order for the time based animations to work correctly.
86 static void set_sim_time_sec( double val ) { sim_time_sec = val; }
89 * Current personality branch : enable animation to behave differently
92 static SGPersonalityBranch *current_object;
96 static double sim_time_sec;
106 class SGNullAnimation : public SGAnimation
109 SGNullAnimation (SGPropertyNode_ptr props);
110 virtual ~SGNullAnimation ();
115 * A range, or level-of-detail (LOD) animation.
117 class SGRangeAnimation : public SGAnimation
120 SGRangeAnimation (SGPropertyNode *prop_root,
121 SGPropertyNode_ptr props);
122 virtual ~SGRangeAnimation ();
123 virtual int update();
125 SGPropertyNode_ptr _min_prop;
126 SGPropertyNode_ptr _max_prop;
131 SGCondition * _condition;
136 * Animation to turn and face the screen.
138 class SGBillboardAnimation : public SGAnimation
141 SGBillboardAnimation (SGPropertyNode_ptr props);
142 virtual ~SGBillboardAnimation ();
147 * Animation to select alternative versions of the same object.
149 class SGSelectAnimation : public SGAnimation
152 SGSelectAnimation( SGPropertyNode *prop_root,
153 SGPropertyNode_ptr props );
154 virtual ~SGSelectAnimation ();
155 virtual int update();
157 SGCondition * _condition;
162 * Animation to spin an object around a center point.
164 * This animation rotates at a specific velocity.
166 class SGSpinAnimation : public SGAnimation
169 SGSpinAnimation( SGPropertyNode *prop_root,
170 SGPropertyNode_ptr props,
171 double sim_time_sec );
172 virtual ~SGSpinAnimation ();
173 virtual int update();
175 bool _use_personality;
176 SGPropertyNode_ptr _prop;
180 double _position_deg;
181 double _position_deg_min;
182 double _position_deg_max;
183 double _last_time_sec;
187 SGCondition * _condition;
192 * Animation to draw objects for a specific amount of time each.
194 class SGTimedAnimation : public SGAnimation
197 SGTimedAnimation (SGPropertyNode_ptr props);
198 virtual ~SGTimedAnimation ();
200 virtual int update();
202 bool _use_personality;
203 double _duration_sec;
204 double _last_time_sec;
205 double _total_duration_sec;
207 struct DurationSpec {
208 DurationSpec( double m = 0.0 ) : _min(m), _max(m) {}
209 DurationSpec( double m1, double m2 ) : _min(m1), _max(m2) {}
212 vector<DurationSpec> _branch_duration_specs;
213 vector<double> _branch_duration_sec;
218 * Animation to rotate an object around a center point.
220 * This animation rotates to a specific position.
222 class SGRotateAnimation : public SGAnimation
225 SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
226 virtual ~SGRotateAnimation ();
227 virtual int update();
229 SGPropertyNode_ptr _prop;
232 SGInterpTable * _table;
237 double _position_deg;
241 SGCondition * _condition;
246 * Animation to slide along an axis.
248 class SGTranslateAnimation : public SGAnimation
251 SGTranslateAnimation( SGPropertyNode *prop_root,
252 SGPropertyNode_ptr props );
253 virtual ~SGTranslateAnimation ();
254 virtual int update();
256 SGPropertyNode_ptr _prop;
259 SGInterpTable * _table;
267 SGCondition * _condition;
271 * Animation to blend an object.
273 class SGBlendAnimation : public SGAnimation
276 SGBlendAnimation( SGPropertyNode *prop_root,
277 SGPropertyNode_ptr props );
278 virtual ~SGBlendAnimation ();
279 virtual int update();
281 SGPropertyNode_ptr _prop;
282 SGInterpTable * _table;
293 * Animation to scale an object.
295 class SGScaleAnimation : public SGAnimation
298 SGScaleAnimation( SGPropertyNode *prop_root,
299 SGPropertyNode_ptr props );
300 virtual ~SGScaleAnimation ();
301 virtual int update();
303 SGPropertyNode_ptr _prop;
310 SGInterpTable * _table;
330 * Animation to rotate texture mappings around a center point.
332 * This animation rotates to a specific position.
334 class SGTexRotateAnimation : public SGAnimation
337 SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
338 virtual ~SGTexRotateAnimation ();
339 virtual int update();
341 SGPropertyNode_ptr _prop;
344 SGInterpTable * _table;
349 double _position_deg;
357 * Animation to slide texture mappings along an axis.
359 class SGTexTranslateAnimation : public SGAnimation
362 SGTexTranslateAnimation( SGPropertyNode *prop_root,
363 SGPropertyNode_ptr props );
364 virtual ~SGTexTranslateAnimation ();
365 virtual int update();
367 SGPropertyNode_ptr _prop;
372 SGInterpTable * _table;
385 * Classes for handling multiple types of Texture translations on one object
388 class SGTexMultipleAnimation : public SGAnimation
391 SGTexMultipleAnimation( SGPropertyNode *prop_root,
392 SGPropertyNode_ptr props );
393 virtual ~SGTexMultipleAnimation ();
394 virtual int update();
399 SGPropertyNode_ptr prop;
400 int subtype; // 0=translation, 1=rotation
405 SGInterpTable * table;
415 SGPropertyNode_ptr _prop;
416 TexTransform* _transform;
422 * An "animation" to enable the alpha test
424 class SGAlphaTestAnimation : public SGAnimation
427 SGAlphaTestAnimation(SGPropertyNode_ptr props);
428 virtual ~SGAlphaTestAnimation ();
431 void setAlphaClampToBranch(ssgBranch *b, float clamp);
437 * An "animation" that compute a scale according to
438 * the angle between an axis and the view direction
440 class SGFlashAnimation : public SGAnimation
443 SGFlashAnimation(SGPropertyNode_ptr props);
444 virtual ~SGFlashAnimation ();
446 static void flashCallback( sgMat4 r, sgFrustum *f, sgMat4 m, void *d );
447 void flashCallback( sgMat4 r, sgFrustum *f, sgMat4 m );
450 sgVec3 _axis, _center;
451 float _power, _factor, _offset, _min_v, _max_v;
457 * An animation that compute a scale according to
458 * the distance from a point and the viewer
460 class SGDistScaleAnimation : public SGAnimation
463 SGDistScaleAnimation(SGPropertyNode_ptr props);
464 virtual ~SGDistScaleAnimation ();
466 static void distScaleCallback( sgMat4 r, sgFrustum *f, sgMat4 m, void *d );
467 void distScaleCallback( sgMat4 r, sgFrustum *f, sgMat4 m );
471 float _factor, _offset, _min_v, _max_v;
472 bool _has_min, _has_max;
473 SGInterpTable * _table;
477 #endif // _SG_ANIMATION_HXX