]> 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   SGSharedPtr<const SGCondition> _condition;
151   SGSharedPtr<const SGDoubleValue> _animationValue;
152   SGVec3d _axis;
153   double _initialValue;
154 };
155
156 \f
157 //////////////////////////////////////////////////////////////////////
158 // Rotate/Spin animation installer
159 //////////////////////////////////////////////////////////////////////
160
161 class SGRotateAnimation : public SGAnimation {
162 public:
163   SGRotateAnimation(const SGPropertyNode* configNode,
164                     SGPropertyNode* modelRoot);
165   virtual osg::Group* createAnimationGroup(osg::Group& parent);
166 private:
167   class UpdateCallback;
168   class SpinUpdateCallback;
169   SGSharedPtr<const SGCondition> _condition;
170   SGSharedPtr<const SGDoubleValue> _animationValue;
171   SGVec3d _axis;
172   SGVec3d _center;
173   double _initialValue;
174   bool _isSpin;
175 };
176
177 \f
178 //////////////////////////////////////////////////////////////////////
179 // Scale animation installer
180 //////////////////////////////////////////////////////////////////////
181
182 class SGScaleAnimation : public SGAnimation {
183 public:
184   SGScaleAnimation(const SGPropertyNode* configNode,
185                    SGPropertyNode* modelRoot);
186   virtual osg::Group* createAnimationGroup(osg::Group& parent);
187 private:
188   class UpdateCallback;
189   SGSharedPtr<const SGCondition> _condition;
190   SGSharedPtr<const SGDoubleValue> _animationValue[3];
191   SGVec3d _initialValue;
192   SGVec3d _center;
193 };
194
195 \f
196 //////////////////////////////////////////////////////////////////////
197 // dist scale animation installer
198 //////////////////////////////////////////////////////////////////////
199
200 class SGDistScaleAnimation : public SGAnimation {
201 public:
202   SGDistScaleAnimation(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 // dist scale animation installer
212 //////////////////////////////////////////////////////////////////////
213
214 class SGFlashAnimation : public SGAnimation {
215 public:
216   SGFlashAnimation(const SGPropertyNode* configNode,
217                    SGPropertyNode* modelRoot);
218   virtual osg::Group* createAnimationGroup(osg::Group& parent);
219 private:
220   class Transform;
221 };
222
223 \f
224 //////////////////////////////////////////////////////////////////////
225 // dist scale animation installer
226 //////////////////////////////////////////////////////////////////////
227
228 class SGBillboardAnimation : public SGAnimation {
229 public:
230   SGBillboardAnimation(const SGPropertyNode* configNode,
231                        SGPropertyNode* modelRoot);
232   virtual osg::Group* createAnimationGroup(osg::Group& parent);
233 private:
234   class Transform;
235 };
236
237 \f
238 //////////////////////////////////////////////////////////////////////
239 // Range animation installer
240 //////////////////////////////////////////////////////////////////////
241
242 class SGRangeAnimation : public SGAnimation {
243 public:
244   SGRangeAnimation(const SGPropertyNode* configNode,
245                    SGPropertyNode* modelRoot);
246   virtual osg::Group* createAnimationGroup(osg::Group& parent);
247 private:
248   class UpdateCallback;
249   SGSharedPtr<const SGCondition> _condition;
250   SGSharedPtr<const SGDoubleValue> _minAnimationValue;
251   SGSharedPtr<const SGDoubleValue> _maxAnimationValue;
252   SGVec2d _initialValue;
253 };
254
255 \f
256 //////////////////////////////////////////////////////////////////////
257 // Select animation installer
258 //////////////////////////////////////////////////////////////////////
259
260 class SGSelectAnimation : public SGAnimation {
261 public:
262   SGSelectAnimation(const SGPropertyNode* configNode,
263                     SGPropertyNode* modelRoot);
264   virtual osg::Group* createAnimationGroup(osg::Group& parent);
265 private:
266   class UpdateCallback;
267 };
268
269 \f
270 //////////////////////////////////////////////////////////////////////
271 // Alpha test animation installer
272 //////////////////////////////////////////////////////////////////////
273
274 class SGAlphaTestAnimation : public SGAnimation {
275 public:
276   SGAlphaTestAnimation(const SGPropertyNode* configNode,
277                        SGPropertyNode* modelRoot);
278   virtual void install(osg::Node& node);
279 };
280
281 \f
282 //////////////////////////////////////////////////////////////////////
283 // Blend animation installer
284 //////////////////////////////////////////////////////////////////////
285
286 class SGBlendAnimation : public SGAnimation {
287 public:
288   SGBlendAnimation(const SGPropertyNode* configNode,
289                    SGPropertyNode* modelRoot);
290   virtual osg::Group* createAnimationGroup(osg::Group& parent);
291   virtual void install(osg::Node& node);
292 private:
293   class BlendVisitor;
294   class UpdateCallback;
295   SGSharedPtr<SGDoubleValue> _animationValue;
296 };
297
298 \f
299 //////////////////////////////////////////////////////////////////////
300 // Timed animation installer
301 //////////////////////////////////////////////////////////////////////
302
303 class SGTimedAnimation : public SGAnimation {
304 public:
305   SGTimedAnimation(const SGPropertyNode* configNode,
306                    SGPropertyNode* modelRoot);
307   virtual osg::Group* createAnimationGroup(osg::Group& parent);
308 private:
309   class UpdateCallback;
310 };
311
312 \f
313 //////////////////////////////////////////////////////////////////////
314 // Shadow animation installer
315 //////////////////////////////////////////////////////////////////////
316
317 class SGShadowAnimation : public SGAnimation {
318 public:
319   SGShadowAnimation(const SGPropertyNode* configNode,
320                     SGPropertyNode* modelRoot);
321   virtual osg::Group* createAnimationGroup(osg::Group& parent);
322 private:
323   class UpdateCallback;
324 };
325
326 \f
327 //////////////////////////////////////////////////////////////////////
328 // TextureTransform animation
329 //////////////////////////////////////////////////////////////////////
330
331 class SGTexTransformAnimation : public SGAnimation {
332 public:
333   SGTexTransformAnimation(const SGPropertyNode* configNode,
334                           SGPropertyNode* modelRoot);
335   virtual osg::Group* createAnimationGroup(osg::Group& parent);
336 private:
337   class Transform;
338   class Translation;
339   class Rotation;
340   class UpdateCallback;
341   void appendTexTranslate(const SGPropertyNode* config,
342                           UpdateCallback* updateCallback);
343   void appendTexRotate(const SGPropertyNode* config,
344                        UpdateCallback* updateCallback);
345 };
346
347 \f
348 //////////////////////////////////////////////////////////////////////
349 // Shader animation
350 //////////////////////////////////////////////////////////////////////
351
352 class SGShaderAnimation : public SGAnimation {
353 public:
354   SGShaderAnimation(const SGPropertyNode* configNode,
355                     SGPropertyNode* modelRoot);
356   virtual osg::Group* createAnimationGroup(osg::Group& parent);
357 private:
358   class UpdateCallback;
359   osg::ref_ptr<osg::Texture2D> _effect_texture;
360 };
361
362 \f
363 //////////////////////////////////////////////////////////////////////
364 // Pick animation
365 //////////////////////////////////////////////////////////////////////
366
367 class SGPickAnimation : public SGAnimation {
368 public:
369   SGPickAnimation(const SGPropertyNode* configNode,
370                   SGPropertyNode* modelRoot);
371   virtual osg::Group* createAnimationGroup(osg::Group& parent);
372 private:
373   class PickCallback;
374 };
375
376 #endif // _SG_ANIMATION_HXX