71
71
TexCoordDamper2D::TexCoordDamper2D (X3DExecutionContext* const executionContext) :
72
72
X3DBaseNode (executionContext -> getBrowser (), executionContext),
76
77
addField (inputOutput, "metadata", metadata ());
77
78
addField (inputOnly, "set_value", set_value ());
95
96
TexCoordDamper2D::initialize ()
97
98
X3DDamperNode::initialize ();
100
set_value () .addInterest (this, &TexCoordDamper2D::_set_value);
101
set_destination () .addInterest (this, &TexCoordDamper2D::_set_destination);
102
order () .addInterest (this, &TexCoordDamper2D::set_order);
104
value .resize (getOrder () + 1);
106
for (auto & v : basic::adapter (value .begin () + 1, value .end ()))
108
v .assign (initialValue () .begin (), initialValue () .end ());
109
v .resize (initialDestination () .size ());
112
value [0] .assign (initialDestination () .begin (), initialDestination () .end ());
114
set_active (not equals (initialDestination (), initialValue (), getTolerance ()));
118
TexCoordDamper2D::_set_value ()
120
for (auto & v : basic::adapter (value .begin () + 1, value .end ()))
121
v .assign (set_value () .begin (), set_value () .end ());
123
value [0] .resize (set_value () .size ());
125
value_changed () = set_value ();
101
131
TexCoordDamper2D::_set_destination ()
105
TexCoordDamper2D::_set_value ()
133
if (not equals (value [0], set_destination (), getTolerance ()))
135
for (auto & v : basic::adapter (value .begin () + 1, value .end ()))
136
v .resize (set_destination () .size ());
138
value [0] .assign (set_destination () .begin (), set_destination () .end ());
109
145
TexCoordDamper2D::set_order ()
147
value .resize (getOrder () + 1, value .back ());
113
151
TexCoordDamper2D::prepareEvents ()
153
size_t order = value .size () - 1;
157
time_type delta = 1 / getBrowser () -> getCurrentFrameRate ();
159
float alpha = std::exp (-delta / tau ());
161
for (size_t i = 0; i < order; ++ i)
163
for (size_t j = 0, s = value [i] .size (); j < s; ++ j)
165
value [i + 1] [j] = lerp (value [i] [j], value [i + 1] [j], alpha);
169
value_changed () .assign (value [order] .begin (), value [order] .end ());
171
if (not equals (value [order], value [0], getTolerance ()))
176
value_changed () .assign (value [0] .begin (), value [0] .end ());
181
for (auto & v : basic::adapter (value .begin () + 1, value .end ()))