I made a function which creates Bezier curves of grade n. What do you think?
float interpolate(float n1, float n2, float prec)
{
return n1 + ((n2-n1) * prec);
}
std::vector<Vector2f> make_bezier(const std::vector<Vector2f>& anchors, double accuracy=10000.0)
{
if(anchors.size()<=2)
return anchors;
std::vector<Vector2f> end;
end.push_back(anchors[0]);
for(float i=0.f; i<1.f; i+=1.f/accuracy)
{
std::vector<Vector2f> temp;
for(unsigned int j=1; j<anchors.size(); ++j)
temp.push_back(Vector2f(interpolate(anchors[j-1].x, anchors[j].x, i),
interpolate(anchors[j-1].y, anchors[j].y, i)));
while(temp.size()>1)
{
std::vector<Vector2f> temp2;
for(unsigned int j=1; j<temp.size(); ++j)
temp2.push_back(Vector2f(interpolate(temp[j-1].x, temp[j].x, i),
interpolate(temp[j-1].y, temp[j].y, i)));
temp = temp2;
}
end.push_back(temp[0]);
}
return end;
}