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