# error This library requires C++
#endif
-#include <vector>
-
-SG_USING_STD(vector);
-
-#include <plib/sg.h>
-#include <plib/ssg.h>
-
-#include <simgear/math/point3d.hxx>
+#include <osg/ref_ptr>
+#include <osg/Group>
+#include <osg/Node>
+#include <osg/NodeVisitor>
+#include <osg/Texture2D>
+#include <osgDB/ReaderWriter>
+
+#include <simgear/scene/util/SGNodeMasks.hxx>
#include <simgear/props/props.hxx>
-
-
-// Don't pull in the headers, since we don't need them here.
-class SGInterpTable;
-class SGCondition;
-
+#include <simgear/props/condition.hxx>
+#include <simgear/structure/SGExpression.hxx>
// Has anyone done anything *really* stupid, like making min and max macros?
#ifdef min
#undef max
#endif
-
+SGExpressiond*
+read_value(const SGPropertyNode* configNode, SGPropertyNode* modelRoot,
+ const char* unit, double defMin, double defMax);
\f
//////////////////////////////////////////////////////////////////////
-// Animation classes
+// Base class for animation installers
//////////////////////////////////////////////////////////////////////
-/**
- * Abstract base class for all animations.
- */
-class SGAnimation : public ssgBase
-{
+class SGAnimation : protected osg::NodeVisitor {
public:
+ SGAnimation(const SGPropertyNode* configNode, SGPropertyNode* modelRoot);
+ virtual ~SGAnimation();
- SGAnimation (SGPropertyNode_ptr props, ssgBranch * branch);
-
- virtual ~SGAnimation ();
+ static bool animate(osg::Node* node, const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot,
+ const osgDB::ReaderWriter::Options* options);
- /**
- * Get the SSG branch holding the animation.
- */
- virtual ssgBranch * getBranch () { return _branch; }
+protected:
+ void apply(osg::Node* node);
- /**
- * Initialize the animation, after children have been added.
- */
- virtual void init ();
+ virtual void install(osg::Node& node);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
- /**
- * Update the animation.
- */
- virtual void update();
+ virtual void apply(osg::Group& group);
- /**
- * Set the value of sim_time_sec. This needs to be called every
- * frame in order for the time based animations to work correctly.
- */
- static void set_sim_time_sec( double val ) { sim_time_sec = val; }
+ void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode);
+ void removeAttribute(osg::Node& node, osg::StateAttribute::Type type);
+ void removeTextureMode(osg::Node& node, unsigned unit,
+ osg::StateAttribute::GLMode mode);
+ void removeTextureAttribute(osg::Node& node, unsigned unit,
+ osg::StateAttribute::Type type);
+ void setRenderBinToInherit(osg::Node& node);
+ void cloneDrawables(osg::Node& node);
-protected:
+ std::string getType() const
+ { return std::string(_configNode->getStringValue("type", "")); }
- static double sim_time_sec;
+ const SGPropertyNode* getConfig() const
+ { return _configNode; }
+ SGPropertyNode* getModelRoot() const
+ { return _modelRoot; }
- ssgBranch * _branch;
+ const SGCondition* getCondition() const;
+private:
+ void installInGroup(const std::string& name, osg::Group& group,
+ osg::ref_ptr<osg::Group>& animationGroup);
+
+ class RemoveModeVisitor;
+ class RemoveAttributeVisitor;
+ class RemoveTextureModeVisitor;
+ class RemoveTextureAttributeVisitor;
+ class BinToInheritVisitor;
+ class DrawableCloneVisitor;
+
+ bool _found;
+ std::string _name;
+ SGSharedPtr<SGPropertyNode const> _configNode;
+ SGPropertyNode* _modelRoot;
+ std::list<std::string> _objectNames;
+ std::list<osg::ref_ptr<osg::Node> > _installedAnimations;
+ bool _enableHOT;
+ bool _disableShadow;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// Null animation installer
+//////////////////////////////////////////////////////////////////////
-/**
- * A no-op animation.
- */
-class SGNullAnimation : public SGAnimation
-{
+class SGGroupAnimation : public SGAnimation {
public:
- SGNullAnimation (SGPropertyNode_ptr props);
- virtual ~SGNullAnimation ();
+ SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
};
+\f
+//////////////////////////////////////////////////////////////////////
+// Translate animation installer
+//////////////////////////////////////////////////////////////////////
-/**
- * A range, or level-of-detail (LOD) animation.
- */
-class SGRangeAnimation : public SGAnimation
-{
+class SGTranslateAnimation : public SGAnimation {
public:
- SGRangeAnimation (SGPropertyNode *prop_root,
- SGPropertyNode_ptr props);
- virtual ~SGRangeAnimation ();
- virtual void update();
+ SGTranslateAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
private:
- SGPropertyNode_ptr _min_prop;
- SGPropertyNode_ptr _max_prop;
- float _min;
- float _max;
- float _min_factor;
- float _max_factor;
+ class UpdateCallback;
+ SGSharedPtr<const SGCondition> _condition;
+ SGSharedPtr<const SGExpressiond> _animationValue;
+ SGVec3d _axis;
+ double _initialValue;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// Rotate/Spin animation installer
+//////////////////////////////////////////////////////////////////////
-/**
- * Animation to turn and face the screen.
- */
-class SGBillboardAnimation : public SGAnimation
-{
+class SGRotateAnimation : public SGAnimation {
public:
- SGBillboardAnimation (SGPropertyNode_ptr props);
- virtual ~SGBillboardAnimation ();
+ SGRotateAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
+private:
+ class UpdateCallback;
+ class SpinUpdateCallback;
+ SGSharedPtr<const SGCondition> _condition;
+ SGSharedPtr<const SGExpressiond> _animationValue;
+ SGVec3d _axis;
+ SGVec3d _center;
+ double _initialValue;
+ bool _isSpin;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// Scale animation installer
+//////////////////////////////////////////////////////////////////////
-/**
- * Animation to select alternative versions of the same object.
- */
-class SGSelectAnimation : public SGAnimation
-{
+class SGScaleAnimation : public SGAnimation {
public:
- SGSelectAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props );
- virtual ~SGSelectAnimation ();
- virtual void update();
+ SGScaleAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
private:
- SGCondition * _condition;
+ class UpdateCallback;
+ SGSharedPtr<const SGCondition> _condition;
+ SGSharedPtr<const SGExpressiond> _animationValue[3];
+ SGVec3d _initialValue;
+ SGVec3d _center;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// dist scale animation installer
+//////////////////////////////////////////////////////////////////////
-/**
- * Animation to spin an object around a center point.
- *
- * This animation rotates at a specific velocity.
- */
-class SGSpinAnimation : public SGAnimation
-{
+class SGDistScaleAnimation : public SGAnimation {
public:
- SGSpinAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props,
- double sim_time_sec );
- virtual ~SGSpinAnimation ();
- virtual void update();
-private:
- SGPropertyNode_ptr _prop;
- double _factor;
- double _position_deg;
- double _last_time_sec;
- sgMat4 _matrix;
- sgVec3 _center;
- sgVec3 _axis;
+ SGDistScaleAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
+ class Transform;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// dist scale animation installer
+//////////////////////////////////////////////////////////////////////
-/**
- * Animation to draw objects for a specific amount of time each.
- */
-class SGTimedAnimation : public SGAnimation
-{
+class SGFlashAnimation : public SGAnimation {
public:
- SGTimedAnimation (SGPropertyNode_ptr props);
- virtual ~SGTimedAnimation ();
- virtual void update();
-private:
- double _duration_sec;
- double _last_time_sec;
- int _step;
+ SGFlashAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
+public:
+ class Transform;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// dist scale animation installer
+//////////////////////////////////////////////////////////////////////
-/**
- * Animation to rotate an object around a center point.
- *
- * This animation rotates to a specific position.
- */
-class SGRotateAnimation : public SGAnimation
-{
+class SGBillboardAnimation : public SGAnimation {
public:
- SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
- virtual ~SGRotateAnimation ();
- virtual void update();
-private:
- SGPropertyNode_ptr _prop;
- double _offset_deg;
- double _factor;
- SGInterpTable * _table;
- bool _has_min;
- double _min_deg;
- bool _has_max;
- double _max_deg;
- double _position_deg;
- sgMat4 _matrix;
- sgVec3 _center;
- sgVec3 _axis;
+ SGBillboardAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
+ class Transform;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// Range animation installer
+//////////////////////////////////////////////////////////////////////
-/**
- * Animation to slide along an axis.
- */
-class SGTranslateAnimation : public SGAnimation
-{
+class SGRangeAnimation : public SGAnimation {
public:
- SGTranslateAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props );
- virtual ~SGTranslateAnimation ();
- virtual void update();
+ SGRangeAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
private:
- SGPropertyNode_ptr _prop;
- double _offset_m;
- double _factor;
- SGInterpTable * _table;
- bool _has_min;
- double _min_m;
- bool _has_max;
- double _max_m;
- double _position_m;
- sgMat4 _matrix;
- sgVec3 _axis;
+ class UpdateCallback;
+ SGSharedPtr<const SGCondition> _condition;
+ SGSharedPtr<const SGExpressiond> _minAnimationValue;
+ SGSharedPtr<const SGExpressiond> _maxAnimationValue;
+ SGVec2d _initialValue;
};
-/**
- * Animation to blend an object.
- */
-class SGBlendAnimation : public SGAnimation
-{
+\f
+//////////////////////////////////////////////////////////////////////
+// Select animation installer
+//////////////////////////////////////////////////////////////////////
+
+class SGSelectAnimation : public SGAnimation {
public:
- SGBlendAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props );
- virtual ~SGBlendAnimation ();
- virtual void update();
+ SGSelectAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
private:
- SGPropertyNode_ptr _prop;
- SGInterpTable * _table;
- double _prev_value;
- double _offset;
- double _factor;
- bool _has_min;
- double _min;
- bool _has_max;
- double _max;
+ class UpdateCallback;
};
-/**
- * Animation to scale an object.
- */
-class SGScaleAnimation : public SGAnimation
-{
+\f
+//////////////////////////////////////////////////////////////////////
+// Alpha test animation installer
+//////////////////////////////////////////////////////////////////////
+
+class SGAlphaTestAnimation : public SGAnimation {
public:
- SGScaleAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props );
- virtual ~SGScaleAnimation ();
- virtual void update();
-private:
- SGPropertyNode_ptr _prop;
- double _x_factor;
- double _y_factor;
- double _z_factor;
- double _x_offset;
- double _y_offset;
- double _z_offset;
- SGInterpTable * _table;
- bool _has_min_x;
- bool _has_min_y;
- bool _has_min_z;
- double _min_x;
- double _min_y;
- double _min_z;
- bool _has_max_x;
- bool _has_max_y;
- bool _has_max_z;
- double _max_x;
- double _max_y;
- double _max_z;
- double _x_scale;
- double _y_scale;
- double _z_scale;
- sgMat4 _matrix;
+ SGAlphaTestAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual void install(osg::Node& node);
};
-/**
- * Animation to rotate texture mappings around a center point.
- *
- * This animation rotates to a specific position.
- */
-class SGTexRotateAnimation : public SGAnimation
-{
+\f
+//////////////////////////////////////////////////////////////////////
+// Blend animation installer
+//////////////////////////////////////////////////////////////////////
+
+class SGBlendAnimation : public SGAnimation {
public:
- SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
- virtual ~SGTexRotateAnimation ();
- virtual void update();
+ SGBlendAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
+ virtual void install(osg::Node& node);
private:
- SGPropertyNode_ptr _prop;
- double _offset_deg;
- double _factor;
- SGInterpTable * _table;
- bool _has_min;
- double _min_deg;
- bool _has_max;
- double _max_deg;
- double _position_deg;
- sgMat4 _matrix;
- sgVec3 _center;
- sgVec3 _axis;
+ class BlendVisitor;
+ class UpdateCallback;
+ SGSharedPtr<SGExpressiond> _animationValue;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// Timed animation installer
+//////////////////////////////////////////////////////////////////////
-/**
- * Animation to slide texture mappings along an axis.
- */
-class SGTexTranslateAnimation : public SGAnimation
-{
+class SGTimedAnimation : public SGAnimation {
public:
- SGTexTranslateAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props );
- virtual ~SGTexTranslateAnimation ();
- virtual void update();
+ SGTimedAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
private:
- SGPropertyNode_ptr _prop;
- double _offset;
- double _factor;
- double _step;
- double _scroll;
- SGInterpTable * _table;
- bool _has_min;
- double _min;
- bool _has_max;
- double _max;
- double _position;
- sgMat4 _matrix;
- sgVec3 _axis;
+ class UpdateCallback;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// Shadow animation installer
+//////////////////////////////////////////////////////////////////////
+class SGShadowAnimation : public SGAnimation {
+public:
+ SGShadowAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
+private:
+ class UpdateCallback;
+};
-/**
- * Classes for handling multiple types of Texture translations on one object
- */
+\f
+//////////////////////////////////////////////////////////////////////
+// TextureTransform animation
+//////////////////////////////////////////////////////////////////////
-class SGTexMultipleAnimation : public SGAnimation
-{
+class SGTexTransformAnimation : public SGAnimation {
public:
- SGTexMultipleAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props );
- virtual ~SGTexMultipleAnimation ();
- virtual void update();
+ SGTexTransformAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
private:
- class TexTransform
- {
- public:
- SGPropertyNode_ptr prop;
- int subtype; // 0=translation, 1=rotation
- double offset;
- double factor;
- double step;
- double scroll;
- SGInterpTable * table;
- bool has_min;
- double min;
- bool has_max;
- double max;
- double position;
- sgMat4 matrix;
- sgVec3 center;
- sgVec3 axis;
- };
- SGPropertyNode_ptr _prop;
- TexTransform* _transform;
- int _num_transforms;
+ class Transform;
+ class Translation;
+ class Rotation;
+ class UpdateCallback;
+ void appendTexTranslate(const SGPropertyNode* config,
+ UpdateCallback* updateCallback);
+ void appendTexRotate(const SGPropertyNode* config,
+ UpdateCallback* updateCallback);
};
+\f
+//////////////////////////////////////////////////////////////////////
+// Shader animation
+//////////////////////////////////////////////////////////////////////
-/**
- * An animation to enable the alpha test
- */
-class SGAlphaTestAnimation : public SGAnimation
-{
+class SGShaderAnimation : public SGAnimation {
public:
- SGAlphaTestAnimation(SGPropertyNode_ptr props);
- virtual ~SGAlphaTestAnimation ();
- virtual void init();
+ SGShaderAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot,
+ const osgDB::ReaderWriter::Options* options);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
private:
- void setAlphaClampToBranch(ssgBranch *b, float clamp);
- bool _done;
- float _alpha_clamp;
+ class UpdateCallback;
+ osg::ref_ptr<osg::Texture2D> _effect_texture;
};
+\f
+//////////////////////////////////////////////////////////////////////
+// Pick animation
+//////////////////////////////////////////////////////////////////////
+
+class SGPickAnimation : public SGAnimation {
+public:
+ SGPickAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot);
+ virtual osg::Group* createAnimationGroup(osg::Group& parent);
+private:
+ class PickCallback;
+};
#endif // _SG_ANIMATION_HXX