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