Interpolation of Targets
-
Each target has a weight of value 0 to 1
-
Set position of each vertex with interpolation function. Do this each frame
of rendering.
-
If using shaders, put this function in vertex shader.
-
For smooth animations, remember to multiply change in each weight by elapsed time
// assume we have set weights for happy and sad faces and have meshes
// work out how much of "neutral" pose to show
float w_neutral = 1.0 - w_happy - w_sad;
clamp (w_neutral, 0.0, 1.0);
// get each weight as a factor of total of weights
float w_sum = w_happy + w_sad + w_neutral;
float happy_factor = w_happy / w_sum;
float sad_factor = w_sad / w_sum;
float neutral_factor = w_neutral / w_sum;
// work out final position by doing weighted average of each target
vec3 mixed_xyz = mix (default_pos, happy_pos, happy_factor);
mixed_xyz = mix (mixed_xyz, sad_pos, sad_factor);