]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation.hxx
warning fix: initializing members in the order they are declared keeps gcc happy
[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 <osg/ref_ptr>
15 #include <osg/Group>
16 #include <osg/Node>
17 #include <osg/NodeVisitor>
18 #include <osg/Texture2D>
19 #include <osgDB/ReaderWriter>
20
21 #include <simgear/scene/util/SGNodeMasks.hxx>
22 #include <simgear/props/props.hxx>
23 #include <simgear/props/condition.hxx>
24 #include <simgear/structure/SGExpression.hxx>
25
26 // Has anyone done anything *really* stupid, like making min and max macros?
27 #ifdef min
28 #undef min
29 #endif
30 #ifdef max
31 #undef max
32 #endif
33
34 SGExpressiond*
35 read_value(const SGPropertyNode* configNode, SGPropertyNode* modelRoot,
36            const char* unit, double defMin, double defMax);
37 \f
38 //////////////////////////////////////////////////////////////////////
39 // Base class for animation installers
40 //////////////////////////////////////////////////////////////////////
41
42 class SGAnimation : protected osg::NodeVisitor {
43 public:
44   SGAnimation(const SGPropertyNode* configNode, SGPropertyNode* modelRoot);
45   virtual ~SGAnimation();
46
47   static bool animate(osg::Node* node, const SGPropertyNode* configNode,
48                       SGPropertyNode* modelRoot,
49                       const osgDB::ReaderWriter::Options* options);
50
51 protected:
52   void apply(osg::Node* node);
53
54   virtual void install(osg::Node& node);
55   virtual osg::Group* createAnimationGroup(osg::Group& parent);
56
57   virtual void apply(osg::Group& group);
58
59   void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode);
60   void removeAttribute(osg::Node& node, osg::StateAttribute::Type type);
61   void removeTextureMode(osg::Node& node, unsigned unit,
62                          osg::StateAttribute::GLMode mode);
63   void removeTextureAttribute(osg::Node& node, unsigned unit,
64                               osg::StateAttribute::Type type);
65   void setRenderBinToInherit(osg::Node& node);
66   void cloneDrawables(osg::Node& node);
67
68   std::string getType() const
69   { return std::string(_configNode->getStringValue("type", "")); }
70
71   const SGPropertyNode* getConfig() const
72   { return _configNode; }
73   SGPropertyNode* getModelRoot() const
74   { return _modelRoot; }
75
76   const SGCondition* getCondition() const;
77
78 private:
79   void installInGroup(const std::string& name, osg::Group& group,
80                       osg::ref_ptr<osg::Group>& animationGroup);
81
82   class RemoveModeVisitor;
83   class RemoveAttributeVisitor;
84   class RemoveTextureModeVisitor;
85   class RemoveTextureAttributeVisitor;
86   class BinToInheritVisitor;
87   class DrawableCloneVisitor;
88
89   bool _found;
90   std::string _name;
91   SGSharedPtr<SGPropertyNode const> _configNode;
92   SGPropertyNode* _modelRoot;
93   std::list<std::string> _objectNames;
94   std::list<osg::ref_ptr<osg::Node> > _installedAnimations;
95   bool _enableHOT;
96   bool _disableShadow;
97 };
98
99 \f
100 //////////////////////////////////////////////////////////////////////
101 // Null animation installer
102 //////////////////////////////////////////////////////////////////////
103
104 class SGGroupAnimation : public SGAnimation {
105 public:
106   SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*);
107   virtual osg::Group* createAnimationGroup(osg::Group& parent);
108 };
109
110 \f
111 //////////////////////////////////////////////////////////////////////
112 // Translate animation installer
113 //////////////////////////////////////////////////////////////////////
114
115 class SGTranslateAnimation : public SGAnimation {
116 public:
117   SGTranslateAnimation(const SGPropertyNode* configNode,
118                        SGPropertyNode* modelRoot);
119   virtual osg::Group* createAnimationGroup(osg::Group& parent);
120 private:
121   class UpdateCallback;
122   SGSharedPtr<const SGCondition> _condition;
123   SGSharedPtr<const SGExpressiond> _animationValue;
124   SGVec3d _axis;
125   double _initialValue;
126 };
127
128 \f
129 //////////////////////////////////////////////////////////////////////
130 // Rotate/Spin animation installer
131 //////////////////////////////////////////////////////////////////////
132
133 class SGRotateAnimation : public SGAnimation {
134 public:
135   SGRotateAnimation(const SGPropertyNode* configNode,
136                     SGPropertyNode* modelRoot);
137   virtual osg::Group* createAnimationGroup(osg::Group& parent);
138 private:
139   class UpdateCallback;
140   class SpinUpdateCallback;
141   SGSharedPtr<const SGCondition> _condition;
142   SGSharedPtr<const SGExpressiond> _animationValue;
143   SGVec3d _axis;
144   SGVec3d _center;
145   double _initialValue;
146   bool _isSpin;
147 };
148
149 \f
150 //////////////////////////////////////////////////////////////////////
151 // Scale animation installer
152 //////////////////////////////////////////////////////////////////////
153
154 class SGScaleAnimation : public SGAnimation {
155 public:
156   SGScaleAnimation(const SGPropertyNode* configNode,
157                    SGPropertyNode* modelRoot);
158   virtual osg::Group* createAnimationGroup(osg::Group& parent);
159 private:
160   class UpdateCallback;
161   SGSharedPtr<const SGCondition> _condition;
162   SGSharedPtr<const SGExpressiond> _animationValue[3];
163   SGVec3d _initialValue;
164   SGVec3d _center;
165 };
166
167 \f
168 //////////////////////////////////////////////////////////////////////
169 // dist scale animation installer
170 //////////////////////////////////////////////////////////////////////
171
172 class SGDistScaleAnimation : public SGAnimation {
173 public:
174   SGDistScaleAnimation(const SGPropertyNode* configNode,
175                        SGPropertyNode* modelRoot);
176   virtual osg::Group* createAnimationGroup(osg::Group& parent);
177 private:
178   class Transform;
179 };
180
181 \f
182 //////////////////////////////////////////////////////////////////////
183 // dist scale animation installer
184 //////////////////////////////////////////////////////////////////////
185
186 class SGFlashAnimation : public SGAnimation {
187 public:
188   SGFlashAnimation(const SGPropertyNode* configNode,
189                    SGPropertyNode* modelRoot);
190   virtual osg::Group* createAnimationGroup(osg::Group& parent);
191 private:
192   class Transform;
193 };
194
195 \f
196 //////////////////////////////////////////////////////////////////////
197 // dist scale animation installer
198 //////////////////////////////////////////////////////////////////////
199
200 class SGBillboardAnimation : public SGAnimation {
201 public:
202   SGBillboardAnimation(const SGPropertyNode* configNode,
203                        SGPropertyNode* modelRoot);
204   virtual osg::Group* createAnimationGroup(osg::Group& parent);
205 private:
206   class Transform;
207 };
208
209 \f
210 //////////////////////////////////////////////////////////////////////
211 // Range animation installer
212 //////////////////////////////////////////////////////////////////////
213
214 class SGRangeAnimation : public SGAnimation {
215 public:
216   SGRangeAnimation(const SGPropertyNode* configNode,
217                    SGPropertyNode* modelRoot);
218   virtual osg::Group* createAnimationGroup(osg::Group& parent);
219 private:
220   class UpdateCallback;
221   SGSharedPtr<const SGCondition> _condition;
222   SGSharedPtr<const SGExpressiond> _minAnimationValue;
223   SGSharedPtr<const SGExpressiond> _maxAnimationValue;
224   SGVec2d _initialValue;
225 };
226
227 \f
228 //////////////////////////////////////////////////////////////////////
229 // Select animation installer
230 //////////////////////////////////////////////////////////////////////
231
232 class SGSelectAnimation : public SGAnimation {
233 public:
234   SGSelectAnimation(const SGPropertyNode* configNode,
235                     SGPropertyNode* modelRoot);
236   virtual osg::Group* createAnimationGroup(osg::Group& parent);
237 private:
238   class UpdateCallback;
239 };
240
241 \f
242 //////////////////////////////////////////////////////////////////////
243 // Alpha test animation installer
244 //////////////////////////////////////////////////////////////////////
245
246 class SGAlphaTestAnimation : public SGAnimation {
247 public:
248   SGAlphaTestAnimation(const SGPropertyNode* configNode,
249                        SGPropertyNode* modelRoot);
250   virtual void install(osg::Node& node);
251 };
252
253 \f
254 //////////////////////////////////////////////////////////////////////
255 // Blend animation installer
256 //////////////////////////////////////////////////////////////////////
257
258 class SGBlendAnimation : public SGAnimation {
259 public:
260   SGBlendAnimation(const SGPropertyNode* configNode,
261                    SGPropertyNode* modelRoot);
262   virtual osg::Group* createAnimationGroup(osg::Group& parent);
263   virtual void install(osg::Node& node);
264 private:
265   class BlendVisitor;
266   class UpdateCallback;
267   SGSharedPtr<SGExpressiond> _animationValue;
268 };
269
270 \f
271 //////////////////////////////////////////////////////////////////////
272 // Timed animation installer
273 //////////////////////////////////////////////////////////////////////
274
275 class SGTimedAnimation : public SGAnimation {
276 public:
277   SGTimedAnimation(const SGPropertyNode* configNode,
278                    SGPropertyNode* modelRoot);
279   virtual osg::Group* createAnimationGroup(osg::Group& parent);
280 private:
281   class UpdateCallback;
282 };
283
284 \f
285 //////////////////////////////////////////////////////////////////////
286 // Shadow animation installer
287 //////////////////////////////////////////////////////////////////////
288
289 class SGShadowAnimation : public SGAnimation {
290 public:
291   SGShadowAnimation(const SGPropertyNode* configNode,
292                     SGPropertyNode* modelRoot);
293   virtual osg::Group* createAnimationGroup(osg::Group& parent);
294 private:
295   class UpdateCallback;
296 };
297
298 \f
299 //////////////////////////////////////////////////////////////////////
300 // TextureTransform animation
301 //////////////////////////////////////////////////////////////////////
302
303 class SGTexTransformAnimation : public SGAnimation {
304 public:
305   SGTexTransformAnimation(const SGPropertyNode* configNode,
306                           SGPropertyNode* modelRoot);
307   virtual osg::Group* createAnimationGroup(osg::Group& parent);
308 private:
309   class Transform;
310   class Translation;
311   class Rotation;
312   class UpdateCallback;
313   void appendTexTranslate(const SGPropertyNode* config,
314                           UpdateCallback* updateCallback);
315   void appendTexRotate(const SGPropertyNode* config,
316                        UpdateCallback* updateCallback);
317 };
318
319 \f
320 //////////////////////////////////////////////////////////////////////
321 // Shader animation
322 //////////////////////////////////////////////////////////////////////
323
324 class SGShaderAnimation : public SGAnimation {
325 public:
326   SGShaderAnimation(const SGPropertyNode* configNode,
327                     SGPropertyNode* modelRoot,
328                     const osgDB::ReaderWriter::Options* options);
329   virtual osg::Group* createAnimationGroup(osg::Group& parent);
330 private:
331   class UpdateCallback;
332   osg::ref_ptr<osg::Texture2D> _effect_texture;
333 };
334
335 \f
336 //////////////////////////////////////////////////////////////////////
337 // Pick animation
338 //////////////////////////////////////////////////////////////////////
339
340 class SGPickAnimation : public SGAnimation {
341 public:
342   SGPickAnimation(const SGPropertyNode* configNode,
343                   SGPropertyNode* modelRoot);
344   virtual osg::Group* createAnimationGroup(osg::Group& parent);
345 private:
346   class PickCallback;
347 };
348
349 #endif // _SG_ANIMATION_HXX