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 ();
190 virtual int update();
192 bool _use_personality;
193 enum PersonalityVar { INIT, LAST_TIME_SEC, TOTAL_DURATION_SEC, BRANCH_DURATION_SEC, STEP };
194 double _duration_sec;
195 double _last_time_sec;
196 double _total_duration_sec;
198 struct DurationSpec {
199 DurationSpec( double m = 0.0 ) : _min(m), _max(m) {}
200 DurationSpec( double m1, double m2 ) : _min(m1), _max(m2) {}
203 vector<DurationSpec> _branch_duration_specs;
204 vector<double> _branch_duration_sec;
209 * Animation to rotate an object around a center point.
211 * This animation rotates to a specific position.
213 class SGRotateAnimation : public SGAnimation
216 SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
217 virtual ~SGRotateAnimation ();
218 virtual int update();
220 SGPropertyNode_ptr _prop;
223 SGInterpTable * _table;
228 double _position_deg;
232 SGCondition * _condition;
237 * Animation to slide along an axis.
239 class SGTranslateAnimation : public SGAnimation
242 SGTranslateAnimation( SGPropertyNode *prop_root,
243 SGPropertyNode_ptr props );
244 virtual ~SGTranslateAnimation ();
245 virtual int update();
247 SGPropertyNode_ptr _prop;
250 SGInterpTable * _table;
258 SGCondition * _condition;
262 * Animation to blend an object.
264 class SGBlendAnimation : public SGAnimation
267 SGBlendAnimation( SGPropertyNode *prop_root,
268 SGPropertyNode_ptr props );
269 virtual ~SGBlendAnimation ();
270 virtual int update();
272 SGPropertyNode_ptr _prop;
273 SGInterpTable * _table;
284 * Animation to scale an object.
286 class SGScaleAnimation : public SGAnimation
289 SGScaleAnimation( SGPropertyNode *prop_root,
290 SGPropertyNode_ptr props );
291 virtual ~SGScaleAnimation ();
292 virtual int update();
294 SGPropertyNode_ptr _prop;
301 SGInterpTable * _table;
321 * Animation to rotate texture mappings around a center point.
323 * This animation rotates to a specific position.
325 class SGTexRotateAnimation : public SGAnimation
328 SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
329 virtual ~SGTexRotateAnimation ();
330 virtual int update();
332 SGPropertyNode_ptr _prop;
335 SGInterpTable * _table;
340 double _position_deg;
348 * Animation to slide texture mappings along an axis.
350 class SGTexTranslateAnimation : public SGAnimation
353 SGTexTranslateAnimation( SGPropertyNode *prop_root,
354 SGPropertyNode_ptr props );
355 virtual ~SGTexTranslateAnimation ();
356 virtual int update();
358 SGPropertyNode_ptr _prop;
363 SGInterpTable * _table;
376 * Classes for handling multiple types of Texture translations on one object
379 class SGTexMultipleAnimation : public SGAnimation
382 SGTexMultipleAnimation( SGPropertyNode *prop_root,
383 SGPropertyNode_ptr props );
384 virtual ~SGTexMultipleAnimation ();
385 virtual int update();
390 SGPropertyNode_ptr prop;
391 int subtype; // 0=translation, 1=rotation
396 SGInterpTable * table;
406 SGPropertyNode_ptr _prop;
407 TexTransform* _transform;
413 * An "animation" to enable the alpha test
415 class SGAlphaTestAnimation : public SGAnimation
418 SGAlphaTestAnimation(SGPropertyNode_ptr props);
419 virtual ~SGAlphaTestAnimation ();
422 void setAlphaClampToBranch(ssgBranch *b, float clamp);
428 * An "animation" that compute a scale according to
429 * the angle between an axis and the view direction
431 class SGFlashAnimation : public SGAnimation
434 SGFlashAnimation(SGPropertyNode_ptr props);
435 virtual ~SGFlashAnimation ();
439 #endif // _SG_ANIMATION_HXX