-SGTexRotateAnimation::SGTexRotateAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props )
- : SGAnimation(props, new osg::Group),
- _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
- _offset_deg(props->getDoubleValue("offset-deg", 0.0)),
- _factor(props->getDoubleValue("factor", 1.0)),
- _table(read_interpolation_table(props)),
- _has_min(props->hasValue("min-deg")),
- _min_deg(props->getDoubleValue("min-deg")),
- _has_max(props->hasValue("max-deg")),
- _max_deg(props->getDoubleValue("max-deg")),
- _position_deg(props->getDoubleValue("starting-position-deg", 0)),
- _condition(0)
-{
- SGPropertyNode *node = props->getChild("condition");
- if (node != 0)
- _condition = sgReadCondition(prop_root, node);
-
- _center[0] = props->getFloatValue("center/x", 0);
- _center[1] = props->getFloatValue("center/y", 0);
- _center[2] = props->getFloatValue("center/z", 0);
- _axis[0] = props->getFloatValue("axis/x", 0);
- _axis[1] = props->getFloatValue("axis/y", 0);
- _axis[2] = props->getFloatValue("axis/z", 0);
- _axis.normalize();
-
- osg::StateSet* stateSet = _branch->getOrCreateStateSet();
- _texMat = new osg::TexMat;
- stateSet->setTextureAttribute(0, _texMat.get());
-}
-
-SGTexRotateAnimation::~SGTexRotateAnimation ()
-{
- delete _table;
-}
-
-int
-SGTexRotateAnimation::update()
-{
- if (_condition && !_condition->test())
- return 1;
-
- if (_table == 0) {
- _position_deg = _prop->getDoubleValue() * _factor + _offset_deg;
- if (_has_min && _position_deg < _min_deg)
- _position_deg = _min_deg;
- if (_has_max && _position_deg > _max_deg)
- _position_deg = _max_deg;
- } else {
- _position_deg = _table->interpolate(_prop->getDoubleValue());
- }
- osg::Matrix _matrix;
- set_rotation(_matrix, _position_deg, _center, _axis);
- _texMat->setMatrix(_matrix);
- return 2;
-}
-
-
-////////////////////////////////////////////////////////////////////////
-// Implementation of SGTexTranslateAnimation
-////////////////////////////////////////////////////////////////////////
-
-SGTexTranslateAnimation::SGTexTranslateAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props )
- : SGAnimation(props, new osg::Group),
- _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
- _offset(props->getDoubleValue("offset", 0.0)),
- _factor(props->getDoubleValue("factor", 1.0)),
- _step(props->getDoubleValue("step",0.0)),
- _scroll(props->getDoubleValue("scroll",0.0)),
- _table(read_interpolation_table(props)),
- _has_min(props->hasValue("min")),
- _min(props->getDoubleValue("min")),
- _has_max(props->hasValue("max")),
- _max(props->getDoubleValue("max")),
- _position(props->getDoubleValue("starting-position", 0)),
- _condition(0)
-{
- SGPropertyNode *node = props->getChild("condition");
- if (node != 0)
- _condition = sgReadCondition(prop_root, node);
-
- _axis[0] = props->getFloatValue("axis/x", 0);
- _axis[1] = props->getFloatValue("axis/y", 0);
- _axis[2] = props->getFloatValue("axis/z", 0);
- _axis.normalize();
-
- osg::StateSet* stateSet = _branch->getOrCreateStateSet();
- _texMat = new osg::TexMat;
- stateSet->setTextureAttribute(0, _texMat.get());
-}
-
-SGTexTranslateAnimation::~SGTexTranslateAnimation ()
-{
- delete _table;
-}
-
-int
-SGTexTranslateAnimation::update()
-{
- if (_condition && !_condition->test())
- return 1;
-
- if (_table == 0) {
- _position = (apply_mods(_prop->getDoubleValue(), _step, _scroll) + _offset) * _factor;
- if (_has_min && _position < _min)
- _position = _min;
- if (_has_max && _position > _max)
- _position = _max;
- } else {
- _position = _table->interpolate(apply_mods(_prop->getDoubleValue(), _step, _scroll));
- }
- osg::Matrix _matrix;
- set_translation(_matrix, _position, _axis);
- _texMat->setMatrix(_matrix);
- return 2;
-}
-
-
-////////////////////////////////////////////////////////////////////////
-// Implementation of SGTexMultipleAnimation
-////////////////////////////////////////////////////////////////////////
-
-SGTexMultipleAnimation::SGTexMultipleAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props )
- : SGAnimation(props, new osg::Group),
- _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true))
-{
- unsigned int i;
- // Load animations
- vector<SGPropertyNode_ptr> transform_nodes = props->getChildren("transform");
- _transform = new TexTransform [transform_nodes.size()];
- _num_transforms = 0;
- for (i = 0; i < transform_nodes.size(); i++) {
- SGPropertyNode_ptr transform_props = transform_nodes[i];
-
- if (!strcmp("textranslate",transform_props->getStringValue("subtype", 0))) {
-
- // transform is a translation
- _transform[i].subtype = 0;
-
- _transform[i].prop = (SGPropertyNode *)prop_root->getNode(transform_props->getStringValue("property", "/null"), true);
-
- _transform[i].offset = transform_props->getDoubleValue("offset", 0.0);
- _transform[i].factor = transform_props->getDoubleValue("factor", 1.0);
- _transform[i].step = transform_props->getDoubleValue("step",0.0);
- _transform[i].scroll = transform_props->getDoubleValue("scroll",0.0);
- _transform[i].table = read_interpolation_table(transform_props);
- _transform[i].has_min = transform_props->hasValue("min");
- _transform[i].min = transform_props->getDoubleValue("min");
- _transform[i].has_max = transform_props->hasValue("max");
- _transform[i].max = transform_props->getDoubleValue("max");
- _transform[i].position = transform_props->getDoubleValue("starting-position", 0);
-
- _transform[i].axis[0] = transform_props->getFloatValue("axis/x", 0);
- _transform[i].axis[1] = transform_props->getFloatValue("axis/y", 0);
- _transform[i].axis[2] = transform_props->getFloatValue("axis/z", 0);
- _transform[i].axis.normalize();
- _num_transforms++;
- } else if (!strcmp("texrotate",transform_nodes[i]->getStringValue("subtype", 0))) {
-
- // transform is a rotation
- _transform[i].subtype = 1;
-
- _transform[i].prop = (SGPropertyNode *)prop_root->getNode(transform_props->getStringValue("property", "/null"), true);
- _transform[i].offset = transform_props->getDoubleValue("offset-deg", 0.0);
- _transform[i].factor = transform_props->getDoubleValue("factor", 1.0);
- _transform[i].table = read_interpolation_table(transform_props);
- _transform[i].has_min = transform_props->hasValue("min-deg");
- _transform[i].min = transform_props->getDoubleValue("min-deg");
- _transform[i].has_max = transform_props->hasValue("max-deg");
- _transform[i].max = transform_props->getDoubleValue("max-deg");
- _transform[i].position = transform_props->getDoubleValue("starting-position-deg", 0);
-
- _transform[i].center[0] = transform_props->getFloatValue("center/x", 0);
- _transform[i].center[1] = transform_props->getFloatValue("center/y", 0);
- _transform[i].center[2] = transform_props->getFloatValue("center/z", 0);
- _transform[i].axis[0] = transform_props->getFloatValue("axis/x", 0);
- _transform[i].axis[1] = transform_props->getFloatValue("axis/y", 0);
- _transform[i].axis[2] = transform_props->getFloatValue("axis/z", 0);
- _transform[i].axis.normalize();
- _num_transforms++;
- }
- }
- osg::StateSet* stateSet = _branch->getOrCreateStateSet();
- _texMat = new osg::TexMat;
- stateSet->setTextureAttribute(0, _texMat.get());
-}
-
-SGTexMultipleAnimation::~SGTexMultipleAnimation ()
-{
- delete [] _transform;
-}
-
-int
-SGTexMultipleAnimation::update()