10 #if (defined(type) && defined(zeroValue) && defined(add) && defined(subtract) && defined(multiply) && defined(bezier3)) || defined(DOXYGEN)
15 typedef struct _VuoSmoothInertia
18 bool updateNeededAfterSetPosition;
19 type positionLastFrame;
22 type positionWhenTargetChanged;
23 type velocityWhenTargetChanged;
36 s->positionLastFrame = initialPosition;
45 s->positionLastFrame = position;
47 s->velocity = zeroValue;
48 s->updateNeededAfterSetPosition =
true;
57 s->positionWhenTargetChanged = s->positionLastFrame;
58 s->velocityWhenTargetChanged = s->velocity;
59 s->timeWhenTargetChanged = time;
68 s->duration =
MAX(duration, 0.00001);
80 bool movedDuringThisStep =
false;
82 if (s->updateNeededAfterSetPosition)
84 movedDuringThisStep =
true;
85 *calculatedPosition = s->positionLastFrame;
86 s->updateNeededAfterSetPosition =
false;
91 movedDuringThisStep =
true;
92 VuoReal timeSinceLastFrame = time - s->timeLastFrame;
93 if (timeSinceLastFrame != 0)
95 double timeSinceTargetChanged =
MIN(time - s->timeWhenTargetChanged, s->duration);
96 double curviness = s->duration/(3.*timeSinceLastFrame);
97 type p1 =
add(s->positionWhenTargetChanged, multiply(s->velocityWhenTargetChanged, timeSinceLastFrame*curviness));
98 *calculatedPosition = bezier3(s->positionWhenTargetChanged, p1, s->target, s->target, timeSinceTargetChanged/s->duration);
100 s->velocity = multiply(subtract(*calculatedPosition, s->positionLastFrame), 1./timeSinceLastFrame);
101 s->positionLastFrame = *calculatedPosition;
103 if (time - s->timeWhenTargetChanged > s->duration)
106 s->velocity = zeroValue;
111 s->timeLastFrame = time;
113 return movedDuringThisStep;