1 // animation.cxx - classes to manage model animation.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain, and comes with no warranty.
7 #include <string.h> // for strcmp()
14 #include <simgear/math/interpolater.hxx>
15 #include <simgear/props/condition.hxx>
16 #include <simgear/props/props.hxx>
18 #include "animation.hxx"
22 ////////////////////////////////////////////////////////////////////////
23 // Static utility functions.
24 ////////////////////////////////////////////////////////////////////////
27 * Set up the transform matrix for a spin or rotation.
30 set_rotation (sgMat4 &matrix, double position_deg,
31 sgVec3 ¢er, sgVec3 &axis)
33 float temp_angle = -position_deg * SG_DEGREES_TO_RADIANS ;
35 float s = (float) sin ( temp_angle ) ;
36 float c = (float) cos ( temp_angle ) ;
37 float t = SG_ONE - c ;
39 // axis was normalized at load time
40 // hint to the compiler to put these into FP registers
45 matrix[0][0] = t * x * x + c ;
46 matrix[0][1] = t * y * x - s * z ;
47 matrix[0][2] = t * z * x + s * y ;
48 matrix[0][3] = SG_ZERO;
50 matrix[1][0] = t * x * y + s * z ;
51 matrix[1][1] = t * y * y + c ;
52 matrix[1][2] = t * z * y - s * x ;
53 matrix[1][3] = SG_ZERO;
55 matrix[2][0] = t * x * z - s * y ;
56 matrix[2][1] = t * y * z + s * x ;
57 matrix[2][2] = t * z * z + c ;
58 matrix[2][3] = SG_ZERO;
60 // hint to the compiler to put these into FP registers
65 matrix[3][0] = x - x*matrix[0][0] - y*matrix[1][0] - z*matrix[2][0];
66 matrix[3][1] = y - x*matrix[0][1] - y*matrix[1][1] - z*matrix[2][1];
67 matrix[3][2] = z - x*matrix[0][2] - y*matrix[1][2] - z*matrix[2][2];
68 matrix[3][3] = SG_ONE;
72 * Set up the transform matrix for a translation.
75 set_translation (sgMat4 &matrix, double position_m, sgVec3 &axis)
78 sgScaleVec3(xyz, axis, position_m);
79 sgMakeTransMat4(matrix, xyz);
83 * Set up the transform matrix for a scale operation.
86 set_scale (sgMat4 &matrix, double x, double y, double z)
88 sgMakeIdentMat4( matrix );
95 * Recursively process all kids to change the alpha values
98 change_alpha( ssgBase *_branch, float _blend )
102 for (i = 0; i < ((ssgBranch *)_branch)->getNumKids(); i++)
103 change_alpha( ((ssgBranch *)_branch)->getKid(i), _blend );
105 if ( !_branch->isAKindOf(ssgTypeLeaf())
106 && !_branch->isAKindOf(ssgTypeVtxTable())
107 && !_branch->isAKindOf(ssgTypeVTable()) )
110 int num_colors = ((ssgLeaf *)_branch)->getNumColours();
111 // unsigned int select_ = (_blend == 1.0) ? false : true;
113 for (i = 0; i < num_colors; i++)
115 // ((ssgSelector *)_branch)->select( select_ );
116 float *color = ((ssgLeaf *)_branch)->getColour(i);
122 * Modify property value by step and scroll settings in texture translations
125 apply_mods(double property, double step, double scroll)
130 double scrollval = 0.0;
132 // calculate scroll amount (for odometer like movement)
133 double remainder = step - fmod(fabs(property), step);
134 if (remainder < scroll) {
135 scrollval = (scroll - remainder) / scroll * step;
138 // apply stepping of input value
140 modprop = ((floor(property/step) * step) + scrollval);
142 modprop = ((ceil(property/step) * step) + scrollval);
151 * Read an interpolation table from properties.
153 static SGInterpTable *
154 read_interpolation_table (SGPropertyNode_ptr props)
156 SGPropertyNode_ptr table_node = props->getNode("interpolation");
157 if (table_node != 0) {
158 SGInterpTable * table = new SGInterpTable();
159 vector<SGPropertyNode_ptr> entries = table_node->getChildren("entry");
160 for (unsigned int i = 0; i < entries.size(); i++)
161 table->addEntry(entries[i]->getDoubleValue("ind", 0.0),
162 entries[i]->getDoubleValue("dep", 0.0));
171 ////////////////////////////////////////////////////////////////////////
172 // Implementation of SGAnimation
173 ////////////////////////////////////////////////////////////////////////
175 // Initialize the static data member
176 double SGAnimation::sim_time_sec = 0.0;
178 SGAnimation::SGAnimation (SGPropertyNode_ptr props, ssgBranch * branch)
181 _branch->setName(props->getStringValue("name", 0));
184 SGAnimation::~SGAnimation ()
194 SGAnimation::update()
200 ////////////////////////////////////////////////////////////////////////
201 // Implementation of SGNullAnimation
202 ////////////////////////////////////////////////////////////////////////
204 SGNullAnimation::SGNullAnimation (SGPropertyNode_ptr props)
205 : SGAnimation(props, new ssgBranch)
209 SGNullAnimation::~SGNullAnimation ()
215 ////////////////////////////////////////////////////////////////////////
216 // Implementation of SGRangeAnimation
217 ////////////////////////////////////////////////////////////////////////
219 SGRangeAnimation::SGRangeAnimation (SGPropertyNode *prop_root,
220 SGPropertyNode_ptr props)
221 : SGAnimation(props, new ssgRangeSelector),
222 _min(0.0), _max(0.0), _min_factor(1.0), _max_factor(1.0)
227 SGPropertyNode_ptr node = props->getChild( "min-factor" );
229 _min_factor = props->getFloatValue("min-factor", 1.0);
231 node = props->getChild( "max-factor" );
233 _max_factor = props->getFloatValue("max-factor", 1.0);
235 node = props->getChild( "min-property" );
237 _min_prop = (SGPropertyNode *)prop_root->getNode(node->getStringValue(), true);
238 ranges[0] = _min_prop->getFloatValue() * _min_factor;
240 _min = props->getFloatValue("min-m", 0);
241 ranges[0] = _min * _min_factor;
243 node = props->getChild( "max-property" );
245 _max_prop = (SGPropertyNode *)prop_root->getNode(node->getStringValue(), true);
246 ranges[1] = _max_prop->getFloatValue() * _max_factor;
248 _max = props->getFloatValue("max-m", 0);
249 ranges[1] = _max * _max_factor;
251 ((ssgRangeSelector *)_branch)->setRanges(ranges, 2);
254 SGRangeAnimation::~SGRangeAnimation ()
259 SGRangeAnimation::update()
263 if (_min_prop != 0) {
264 ranges[0] = _min_prop->getFloatValue() * _min_factor;
267 ranges[0] = _min * _min_factor;
269 if (_max_prop != 0) {
270 ranges[1] = _max_prop->getFloatValue() * _max_factor;
273 ranges[1] = _max * _max_factor;
276 ((ssgRangeSelector *)_branch)->setRanges(ranges, 2);
282 ////////////////////////////////////////////////////////////////////////
283 // Implementation of SGBillboardAnimation
284 ////////////////////////////////////////////////////////////////////////
286 SGBillboardAnimation::SGBillboardAnimation (SGPropertyNode_ptr props)
287 : SGAnimation(props, new ssgCutout(props->getBoolValue("spherical", true)))
291 SGBillboardAnimation::~SGBillboardAnimation ()
297 ////////////////////////////////////////////////////////////////////////
298 // Implementation of SGSelectAnimation
299 ////////////////////////////////////////////////////////////////////////
301 SGSelectAnimation::SGSelectAnimation( SGPropertyNode *prop_root,
302 SGPropertyNode_ptr props )
303 : SGAnimation(props, new ssgSelector),
306 SGPropertyNode_ptr node = props->getChild("condition");
308 _condition = sgReadCondition(prop_root, node);
311 SGSelectAnimation::~SGSelectAnimation ()
317 SGSelectAnimation::update()
319 if (_condition != 0 && _condition->test())
320 ((ssgSelector *)_branch)->select(0xffff);
322 ((ssgSelector *)_branch)->select(0x0000);
327 ////////////////////////////////////////////////////////////////////////
328 // Implementation of SGSpinAnimation
329 ////////////////////////////////////////////////////////////////////////
331 SGSpinAnimation::SGSpinAnimation( SGPropertyNode *prop_root,
332 SGPropertyNode_ptr props,
333 double sim_time_sec )
334 : SGAnimation(props, new ssgTransform),
335 _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
336 _factor(props->getDoubleValue("factor", 1.0)),
337 _position_deg(props->getDoubleValue("starting-position-deg", 0)),
338 _last_time_sec( sim_time_sec )
343 if (props->hasValue("axis/x1-m")) {
344 double x1,y1,z1,x2,y2,z2;
345 x1 = props->getFloatValue("axis/x1-m");
346 y1 = props->getFloatValue("axis/y1-m");
347 z1 = props->getFloatValue("axis/z1-m");
348 x2 = props->getFloatValue("axis/x2-m");
349 y2 = props->getFloatValue("axis/y2-m");
350 z2 = props->getFloatValue("axis/z2-m");
351 _center[0] = (x1+x2)/2;
352 _center[1]= (y1+y2)/2;
353 _center[2] = (z1+z2)/2;
354 float vector_length = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1));
355 _axis[0] = (x2-x1)/vector_length;
356 _axis[1] = (y2-y1)/vector_length;
357 _axis[2] = (z2-z1)/vector_length;
359 _axis[0] = props->getFloatValue("axis/x", 0);
360 _axis[1] = props->getFloatValue("axis/y", 0);
361 _axis[2] = props->getFloatValue("axis/z", 0);
363 if (props->hasValue("center/x-m")) {
364 _center[0] = props->getFloatValue("center/x-m", 0);
365 _center[1] = props->getFloatValue("center/y-m", 0);
366 _center[2] = props->getFloatValue("center/z-m", 0);
368 sgNormalizeVec3(_axis);
371 SGSpinAnimation::~SGSpinAnimation ()
376 SGSpinAnimation::update()
378 double dt = sim_time_sec - _last_time_sec;
379 _last_time_sec = sim_time_sec;
381 float velocity_rpms = (_prop->getDoubleValue() * _factor / 60.0);
382 _position_deg += (dt * velocity_rpms * 360);
383 while (_position_deg < 0)
384 _position_deg += 360.0;
385 while (_position_deg >= 360.0)
386 _position_deg -= 360.0;
387 set_rotation(_matrix, _position_deg, _center, _axis);
388 ((ssgTransform *)_branch)->setTransform(_matrix);
393 ////////////////////////////////////////////////////////////////////////
394 // Implementation of SGTimedAnimation
395 ////////////////////////////////////////////////////////////////////////
397 SGTimedAnimation::SGTimedAnimation (SGPropertyNode_ptr props)
398 : SGAnimation(props, new ssgSelector),
399 _duration_sec(props->getDoubleValue("duration-sec", 1.0)),
405 SGTimedAnimation::~SGTimedAnimation ()
410 SGTimedAnimation::update()
412 if ((sim_time_sec - _last_time_sec) >= _duration_sec) {
413 _last_time_sec = sim_time_sec;
415 if (_step >= getBranch()->getNumKids())
417 ((ssgSelector *)getBranch())->selectStep(_step);
423 ////////////////////////////////////////////////////////////////////////
424 // Implementation of SGRotateAnimation
425 ////////////////////////////////////////////////////////////////////////
427 SGRotateAnimation::SGRotateAnimation( SGPropertyNode *prop_root,
428 SGPropertyNode_ptr props )
429 : SGAnimation(props, new ssgTransform),
430 _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
431 _offset_deg(props->getDoubleValue("offset-deg", 0.0)),
432 _factor(props->getDoubleValue("factor", 1.0)),
433 _table(read_interpolation_table(props)),
434 _has_min(props->hasValue("min-deg")),
435 _min_deg(props->getDoubleValue("min-deg")),
436 _has_max(props->hasValue("max-deg")),
437 _max_deg(props->getDoubleValue("max-deg")),
438 _position_deg(props->getDoubleValue("starting-position-deg", 0))
443 if (props->hasValue("axis/x1-m")) {
444 double x1,y1,z1,x2,y2,z2;
445 x1 = props->getFloatValue("axis/x1-m");
446 y1 = props->getFloatValue("axis/y1-m");
447 z1 = props->getFloatValue("axis/z1-m");
448 x2 = props->getFloatValue("axis/x2-m");
449 y2 = props->getFloatValue("axis/y2-m");
450 z2 = props->getFloatValue("axis/z2-m");
451 _center[0] = (x1+x2)/2;
452 _center[1]= (y1+y2)/2;
453 _center[2] = (z1+z2)/2;
454 float vector_length = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1));
455 _axis[0] = (x2-x1)/vector_length;
456 _axis[1] = (y2-y1)/vector_length;
457 _axis[2] = (z2-z1)/vector_length;
459 _axis[0] = props->getFloatValue("axis/x", 0);
460 _axis[1] = props->getFloatValue("axis/y", 0);
461 _axis[2] = props->getFloatValue("axis/z", 0);
463 if (props->hasValue("center/x-m")) {
464 _center[0] = props->getFloatValue("center/x-m", 0);
465 _center[1] = props->getFloatValue("center/y-m", 0);
466 _center[2] = props->getFloatValue("center/z-m", 0);
468 sgNormalizeVec3(_axis);
471 SGRotateAnimation::~SGRotateAnimation ()
477 SGRotateAnimation::update()
480 _position_deg = _prop->getDoubleValue() * _factor + _offset_deg;
481 if (_has_min && _position_deg < _min_deg)
482 _position_deg = _min_deg;
483 if (_has_max && _position_deg > _max_deg)
484 _position_deg = _max_deg;
486 _position_deg = _table->interpolate(_prop->getDoubleValue());
488 set_rotation(_matrix, _position_deg, _center, _axis);
489 ((ssgTransform *)_branch)->setTransform(_matrix);
493 ////////////////////////////////////////////////////////////////////////
494 // Implementation of SGBlendAnimation
495 ////////////////////////////////////////////////////////////////////////
497 SGBlendAnimation::SGBlendAnimation( SGPropertyNode *prop_root,
498 SGPropertyNode_ptr props )
499 : SGAnimation(props, new ssgTransform),
500 _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
501 _table(read_interpolation_table(props)),
503 _offset(props->getDoubleValue("offset", 0.0)),
504 _factor(props->getDoubleValue("factor", 1.0)),
505 _has_min(props->hasValue("min")),
506 _min(props->getDoubleValue("min", 0.0)),
507 _has_max(props->hasValue("max")),
508 _max(props->getDoubleValue("max", 1.0))
512 SGBlendAnimation::~SGBlendAnimation ()
518 SGBlendAnimation::update()
523 _blend = 1.0 - (_prop->getDoubleValue() * _factor + _offset);
525 if (_has_min && (_blend < _min))
527 if (_has_max && (_blend > _max))
530 _blend = _table->interpolate(_prop->getDoubleValue());
533 if (_blend != _prev_value) {
534 _prev_value = _blend;
535 change_alpha( _branch, _blend );
541 ////////////////////////////////////////////////////////////////////////
542 // Implementation of SGTranslateAnimation
543 ////////////////////////////////////////////////////////////////////////
545 SGTranslateAnimation::SGTranslateAnimation( SGPropertyNode *prop_root,
546 SGPropertyNode_ptr props )
547 : SGAnimation(props, new ssgTransform),
548 _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
549 _offset_m(props->getDoubleValue("offset-m", 0.0)),
550 _factor(props->getDoubleValue("factor", 1.0)),
551 _table(read_interpolation_table(props)),
552 _has_min(props->hasValue("min-m")),
553 _min_m(props->getDoubleValue("min-m")),
554 _has_max(props->hasValue("max-m")),
555 _max_m(props->getDoubleValue("max-m")),
556 _position_m(props->getDoubleValue("starting-position-m", 0))
558 _axis[0] = props->getFloatValue("axis/x", 0);
559 _axis[1] = props->getFloatValue("axis/y", 0);
560 _axis[2] = props->getFloatValue("axis/z", 0);
561 sgNormalizeVec3(_axis);
564 SGTranslateAnimation::~SGTranslateAnimation ()
570 SGTranslateAnimation::update()
573 _position_m = (_prop->getDoubleValue() + _offset_m) * _factor;
574 if (_has_min && _position_m < _min_m)
575 _position_m = _min_m;
576 if (_has_max && _position_m > _max_m)
577 _position_m = _max_m;
579 _position_m = _table->interpolate(_prop->getDoubleValue());
581 set_translation(_matrix, _position_m, _axis);
582 ((ssgTransform *)_branch)->setTransform(_matrix);
587 ////////////////////////////////////////////////////////////////////////
588 // Implementation of SGScaleAnimation
589 ////////////////////////////////////////////////////////////////////////
591 SGScaleAnimation::SGScaleAnimation( SGPropertyNode *prop_root,
592 SGPropertyNode_ptr props )
593 : SGAnimation(props, new ssgTransform),
594 _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
595 _x_factor(props->getDoubleValue("x-factor", 1.0)),
596 _y_factor(props->getDoubleValue("y-factor", 1.0)),
597 _z_factor(props->getDoubleValue("z-factor", 1.0)),
598 _x_offset(props->getDoubleValue("x-offset", 1.0)),
599 _y_offset(props->getDoubleValue("y-offset", 1.0)),
600 _z_offset(props->getDoubleValue("z-offset", 1.0)),
601 _table(read_interpolation_table(props)),
602 _has_min_x(props->hasValue("x-min")),
603 _has_min_y(props->hasValue("y-min")),
604 _has_min_z(props->hasValue("z-min")),
605 _min_x(props->getDoubleValue("x-min")),
606 _min_y(props->getDoubleValue("y-min")),
607 _min_z(props->getDoubleValue("z-min")),
608 _has_max_x(props->hasValue("x-max")),
609 _has_max_y(props->hasValue("y-max")),
610 _has_max_z(props->hasValue("z-max")),
611 _max_x(props->getDoubleValue("x-max")),
612 _max_y(props->getDoubleValue("y-max")),
613 _max_z(props->getDoubleValue("z-max"))
617 SGScaleAnimation::~SGScaleAnimation ()
623 SGScaleAnimation::update()
626 _x_scale = _prop->getDoubleValue() * _x_factor + _x_offset;
627 if (_has_min_x && _x_scale < _min_x)
629 if (_has_max_x && _x_scale > _max_x)
632 _x_scale = _table->interpolate(_prop->getDoubleValue());
636 _y_scale = _prop->getDoubleValue() * _y_factor + _y_offset;
637 if (_has_min_y && _y_scale < _min_y)
639 if (_has_max_y && _y_scale > _max_y)
642 _y_scale = _table->interpolate(_prop->getDoubleValue());
646 _z_scale = _prop->getDoubleValue() * _z_factor + _z_offset;
647 if (_has_min_z && _z_scale < _min_z)
649 if (_has_max_z && _z_scale > _max_z)
652 _z_scale = _table->interpolate(_prop->getDoubleValue());
655 set_scale(_matrix, _x_scale, _y_scale, _z_scale );
656 ((ssgTransform *)_branch)->setTransform(_matrix);
660 ////////////////////////////////////////////////////////////////////////
661 // Implementation of SGTexRotateAnimation
662 ////////////////////////////////////////////////////////////////////////
664 SGTexRotateAnimation::SGTexRotateAnimation( SGPropertyNode *prop_root,
665 SGPropertyNode_ptr props )
666 : SGAnimation(props, new ssgTexTrans),
667 _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
668 _offset_deg(props->getDoubleValue("offset-deg", 0.0)),
669 _factor(props->getDoubleValue("factor", 1.0)),
670 _table(read_interpolation_table(props)),
671 _has_min(props->hasValue("min-deg")),
672 _min_deg(props->getDoubleValue("min-deg")),
673 _has_max(props->hasValue("max-deg")),
674 _max_deg(props->getDoubleValue("max-deg")),
675 _position_deg(props->getDoubleValue("starting-position-deg", 0))
677 _center[0] = props->getFloatValue("center/x", 0);
678 _center[1] = props->getFloatValue("center/y", 0);
679 _center[2] = props->getFloatValue("center/z", 0);
680 _axis[0] = props->getFloatValue("axis/x", 0);
681 _axis[1] = props->getFloatValue("axis/y", 0);
682 _axis[2] = props->getFloatValue("axis/z", 0);
683 sgNormalizeVec3(_axis);
686 SGTexRotateAnimation::~SGTexRotateAnimation ()
692 SGTexRotateAnimation::update()
695 _position_deg = _prop->getDoubleValue() * _factor + _offset_deg;
696 if (_has_min && _position_deg < _min_deg)
697 _position_deg = _min_deg;
698 if (_has_max && _position_deg > _max_deg)
699 _position_deg = _max_deg;
701 _position_deg = _table->interpolate(_prop->getDoubleValue());
703 set_rotation(_matrix, _position_deg, _center, _axis);
704 ((ssgTexTrans *)_branch)->setTransform(_matrix);
708 ////////////////////////////////////////////////////////////////////////
709 // Implementation of SGTexTranslateAnimation
710 ////////////////////////////////////////////////////////////////////////
712 SGTexTranslateAnimation::SGTexTranslateAnimation( SGPropertyNode *prop_root,
713 SGPropertyNode_ptr props )
714 : SGAnimation(props, new ssgTexTrans),
715 _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
716 _offset(props->getDoubleValue("offset", 0.0)),
717 _factor(props->getDoubleValue("factor", 1.0)),
718 _step(props->getDoubleValue("step",0.0)),
719 _scroll(props->getDoubleValue("scroll",0.0)),
720 _table(read_interpolation_table(props)),
721 _has_min(props->hasValue("min")),
722 _min(props->getDoubleValue("min")),
723 _has_max(props->hasValue("max")),
724 _max(props->getDoubleValue("max")),
725 _position(props->getDoubleValue("starting-position", 0))
727 _axis[0] = props->getFloatValue("axis/x", 0);
728 _axis[1] = props->getFloatValue("axis/y", 0);
729 _axis[2] = props->getFloatValue("axis/z", 0);
730 sgNormalizeVec3(_axis);
733 SGTexTranslateAnimation::~SGTexTranslateAnimation ()
739 SGTexTranslateAnimation::update()
742 _position = (apply_mods(_prop->getDoubleValue(), _step, _scroll) + _offset) * _factor;
743 if (_has_min && _position < _min)
745 if (_has_max && _position > _max)
748 _position = _table->interpolate(apply_mods(_prop->getDoubleValue(), _step, _scroll));
750 set_translation(_matrix, _position, _axis);
751 ((ssgTexTrans *)_branch)->setTransform(_matrix);
755 ////////////////////////////////////////////////////////////////////////
756 // Implementation of SGTexMultipleAnimation
757 ////////////////////////////////////////////////////////////////////////
759 SGTexMultipleAnimation::SGTexMultipleAnimation( SGPropertyNode *prop_root,
760 SGPropertyNode_ptr props )
761 : SGAnimation(props, new ssgTexTrans),
762 _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true))
766 vector<SGPropertyNode_ptr> transform_nodes = props->getChildren("transform");
767 _transform = new TexTransform [transform_nodes.size()];
769 for (i = 0; i < transform_nodes.size(); i++) {
770 SGPropertyNode_ptr transform_props = transform_nodes[i];
772 if (!strcmp("textranslate",transform_props->getStringValue("subtype", 0))) {
774 // transform is a translation
775 _transform[i].subtype = 0;
777 _transform[i].prop = (SGPropertyNode *)prop_root->getNode(transform_props->getStringValue("property", "/null"), true);
779 _transform[i].offset = transform_props->getDoubleValue("offset", 0.0);
780 _transform[i].factor = transform_props->getDoubleValue("factor", 1.0);
781 _transform[i].step = transform_props->getDoubleValue("step",0.0);
782 _transform[i].scroll = transform_props->getDoubleValue("scroll",0.0);
783 _transform[i].table = read_interpolation_table(transform_props);
784 _transform[i].has_min = transform_props->hasValue("min");
785 _transform[i].min = transform_props->getDoubleValue("min");
786 _transform[i].has_max = transform_props->hasValue("max");
787 _transform[i].max = transform_props->getDoubleValue("max");
788 _transform[i].position = transform_props->getDoubleValue("starting-position", 0);
790 _transform[i].axis[0] = transform_props->getFloatValue("axis/x", 0);
791 _transform[i].axis[1] = transform_props->getFloatValue("axis/y", 0);
792 _transform[i].axis[2] = transform_props->getFloatValue("axis/z", 0);
793 sgNormalizeVec3(_transform[i].axis);
795 } else if (!strcmp("texrotate",transform_nodes[i]->getStringValue("subtype", 0))) {
797 // transform is a rotation
798 _transform[i].subtype = 1;
800 _transform[i].prop = (SGPropertyNode *)prop_root->getNode(transform_props->getStringValue("property", "/null"), true);
801 _transform[i].offset = transform_props->getDoubleValue("offset-deg", 0.0);
802 _transform[i].factor = transform_props->getDoubleValue("factor", 1.0);
803 _transform[i].table = read_interpolation_table(transform_props);
804 _transform[i].has_min = transform_props->hasValue("min-deg");
805 _transform[i].min = transform_props->getDoubleValue("min-deg");
806 _transform[i].has_max = transform_props->hasValue("max-deg");
807 _transform[i].max = transform_props->getDoubleValue("max-deg");
808 _transform[i].position = transform_props->getDoubleValue("starting-position-deg", 0);
810 _transform[i].center[0] = transform_props->getFloatValue("center/x", 0);
811 _transform[i].center[1] = transform_props->getFloatValue("center/y", 0);
812 _transform[i].center[2] = transform_props->getFloatValue("center/z", 0);
813 _transform[i].axis[0] = transform_props->getFloatValue("axis/x", 0);
814 _transform[i].axis[1] = transform_props->getFloatValue("axis/y", 0);
815 _transform[i].axis[2] = transform_props->getFloatValue("axis/z", 0);
816 sgNormalizeVec3(_transform[i].axis);
822 SGTexMultipleAnimation::~SGTexMultipleAnimation ()
829 SGTexMultipleAnimation::update()
833 sgMakeIdentMat4(tmatrix);
834 for (i = 0; i < _num_transforms; i++) {
836 if(_transform[i].subtype == 0) {
838 // subtype 0 is translation
839 if (_transform[i].table == 0) {
840 _transform[i].position = (apply_mods(_transform[i].prop->getDoubleValue(), _transform[i].step,_transform[i].scroll) + _transform[i].offset) * _transform[i].factor;
841 if (_transform[i].has_min && _transform[i].position < _transform[i].min)
842 _transform[i].position = _transform[i].min;
843 if (_transform[i].has_max && _transform[i].position > _transform[i].max)
844 _transform[i].position = _transform[i].max;
846 _transform[i].position = _transform[i].table->interpolate(apply_mods(_transform[i].prop->getDoubleValue(), _transform[i].step,_transform[i].scroll));
848 set_translation(_transform[i].matrix, _transform[i].position, _transform[i].axis);
849 sgPreMultMat4(tmatrix, _transform[i].matrix);
851 } else if (_transform[i].subtype == 1) {
853 // subtype 1 is rotation
855 if (_transform[i].table == 0) {
856 _transform[i].position = _transform[i].prop->getDoubleValue() * _transform[i].factor + _transform[i].offset;
857 if (_transform[i].has_min && _transform[i].position < _transform[i].min)
858 _transform[i].position = _transform[i].min;
859 if (_transform[i].has_max && _transform[i].position > _transform[i].max)
860 _transform[i].position = _transform[i].max;
862 _transform[i].position = _transform[i].table->interpolate(_transform[i].prop->getDoubleValue());
864 set_rotation(_transform[i].matrix, _transform[i].position, _transform[i].center, _transform[i].axis);
865 sgPreMultMat4(tmatrix, _transform[i].matrix);
868 ((ssgTexTrans *)_branch)->setTransform(tmatrix);
873 ////////////////////////////////////////////////////////////////////////
874 // Implementation of SGAlphaTestAnimation
875 ////////////////////////////////////////////////////////////////////////
877 SGAlphaTestAnimation::SGAlphaTestAnimation(SGPropertyNode_ptr props)
878 : SGAnimation(props, new ssgBranch)
880 _alpha_clamp = props->getFloatValue("alpha-factor", 0.0);
883 SGAlphaTestAnimation::~SGAlphaTestAnimation ()
887 void SGAlphaTestAnimation::init()
889 setAlphaClampToBranch(_branch,_alpha_clamp);
892 void SGAlphaTestAnimation::setAlphaClampToBranch(ssgBranch *b, float clamp)
894 int nb = b->getNumKids();
895 for (int i = 0; i<nb; i++) {
896 ssgEntity *e = b->getKid(i);
897 if (e->isAKindOf(ssgTypeLeaf())) {
898 ssgSimpleState*s = (ssgSimpleState*)((ssgLeaf*)e)->getState();
899 s->enable( GL_ALPHA_TEST );
900 s->setAlphaClamp( clamp );
901 } else if (e->isAKindOf(ssgTypeBranch())) {
902 setAlphaClampToBranch( (ssgBranch*)e, clamp );
907 // end of animation.cxx