Bezier interpolation

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent 84a594e670
commit 8f9e657d14
6 changed files with 46 additions and 16 deletions
+18 -6
View File
@@ -3,22 +3,34 @@
using namespace std;
namespace vb01{
float KeyframeChannel::interpolate(float pastValue, float nextValue, Keyframe::Interpolation mode, float ratio){
float KeyframeChannel::interpolate(Keyframe pastKeyframe, Keyframe nextKeyframe, float ratio){
float currentValue;
switch(mode){
switch(pastKeyframe.interpolation){
case Keyframe::CONSTANT:
currentValue = pastValue;
currentValue = pastKeyframe.value;
break;
case Keyframe::LINEAR:
currentValue = pastValue + (nextValue - pastValue) * ratio;
break;
case Keyframe::BEZIER:
currentValue = pastValue + (nextValue - pastValue) * ratio;
vector<float> points = vector<float>({pastKeyframe.value, pastKeyframe.rightHandleValue, nextKeyframe.leftHandleValue, nextKeyframe.value});
currentValue = interpolateBezier(points, ratio);
break;
}
return currentValue;
}
float KeyframeChannel::interpolateBezier(vector<float> points, float ratio){
int numPoints = points.size();
vector<float> newPoints;
for(int i = 0; i < numPoints - 1; i++)
newPoints.push_back(points[i] + (points[i + 1] - points[i]) * ratio);
if(newPoints.size() >= 2)
return interpolateBezier(newPoints, ratio);
else
return newPoints[0];
}
KeyframeChannelType KeyframeChannel::getKeyframeChannelType(string typeString){
KeyframeChannelType type;
if(typeString == "pos_x")