]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation.hxx
Minor tweaks and clean ups.
[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 SGInterpTable;
26 class FGCondition;
27
28
29 // Has anyone done anything *really* stupid, like making min and max macros?
30 #ifdef min
31 #undef min
32 #endif
33 #ifdef max
34 #undef max
35 #endif
36
37
38 \f
39 //////////////////////////////////////////////////////////////////////
40 // Animation classes
41 //////////////////////////////////////////////////////////////////////
42
43 /**
44  * Abstract base class for all animations.
45  */
46 class Animation :  public ssgBase
47 {
48 public:
49
50   Animation (SGPropertyNode_ptr props, ssgBranch * branch);
51
52   virtual ~Animation ();
53
54   /**
55    * Get the SSG branch holding the animation.
56    */
57   virtual ssgBranch * getBranch () { return _branch; }
58
59   /**
60    * Initialize the animation, after children have been added.
61    */
62   virtual void init ();
63
64   /**
65    * Update the animation.
66    */
67   virtual void update();
68
69   /**
70    * Set the value of sim_time_sec.  This needs to be called every
71    * frame in order for the time based animations to work correctly.
72    */
73   static void set_sim_time_sec( double val ) { sim_time_sec = val; }
74
75 protected:
76
77   static double sim_time_sec;
78
79   ssgBranch * _branch;
80
81 };
82
83
84 /**
85  * A no-op animation.
86  */
87 class NullAnimation : public Animation
88 {
89 public:
90   NullAnimation (SGPropertyNode_ptr props);
91   virtual ~NullAnimation ();
92 };
93
94
95 /**
96  * A range, or level-of-detail (LOD) animation.
97  */
98 class RangeAnimation : public Animation
99 {
100 public:
101   RangeAnimation (SGPropertyNode_ptr props);
102   virtual ~RangeAnimation ();
103 };
104
105
106 /**
107  * Animation to turn and face the screen.
108  */
109 class BillboardAnimation : public Animation
110 {
111 public:
112   BillboardAnimation (SGPropertyNode_ptr props);
113   virtual ~BillboardAnimation ();
114 };
115
116
117 /**
118  * Animation to select alternative versions of the same object.
119  */
120 class SelectAnimation : public Animation
121 {
122 public:
123   SelectAnimation( SGPropertyNode *prop_root,
124                    SGPropertyNode_ptr props );
125   virtual ~SelectAnimation ();
126   virtual void update();
127 private:
128   FGCondition * _condition;
129 };
130
131
132 /**
133  * Animation to spin an object around a center point.
134  *
135  * This animation rotates at a specific velocity.
136  */
137 class SpinAnimation : public Animation
138 {
139 public:
140   SpinAnimation( SGPropertyNode *prop_root,
141                  SGPropertyNode_ptr props,
142                  double sim_time_sec );
143   virtual ~SpinAnimation ();
144   virtual void update();
145 private:
146   SGPropertyNode_ptr _prop;
147   double _factor;
148   double _position_deg;
149   double _last_time_sec;
150   sgMat4 _matrix;
151   sgVec3 _center;
152   sgVec3 _axis;
153 };
154
155
156 /**
157  * Animation to draw objects for a specific amount of time each.
158  */
159 class TimedAnimation : public Animation
160 {
161 public:
162     TimedAnimation (SGPropertyNode_ptr props);
163     virtual ~TimedAnimation ();
164     virtual void update();
165 private:
166     double _duration_sec;
167     double _last_time_sec;
168     int _step;
169 };
170
171
172 /**
173  * Animation to rotate an object around a center point.
174  *
175  * This animation rotates to a specific position.
176  */
177 class RotateAnimation : public Animation
178 {
179 public:
180   RotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
181   virtual ~RotateAnimation ();
182   virtual void update();
183 private:
184   SGPropertyNode_ptr _prop;
185   double _offset_deg;
186   double _factor;
187   SGInterpTable * _table;
188   bool _has_min;
189   double _min_deg;
190   bool _has_max;
191   double _max_deg;
192   double _position_deg;
193   sgMat4 _matrix;
194   sgVec3 _center;
195   sgVec3 _axis;
196 };
197
198
199 /**
200  * Animation to slide along an axis.
201  */
202 class TranslateAnimation : public Animation
203 {
204 public:
205   TranslateAnimation( SGPropertyNode *prop_root,
206                       SGPropertyNode_ptr props );
207   virtual ~TranslateAnimation ();
208   virtual void update();
209 private:
210   SGPropertyNode_ptr _prop;
211   double _offset_m;
212   double _factor;
213   SGInterpTable * _table;
214   bool _has_min;
215   double _min_m;
216   bool _has_max;
217   double _max_m;
218   double _position_m;
219   sgMat4 _matrix;
220   sgVec3 _axis;
221 };
222
223
224 #endif // _SG_ANIMATION_HXX