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.
32 // Has anyone done anything *really* stupid, like making min and max macros?
42 //////////////////////////////////////////////////////////////////////
44 //////////////////////////////////////////////////////////////////////
47 * Abstract base class for all animations.
49 class SGAnimation : public ssgBase
53 SGAnimation (SGPropertyNode_ptr props, ssgBranch * branch);
55 virtual ~SGAnimation ();
58 * Get the SSG branch holding the animation.
60 virtual ssgBranch * getBranch () { return _branch; }
63 * Initialize the animation, after children have been added.
68 * Update the animation.
73 * Restore the state after the animation.
75 virtual void restore();
78 * Set the value of sim_time_sec. This needs to be called every
79 * frame in order for the time based animations to work correctly.
81 static void set_sim_time_sec( double val ) { sim_time_sec = val; }
84 * Current personality branch : enable animation to behave differently
87 static ssgBranch *current_object;
91 static double sim_time_sec;
101 class SGNullAnimation : public SGAnimation
104 SGNullAnimation (SGPropertyNode_ptr props);
105 virtual ~SGNullAnimation ();
110 * A range, or level-of-detail (LOD) animation.
112 class SGRangeAnimation : public SGAnimation
115 SGRangeAnimation (SGPropertyNode *prop_root,
116 SGPropertyNode_ptr props);
117 virtual ~SGRangeAnimation ();
118 virtual int update();
120 SGPropertyNode_ptr _min_prop;
121 SGPropertyNode_ptr _max_prop;
126 SGCondition * _condition;
131 * Animation to turn and face the screen.
133 class SGBillboardAnimation : public SGAnimation
136 SGBillboardAnimation (SGPropertyNode_ptr props);
137 virtual ~SGBillboardAnimation ();
142 * Animation to select alternative versions of the same object.
144 class SGSelectAnimation : public SGAnimation
147 SGSelectAnimation( SGPropertyNode *prop_root,
148 SGPropertyNode_ptr props );
149 virtual ~SGSelectAnimation ();
150 virtual int update();
152 SGCondition * _condition;
157 * Animation to spin an object around a center point.
159 * This animation rotates at a specific velocity.
161 class SGSpinAnimation : public SGAnimation
164 SGSpinAnimation( SGPropertyNode *prop_root,
165 SGPropertyNode_ptr props,
166 double sim_time_sec );
167 virtual ~SGSpinAnimation ();
168 virtual int update();
170 SGPropertyNode_ptr _prop;
172 double _position_deg;
173 double _last_time_sec;
177 SGCondition * _condition;
182 * Animation to draw objects for a specific amount of time each.
184 class SGTimedAnimation : public SGAnimation
187 SGTimedAnimation (SGPropertyNode_ptr props);
188 virtual ~SGTimedAnimation ();
189 virtual int update();
191 double _duration_sec;
192 map<ssgBranch *,double> _last_time_sec;
193 map<ssgBranch *,double> _total_duration_sec;
195 struct DurationSpec {
196 DurationSpec( double m = 0.0 ) : _min(m), _max(m) {}
197 DurationSpec( double m1, double m2 ) : _min(m1), _max(m2) {}
200 vector<DurationSpec> _branch_duration_specs;
201 bool _use_personality;
202 typedef map<ssgBranch *,vector<double> > PersonalityMap;
203 PersonalityMap _branch_duration_sec;
208 * Animation to rotate an object around a center point.
210 * This animation rotates to a specific position.
212 class SGRotateAnimation : public SGAnimation
215 SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
216 virtual ~SGRotateAnimation ();
217 virtual int update();
219 SGPropertyNode_ptr _prop;
222 SGInterpTable * _table;
227 double _position_deg;
231 SGCondition * _condition;
236 * Animation to slide along an axis.
238 class SGTranslateAnimation : public SGAnimation
241 SGTranslateAnimation( SGPropertyNode *prop_root,
242 SGPropertyNode_ptr props );
243 virtual ~SGTranslateAnimation ();
244 virtual int update();
246 SGPropertyNode_ptr _prop;
249 SGInterpTable * _table;
257 SGCondition * _condition;
261 * Animation to blend an object.
263 class SGBlendAnimation : public SGAnimation
266 SGBlendAnimation( SGPropertyNode *prop_root,
267 SGPropertyNode_ptr props );
268 virtual ~SGBlendAnimation ();
269 virtual int update();
271 SGPropertyNode_ptr _prop;
272 SGInterpTable * _table;
283 * Animation to scale an object.
285 class SGScaleAnimation : public SGAnimation
288 SGScaleAnimation( SGPropertyNode *prop_root,
289 SGPropertyNode_ptr props );
290 virtual ~SGScaleAnimation ();
291 virtual int update();
293 SGPropertyNode_ptr _prop;
300 SGInterpTable * _table;
320 * Animation to rotate texture mappings around a center point.
322 * This animation rotates to a specific position.
324 class SGTexRotateAnimation : public SGAnimation
327 SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
328 virtual ~SGTexRotateAnimation ();
329 virtual int update();
331 SGPropertyNode_ptr _prop;
334 SGInterpTable * _table;
339 double _position_deg;
347 * Animation to slide texture mappings along an axis.
349 class SGTexTranslateAnimation : public SGAnimation
352 SGTexTranslateAnimation( SGPropertyNode *prop_root,
353 SGPropertyNode_ptr props );
354 virtual ~SGTexTranslateAnimation ();
355 virtual int update();
357 SGPropertyNode_ptr _prop;
362 SGInterpTable * _table;
375 * Classes for handling multiple types of Texture translations on one object
378 class SGTexMultipleAnimation : public SGAnimation
381 SGTexMultipleAnimation( SGPropertyNode *prop_root,
382 SGPropertyNode_ptr props );
383 virtual ~SGTexMultipleAnimation ();
384 virtual int update();
389 SGPropertyNode_ptr prop;
390 int subtype; // 0=translation, 1=rotation
395 SGInterpTable * table;
405 SGPropertyNode_ptr _prop;
406 TexTransform* _transform;
412 * An "animation" to enable the alpha test
414 class SGAlphaTestAnimation : public SGAnimation
417 SGAlphaTestAnimation(SGPropertyNode_ptr props);
418 virtual ~SGAlphaTestAnimation ();
421 void setAlphaClampToBranch(ssgBranch *b, float clamp);
427 * An "animation" that compute a scale according to
428 * the angle between an axis and the view direction
430 class SGFlashAnimation : public SGAnimation
433 SGFlashAnimation(SGPropertyNode_ptr props);
434 virtual ~SGFlashAnimation ();
438 #endif // _SG_ANIMATION_HXX