]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation.hxx
Random buildings - initial commit.
[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::Options* options,
50                       const string &path, int i);
51
52 protected:
53   void apply(osg::Node* node);
54
55   virtual void install(osg::Node& node);
56   virtual osg::Group* createAnimationGroup(osg::Group& parent);
57
58   virtual void apply(osg::Group& group);
59
60   void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode);
61   void removeAttribute(osg::Node& node, osg::StateAttribute::Type type);
62   void removeTextureMode(osg::Node& node, unsigned unit,
63                          osg::StateAttribute::GLMode mode);
64   void removeTextureAttribute(osg::Node& node, unsigned unit,
65                               osg::StateAttribute::Type type);
66   void setRenderBinToInherit(osg::Node& node);
67   void cloneDrawables(osg::Node& node);
68
69   std::string getType() const
70   { return std::string(_configNode->getStringValue("type", "")); }
71
72   const SGPropertyNode* getConfig() const
73   { return _configNode; }
74   SGPropertyNode* getModelRoot() const
75   { return _modelRoot; }
76
77   const SGCondition* getCondition() const;
78
79 private:
80   void installInGroup(const std::string& name, osg::Group& group,
81                       osg::ref_ptr<osg::Group>& animationGroup);
82
83   class RemoveModeVisitor;
84   class RemoveAttributeVisitor;
85   class RemoveTextureModeVisitor;
86   class RemoveTextureAttributeVisitor;
87   class BinToInheritVisitor;
88   class DrawableCloneVisitor;
89
90   bool _found;
91   std::string _name;
92   SGSharedPtr<SGPropertyNode const> _configNode;
93   SGPropertyNode* _modelRoot;
94   std::list<std::string> _objectNames;
95   std::list<osg::ref_ptr<osg::Node> > _installedAnimations;
96   bool _enableHOT;
97   bool _disableShadow;
98 };
99
100 \f
101 //////////////////////////////////////////////////////////////////////
102 // Null animation installer
103 //////////////////////////////////////////////////////////////////////
104
105 class SGGroupAnimation : public SGAnimation {
106 public:
107   SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*);
108   virtual osg::Group* createAnimationGroup(osg::Group& parent);
109 };
110
111 \f
112 //////////////////////////////////////////////////////////////////////
113 // Translate animation installer
114 //////////////////////////////////////////////////////////////////////
115
116 class SGTranslateAnimation : public SGAnimation {
117 public:
118   SGTranslateAnimation(const SGPropertyNode* configNode,
119                        SGPropertyNode* modelRoot);
120   virtual osg::Group* createAnimationGroup(osg::Group& parent);
121 private:
122   class UpdateCallback;
123   SGSharedPtr<const SGCondition> _condition;
124   SGSharedPtr<const SGExpressiond> _animationValue;
125   SGVec3d _axis;
126   double _initialValue;
127 };
128
129 \f
130 //////////////////////////////////////////////////////////////////////
131 // Rotate/Spin animation installer
132 //////////////////////////////////////////////////////////////////////
133
134 class SGRotateAnimation : public SGAnimation {
135 public:
136   SGRotateAnimation(const SGPropertyNode* configNode,
137                     SGPropertyNode* modelRoot);
138   virtual osg::Group* createAnimationGroup(osg::Group& parent);
139 private:
140   class UpdateCallback;
141   class SpinUpdateCallback;
142   SGSharedPtr<const SGCondition> _condition;
143   SGSharedPtr<const SGExpressiond> _animationValue;
144   SGVec3d _axis;
145   SGVec3d _center;
146   double _initialValue;
147   bool _isSpin;
148 };
149
150 \f
151 //////////////////////////////////////////////////////////////////////
152 // Scale animation installer
153 //////////////////////////////////////////////////////////////////////
154
155 class SGScaleAnimation : public SGAnimation {
156 public:
157   SGScaleAnimation(const SGPropertyNode* configNode,
158                    SGPropertyNode* modelRoot);
159   virtual osg::Group* createAnimationGroup(osg::Group& parent);
160 private:
161   class UpdateCallback;
162   SGSharedPtr<const SGCondition> _condition;
163   SGSharedPtr<const SGExpressiond> _animationValue[3];
164   SGVec3d _initialValue;
165   SGVec3d _center;
166 };
167
168 \f
169 //////////////////////////////////////////////////////////////////////
170 // dist scale animation installer
171 //////////////////////////////////////////////////////////////////////
172
173 class SGDistScaleAnimation : public SGAnimation {
174 public:
175   SGDistScaleAnimation(const SGPropertyNode* configNode,
176                        SGPropertyNode* modelRoot);
177   virtual osg::Group* createAnimationGroup(osg::Group& parent);
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 public:
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   class Transform;
206 };
207
208 \f
209 //////////////////////////////////////////////////////////////////////
210 // Range animation installer
211 //////////////////////////////////////////////////////////////////////
212
213 class SGRangeAnimation : public SGAnimation {
214 public:
215   SGRangeAnimation(const SGPropertyNode* configNode,
216                    SGPropertyNode* modelRoot);
217   virtual osg::Group* createAnimationGroup(osg::Group& parent);
218 private:
219   class UpdateCallback;
220   SGSharedPtr<const SGCondition> _condition;
221   SGSharedPtr<const SGExpressiond> _minAnimationValue;
222   SGSharedPtr<const SGExpressiond> _maxAnimationValue;
223   SGVec2d _initialValue;
224 };
225
226 \f
227 //////////////////////////////////////////////////////////////////////
228 // Select animation installer
229 //////////////////////////////////////////////////////////////////////
230
231 class SGSelectAnimation : public SGAnimation {
232 public:
233   SGSelectAnimation(const SGPropertyNode* configNode,
234                     SGPropertyNode* modelRoot);
235   virtual osg::Group* createAnimationGroup(osg::Group& parent);
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::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   class VncCallback;
345 };
346
347 \f
348 //////////////////////////////////////////////////////////////////////
349 // Light animation
350 //////////////////////////////////////////////////////////////////////
351
352 class SGLightAnimation : public SGAnimation {
353 public:
354   SGLightAnimation(const SGPropertyNode* configNode,
355                    SGPropertyNode* modelRoot,
356                    const string &path, int i);
357   virtual osg::Group* createAnimationGroup(osg::Group& parent);
358   virtual void install(osg::Node& node);
359 private:
360   string _light_type;
361   SGVec3d _position;
362   SGVec3d _direction;
363   SGVec4d _ambient;
364   SGVec4d _diffuse;
365   SGVec4d _specular;
366   SGVec3d _attenuation;
367   double _exponent;
368   double _cutoff;
369   double _near;
370   double _far;
371   string _key;
372   class UpdateCallback;
373   friend class UpdateCallback;
374   SGSharedPtr<SGExpressiond> _animationValue;
375 };
376
377 #endif // _SG_ANIMATION_HXX