Destination_Connector.inl
Go to the documentation of this file.
1 namespace iv
2 {
3 
4 template< class T, class Interp >
6  AnimConnector( inst ),
7  cm( inst, this, "Destination_ConnectorGI" ),
8  _accumulated_distance( 0.0 ),
9  _parent( nullptr ),
10  _destination( destination )
11 {
12  this->cm.inherits( this->AnimConnector::cm );
13  this->SetParent( parent );
14 }
15 
16 template< class T, class Interp >
18 {
19  if( this->_parent )
20  this->_parent->anim_removeChild( this );
21 }
22 
23 template< class T, class Interp >
25 {
26  if( node )
27  {
28  if( this->_parent )
29  this->SetParent( nullptr );
30 
31  this->_parent = node;
32  this->_parent->anim_addChild( this );
33  this->Activate();
34  }
35  else
36  {
37  this->_parent->anim_removeChild( this );
38  this->_parent = nullptr;
39  this->Activate();
40  }
41 }
42 
43 template< class T, class Interp >
44 void Destination_ConnectorGI< T, Interp >::anim_eachParent( std::function< void( AnimNodeI * ) > const & f )
45 {
46  if( this->_parent )
47  f( this->_parent );
48 }
49 
50 template< class T, class Interp >
52 {
53  if( this->_parent == node )
54  {
55  this->_parent->anim_removeChild( this );
56  this->_parent = nullptr;
57  this->Activate();
58  }
59 }
60 
61 template< class T, class Interp >
63 {
64  this->_destination = destination;
65  this->Activate();
66 }
67 
68 template< class T, class Interp >
70 {
71  if( !this->_parent || !this->_destination )
72  {
73  this->_distance = 0.0;
74  return;
75  }
76 
77  // advance
78  Anim_float distance = this->_parent->Step() + this->_accumulated_distance;
79  T tgt = this->_parent->Target();
80  T current_value = this->_destination->Get();
81 
82  auto val_rem = Interp().Interpolate( current_value, tgt, distance );
83  this->_accumulated_distance = val_rem.second;
84 
85  // distance
86  auto dist = Interp().Distance( val_rem.first, tgt );
87  auto result = dist - this->_accumulated_distance;
88 
89  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_ConnectorUpdate, "UpdatePass_Down | step ", distance, ", value ", current_value, " -> ", val_rem.first, " -> ", tgt, ", accumulated_distance ", this->_accumulated_distance, "." );
90 
91  // apply
92  this->_destination->Modify( &this->cm, val_rem.first );
93  this->_distance = result;
94 }
95 
96 template< class T, class Interp >
98 {
99  if( !this->_parent || !this->_destination )
100  return;
101 
102  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_ConnectorUpdate, "UpdatePass_Up | distance ", this->_distance, "." );
103 
104  this->_parent->Connector_UpdateDistance( this->_distance );
105 }
106 
107 }