]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation.hxx
Add the ability to include stepped texture translations for things like digital displ...
[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_ptr props);
103   virtual ~SGRangeAnimation ();
104 };
105
106
107 /**
108  * Animation to turn and face the screen.
109  */
110 class SGBillboardAnimation : public SGAnimation
111 {
112 public:
113   SGBillboardAnimation (SGPropertyNode_ptr props);
114   virtual ~SGBillboardAnimation ();
115 };
116
117
118 /**
119  * Animation to select alternative versions of the same object.
120  */
121 class SGSelectAnimation : public SGAnimation
122 {
123 public:
124   SGSelectAnimation( SGPropertyNode *prop_root,
125                    SGPropertyNode_ptr props );
126   virtual ~SGSelectAnimation ();
127   virtual void update();
128 private:
129   SGCondition * _condition;
130 };
131
132
133 /**
134  * Animation to spin an object around a center point.
135  *
136  * This animation rotates at a specific velocity.
137  */
138 class SGSpinAnimation : public SGAnimation
139 {
140 public:
141   SGSpinAnimation( SGPropertyNode *prop_root,
142                  SGPropertyNode_ptr props,
143                  double sim_time_sec );
144   virtual ~SGSpinAnimation ();
145   virtual void update();
146 private:
147   SGPropertyNode_ptr _prop;
148   double _factor;
149   double _position_deg;
150   double _last_time_sec;
151   sgMat4 _matrix;
152   sgVec3 _center;
153   sgVec3 _axis;
154 };
155
156
157 /**
158  * Animation to draw objects for a specific amount of time each.
159  */
160 class SGTimedAnimation : public SGAnimation
161 {
162 public:
163     SGTimedAnimation (SGPropertyNode_ptr props);
164     virtual ~SGTimedAnimation ();
165     virtual void update();
166 private:
167     double _duration_sec;
168     double _last_time_sec;
169     int _step;
170 };
171
172
173 /**
174  * Animation to rotate an object around a center point.
175  *
176  * This animation rotates to a specific position.
177  */
178 class SGRotateAnimation : public SGAnimation
179 {
180 public:
181   SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
182   virtual ~SGRotateAnimation ();
183   virtual void update();
184 private:
185   SGPropertyNode_ptr _prop;
186   double _offset_deg;
187   double _factor;
188   SGInterpTable * _table;
189   bool _has_min;
190   double _min_deg;
191   bool _has_max;
192   double _max_deg;
193   double _position_deg;
194   sgMat4 _matrix;
195   sgVec3 _center;
196   sgVec3 _axis;
197 };
198
199
200 /**
201  * Animation to slide along an axis.
202  */
203 class SGTranslateAnimation : public SGAnimation
204 {
205 public:
206   SGTranslateAnimation( SGPropertyNode *prop_root,
207                       SGPropertyNode_ptr props );
208   virtual ~SGTranslateAnimation ();
209   virtual void update();
210 private:
211   SGPropertyNode_ptr _prop;
212   double _offset_m;
213   double _factor;
214   SGInterpTable * _table;
215   bool _has_min;
216   double _min_m;
217   bool _has_max;
218   double _max_m;
219   double _position_m;
220   sgMat4 _matrix;
221   sgVec3 _axis;
222 };
223
224 /**
225  * Animation to rotate texture mappings around a center point.
226  *
227  * This animation rotates to a specific position.
228  */
229 class SGTexRotateAnimation : public SGAnimation
230 {
231 public:
232   SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
233   virtual ~SGTexRotateAnimation ();
234   virtual void update();
235 private:
236   SGPropertyNode_ptr _prop;
237   double _offset_deg;
238   double _factor;
239   SGInterpTable * _table;
240   bool _has_min;
241   double _min_deg;
242   bool _has_max;
243   double _max_deg;
244   double _position_deg;
245   sgMat4 _matrix;
246   sgVec3 _center;
247   sgVec3 _axis;
248 };
249
250
251 /**
252  * Animation to slide texture mappings along an axis.
253  */
254 class SGTexTranslateAnimation : public SGAnimation
255 {
256 public:
257   SGTexTranslateAnimation( SGPropertyNode *prop_root,
258                       SGPropertyNode_ptr props );
259   virtual ~SGTexTranslateAnimation ();
260   virtual void update();
261 private:
262   SGPropertyNode_ptr _prop;
263   double _offset_m;
264   double _factor;
265   double _step;
266   SGInterpTable * _table;
267   bool _has_min;
268   double _min_m;
269   bool _has_max;
270   double _max_m;
271   double _position_m;
272   sgMat4 _matrix;
273   sgVec3 _axis;
274 };
275
276 #endif // _SG_ANIMATION_HXX