-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGP_Stroke.cpp
More file actions
42 lines (37 loc) · 1022 Bytes
/
GP_Stroke.cpp
File metadata and controls
42 lines (37 loc) · 1022 Bytes
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
#include "GP_Stroke.hpp"
void Stroke::clear() {
points.clear();
new_points = 0;
dirty = false;
}
void Stroke::submit_point(Vector2f const &new_point) {
points.push_back(new_point);
++new_points;
//TODO: 'new point' hook?
}
void SmoothStroke::clear() {
smoothing_queue.clear();
Stroke::clear();
}
void SmoothStroke::submit_point(Vector2f const &new_point) {
//chop stroke, add points:
if (points.empty() && smoothing_queue.empty()) {
//no stroke yet, so dump starting point in:
smoothing_queue.push_back(new_point);
last = new_point;
along = 0.0f;
}
while (along + length(new_point - last) > Step) {
last += normalize(new_point - last) * (Step - along);
smoothing_queue.push_back(last);
along = 0.0f;
if (smoothing_queue.size() == smoothing_kernel.size()) {
Vector2f p = make_vector( 0.0f, 0.0f );
for (unsigned int i = 0; i < smoothing_kernel.size(); ++i) {
p += smoothing_kernel[i] * smoothing_queue[i];
}
Stroke::submit_point(p);
smoothing_queue.pop_front();
}
}
}