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