From 6dc243e1afc738e947a1f1539fa7d50ad8ffba3d Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 25 Jul 2003 14:48:02 +0000 Subject: [PATCH] Actually commit the code changes which impliment a "scale" animation type. --- simgear/scene/model/animation.cxx | 86 +++++++++++++++++++++++++++++++ simgear/scene/model/animation.hxx | 37 +++++++++++++ simgear/scene/model/model.cxx | 2 + 3 files changed, 125 insertions(+) diff --git a/simgear/scene/model/animation.cxx b/simgear/scene/model/animation.cxx index f3a1b708..517e8f56 100644 --- a/simgear/scene/model/animation.cxx +++ b/simgear/scene/model/animation.cxx @@ -79,6 +79,18 @@ set_translation (sgMat4 &matrix, double position_m, sgVec3 &axis) sgMakeTransMat4(matrix, xyz); } +/** + * Set up the transform matrix for a scale operation. + */ +static void +set_scale (sgMat4 &matrix, double x, double y, double z) +{ + sgMakeIdentMat4( matrix ); + matrix[0][0] = x; + matrix[1][1] = y; + matrix[2][2] = z; +} + /** * Modify property value by step and scroll settings in texture translations */ @@ -449,6 +461,80 @@ SGTranslateAnimation::update() } + +//////////////////////////////////////////////////////////////////////// +// Implementation of SGScaleAnimation +//////////////////////////////////////////////////////////////////////// + +SGScaleAnimation::SGScaleAnimation( SGPropertyNode *prop_root, + SGPropertyNode_ptr props ) + : SGAnimation(props, new ssgTransform), + _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)), + _x_factor(props->getDoubleValue("x-factor", 1.0)), + _y_factor(props->getDoubleValue("y-factor", 1.0)), + _z_factor(props->getDoubleValue("z-factor", 1.0)), + _x_offset(props->getDoubleValue("x-offset", 1.0)), + _y_offset(props->getDoubleValue("y-offset", 1.0)), + _z_offset(props->getDoubleValue("z-offset", 1.0)), + _table(read_interpolation_table(props)), + _has_min_x(props->hasValue("x-min")), + _has_min_y(props->hasValue("y-min")), + _has_min_z(props->hasValue("z-min")), + _min_x(props->getDoubleValue("x-min")), + _min_y(props->getDoubleValue("y-min")), + _min_z(props->getDoubleValue("z-min")), + _has_max_x(props->hasValue("x-max")), + _has_max_y(props->hasValue("y-max")), + _has_max_z(props->hasValue("z-max")), + _max_x(props->getDoubleValue("x-max")), + _max_y(props->getDoubleValue("y-max")), + _max_z(props->getDoubleValue("z-max")) +{ +} + +SGScaleAnimation::~SGScaleAnimation () +{ + delete _table; +} + +void +SGScaleAnimation::update() +{ + if (_table == 0) { + _x_scale = _prop->getDoubleValue() * _x_factor + _x_offset; + if (_has_min_x && _x_scale < _min_x) + _x_scale = _min_x; + if (_has_max_x && _x_scale > _max_x) + _x_scale = _max_x; + } else { + _x_scale = _table->interpolate(_prop->getDoubleValue()); + } + + if (_table == 0) { + _y_scale = _prop->getDoubleValue() * _y_factor + _y_offset; + if (_has_min_y && _y_scale < _min_y) + _y_scale = _min_y; + if (_has_max_y && _y_scale > _max_y) + _y_scale = _max_y; + } else { + _y_scale = _table->interpolate(_prop->getDoubleValue()); + } + + if (_table == 0) { + _z_scale = _prop->getDoubleValue() * _z_factor + _z_offset; + if (_has_min_z && _z_scale < _min_z) + _z_scale = _min_z; + if (_has_max_z && _z_scale > _max_z) + _z_scale = _max_z; + } else { + _z_scale = _table->interpolate(_prop->getDoubleValue()); + } + + set_scale(_matrix, _x_scale, _y_scale, _z_scale ); + ((ssgTransform *)_branch)->setTransform(_matrix); +} + + //////////////////////////////////////////////////////////////////////// // Implementation of SGTexRotateAnimation //////////////////////////////////////////////////////////////////////// diff --git a/simgear/scene/model/animation.hxx b/simgear/scene/model/animation.hxx index 9259401b..0e61500c 100644 --- a/simgear/scene/model/animation.hxx +++ b/simgear/scene/model/animation.hxx @@ -221,6 +221,43 @@ private: sgVec3 _axis; }; +/** + * Animation to scale an object. + */ +class SGScaleAnimation : 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; +}; + /** * Animation to rotate texture mappings around a center point. * diff --git a/simgear/scene/model/model.cxx b/simgear/scene/model/model.cxx index 528ad116..853e41be 100644 --- a/simgear/scene/model/model.cxx +++ b/simgear/scene/model/model.cxx @@ -121,6 +121,8 @@ sgMakeAnimation( ssgBranch * model, animation = new SGRotateAnimation(prop_root, node); } else if (!strcmp("translate", type)) { animation = new SGTranslateAnimation(prop_root, node); + } else if (!strcmp("scale", type)) { + animation = new SGScaleAnimation(prop_root, node); } else if (!strcmp("texrotate", type)) { animation = new SGTexRotateAnimation(prop_root, node); } else if (!strcmp("textranslate", type)) { -- 2.39.5