-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathline_effect.cpp~
More file actions
36 lines (31 loc) · 998 Bytes
/
line_effect.cpp~
File metadata and controls
36 lines (31 loc) · 998 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
#include <cmath>
#include "line_effect.hpp"
#include "color_utils.hpp"
LineEffect::LineEffect(const Point& p1, const Point& p2, const Color3 color)
: m_p1(p1), m_p2(p2), m_color(color)
{}
void LineEffect::fill(EffectBuffer& buffer, const EffectState& state)
{
float dx = float(m_p2.x-m_p1.x)/float(m_p2.y-m_p1.y);
float dy = float(m_p2.y-m_p1.y)/float(m_p2.x-m_p1.x);
float len = length(m_p2.x-m_p1.x, m_p2.y-m_p1.y);
float factor = std::fabs(m_rot - state.rotation.x) * 5.0f;
factor = factor * 0.82f + m_lastFactor * 0.1f;
if (factor > 20)
factor = m_lastFactor;
if (dx < dy) {
float x = m_p1.x;
for (int y=m_p1.y; y<=m_p2.y; y++) {
x += dx;
buffer.set(x, y, m_color * factor);
}
} else {
float y = m_p1.y;
for (int x=m_p1.x; x<=m_p2.x; x++) {
y += dy;
buffer.set(x, y, m_color * factor);
}
}
m_rot = state.rotation.x;
m_lastFactor = factor;
}