]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation.hxx
Split out animation code from fgfs-src/Model/model.[ch]xx and move it over
[simgear.git] / simgear / scene / model / animation.hxx
1 // animation.hxx - classes to manage model animation.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifndef _SG_ANIMATION_HXX
7 #define _SG_ANIMATION_HXX 1
8
9 #ifndef __cplusplus
10 # error This library requires C++
11 #endif
12
13 #include <vector>
14
15 SG_USING_STD(vector);
16
17 #include <plib/sg.h>
18 #include <plib/ssg.h>
19
20 #include <simgear/math/point3d.hxx>
21 #include <simgear/props/props.hxx>
22
23
24 // Don't pull in the headers, since we don't need them here.
25 class ssgBranch;
26 class ssgCutout;
27 class ssgEntity;
28 class ssgRangeSelector;
29 class ssgSelector;
30 class ssgTransform;
31
32 class SGInterpTable;
33 class FGCondition;
34 class FGLocation;
35
36
37 // Has anyone done anything *really* stupid, like making min and max macros?
38 #ifdef min
39 #undef min
40 #endif
41 #ifdef max
42 #undef max
43 #endif
44
45
46 \f
47 //////////////////////////////////////////////////////////////////////
48 // Animation classes
49 //////////////////////////////////////////////////////////////////////
50
51 /**
52  * Abstract base class for all animations.
53  */
54 class Animation :  public ssgBase
55 {
56 public:
57
58   Animation (SGPropertyNode_ptr props, ssgBranch * branch);
59
60   virtual ~Animation ();
61
62   /**
63    * Get the SSG branch holding the animation.
64    */
65   virtual ssgBranch * getBranch () { return _branch; }
66
67   /**
68    * Initialize the animation, after children have been added.
69    */
70   virtual void init ();
71
72   /**
73    * Update the animation.
74    */
75   virtual void update();
76
77   /**
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.
80    */
81   static void set_sim_time_sec( double val ) { sim_time_sec = val; }
82
83 protected:
84
85   static double sim_time_sec;
86
87   ssgBranch * _branch;
88
89 };
90
91
92 /**
93  * A no-op animation.
94  */
95 class NullAnimation : public Animation
96 {
97 public:
98   NullAnimation (SGPropertyNode_ptr props);
99   virtual ~NullAnimation ();
100 };
101
102
103 /**
104  * A range, or level-of-detail (LOD) animation.
105  */
106 class RangeAnimation : public Animation
107 {
108 public:
109   RangeAnimation (SGPropertyNode_ptr props);
110   virtual ~RangeAnimation ();
111 };
112
113
114 /**
115  * Animation to turn and face the screen.
116  */
117 class BillboardAnimation : public Animation
118 {
119 public:
120   BillboardAnimation (SGPropertyNode_ptr props);
121   virtual ~BillboardAnimation ();
122 };
123
124
125 /**
126  * Animation to select alternative versions of the same object.
127  */
128 class SelectAnimation : public Animation
129 {
130 public:
131   SelectAnimation( SGPropertyNode *prop_root,
132                    SGPropertyNode_ptr props );
133   virtual ~SelectAnimation ();
134   virtual void update();
135 private:
136   FGCondition * _condition;
137 };
138
139
140 /**
141  * Animation to spin an object around a center point.
142  *
143  * This animation rotates at a specific velocity.
144  */
145 class SpinAnimation : public Animation
146 {
147 public:
148   SpinAnimation( SGPropertyNode *prop_root,
149                  SGPropertyNode_ptr props,
150                  double sim_time_sec );
151   virtual ~SpinAnimation ();
152   virtual void update();
153 private:
154   SGPropertyNode_ptr _prop;
155   double _factor;
156   double _position_deg;
157   double _last_time_sec;
158   sgMat4 _matrix;
159   sgVec3 _center;
160   sgVec3 _axis;
161 };
162
163
164 /**
165  * Animation to draw objects for a specific amount of time each.
166  */
167 class TimedAnimation : public Animation
168 {
169 public:
170     TimedAnimation (SGPropertyNode_ptr props);
171     virtual ~TimedAnimation ();
172     virtual void update();
173 private:
174     double _duration_sec;
175     double _last_time_sec;
176     int _step;
177 };
178
179
180 /**
181  * Animation to rotate an object around a center point.
182  *
183  * This animation rotates to a specific position.
184  */
185 class RotateAnimation : public Animation
186 {
187 public:
188   RotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
189   virtual ~RotateAnimation ();
190   virtual void update();
191 private:
192   SGPropertyNode_ptr _prop;
193   double _offset_deg;
194   double _factor;
195   SGInterpTable * _table;
196   bool _has_min;
197   double _min_deg;
198   bool _has_max;
199   double _max_deg;
200   double _position_deg;
201   sgMat4 _matrix;
202   sgVec3 _center;
203   sgVec3 _axis;
204 };
205
206
207 /**
208  * Animation to slide along an axis.
209  */
210 class TranslateAnimation : public Animation
211 {
212 public:
213   TranslateAnimation( SGPropertyNode *prop_root,
214                       SGPropertyNode_ptr props );
215   virtual ~TranslateAnimation ();
216   virtual void update();
217 private:
218   SGPropertyNode_ptr _prop;
219   double _offset_m;
220   double _factor;
221   SGInterpTable * _table;
222   bool _has_min;
223   double _min_m;
224   bool _has_max;
225   double _max_m;
226   double _position_m;
227   sgMat4 _matrix;
228   sgVec3 _axis;
229 };
230
231
232 #endif // _SG_ANIMATION_HXX