-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubdivisionCurve.cpp
45 lines (42 loc) · 1.15 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
#include "SubdivisionCurve.h"
#define GL_SILENCE_DEPRECATION
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
SubdivisionCurve::SubdivisionCurve(const Points3& points, uint level): points(points), level(level)
{
subdivide();
}
void SubdivisionCurve::subdivide()
{
for (uint i = 0; i < level; ++i) {
Points3 temp;
for (uint j = 0; j < points.size(); ++j) {
Point_3 a = points[j];
Point_3 b = points[(j + 1) % points.size()];
temp.emplace_back(
a.x() + (b.x() - a.x()) * 0.25,
a.y() + (b.y() - a.y()) * 0.25,
a.z() + (b.z() - a.z()) * 0.25
);
temp.emplace_back(
a.x() + (b.x() - a.x()) * 0.75,
a.y() + (b.y() - a.y()) * 0.75,
a.z() + (b.z() - a.z()) * 0.75
);
}
points = std::move(temp);
}
}
void SubdivisionCurve::drawSubdivisionCurve()
{
glLineWidth(2.0f);
glColor4f(0.5f, 1.0f, 0.0f, 1.0f);
glBegin(GL_LINE_LOOP);
for (uint i = 0; i < points.size(); ++i) {
glVertex3f(points[i].x(), points[i].y(), points[i].z());
}
glEnd();
}