-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubdivisioncurve.cpp
61 lines (48 loc) · 1.4 KB
/
subdivisioncurve.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "subdivisioncurve.h"
#include "vec.h"
void SubdivisionCurveEvaluator::evaluateCurve(const std::vector<Point>& ptvCtrlPts,
std::vector<Point>& ptvEvaluatedCurvePts,
const float& fAniLength,
const bool& bWrap,
const bool& bAdaptive,
const double& dTension) const {
vector<Point> curve;
curve.assign(ptvCtrlPts.begin(), ptvCtrlPts.end());
if (bWrap)
{
curve.insert(curve.begin(), Point(0, 0));
curve.push_back(Point(fAniLength, 0));
}
for(int k=0;k<10;++k)
{
if (curve.size() == 2)
break;
//chaikiin's algorithm: split -> average
vector<Point> split;
split.push_back(curve[0]);
for (int i = 0; i < curve.size() - 1; i++)
{
float midx = (curve[i].x + curve[i + 1].x) / 2;
float midy = (curve[i].y + curve[i + 1].y) / 2;
split.push_back(Point(midx,midy));
split.push_back(curve[i + 1]);
}
vector<Point> avg;
avg.push_back(split[0]);
for (int i = 0; i < split.size() - 1; i++)
{
float x = split[i].x + (split[i + 1].x - split[i].x) * Mask;
float y = split[i].y + (split[i + 1].y - split[i].y) * Mask;
avg.push_back(Point(x, y));
}
split.push_back(split.back());
curve = avg;
}
ptvEvaluatedCurvePts.clear();
ptvEvaluatedCurvePts.assign(curve.begin(), curve.end());
if (!bWrap)
{
ptvEvaluatedCurvePts.insert(ptvEvaluatedCurvePts.begin(), Point(0, curve[0].y));
ptvEvaluatedCurvePts.push_back(Point(fAniLength, curve.back().y));
}
}