-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatterns.cpp
More file actions
113 lines (88 loc) · 2.46 KB
/
Patterns.cpp
File metadata and controls
113 lines (88 loc) · 2.46 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "Patterns.h"
#include "RayCasting.h"
class Shape;
StripePattern::StripePattern(Color a, Color b) : a(a), b(b) {}
Color StripePattern::PatternAt(Entity point) {
float x_coord = floor(point.x);
if (int(x_coord) % 2 == 0)
return a;
else
return b;
}
Gradient::Gradient(Color a, Color b) : a(a), b(b) {}
Color Gradient::PatternAt(Entity point) {
return a + (b - a) * (point.x - floor(point.x));
}
RingPattern::RingPattern(Color a, Color b, int axes) : a(a), b(b) ,axes(axes) {}
Color RingPattern::PatternAt(Entity point) {
float exp = 0.0f;
switch (axes)
{
case 1:
exp = (pow(point.x, 2.0f) + pow(point.y, 2.0f));
break;
case 2:
exp = (pow(point.y, 2.0f) + pow(point.z, 2.0f));
break;
case 3:
exp = (pow(point.z, 2.0f) + pow(point.x, 2.0f));
break;
default:
std::cout << "Invalid axes" << std::endl;
break;
}
exp = sqrtf(exp);
if (int(floor(exp)) % 2 == 0)
return a;
else
return b;
}
CheckeredPattern::CheckeredPattern(Color a, Color b) : a(a), b(b) {}
Color CheckeredPattern::PatternAt(Entity point) {
float exp = floor(point.x) + floor(point.y) + floor(point.z);
if (int(exp) % 2 == 0)
return a;
else
return b;
}
RadialGradient::RadialGradient(Gradient grad, RingPattern ringPat) : grad(grad), ringPat(ringPat) {}
Color RadialGradient::PatternAt(Entity point) {
float exp = 0.0f;
switch (ringPat.axes)
{
case 1:
exp = (pow(point.x, 2.0f) + pow(point.y, 2.0f));
break;
case 2:
exp = (pow(point.y, 2.0f) + pow(point.z, 2.0f));
break;
case 3:
exp = (pow(point.z, 2.0f) + pow(point.x, 2.0f));
break;
default:
std::cout << "Invalid axes" << std::endl;
break;
}
exp = sqrtf(exp);
return grad.a + (grad.b - grad.a) * (exp - floor(exp));
}
CheckeredStrips::CheckeredStrips(StripePattern s1, StripePattern s2) : Stripes1(s1), Stripes2(s2) {}
Color CheckeredStrips::PatternAt(Entity point) {
float exp = floor(point.x) + floor(point.y) + floor(point.z);
point = Matrix_Entity_Multiply(transform, point);
if (int(exp) % 2 == 0) {
point = Matrix_Entity_Multiply(Invert_Matrix(Stripes1.transform), point);
return Stripes1.PatternAt(point);
}
else {
point = Matrix_Entity_Multiply(Invert_Matrix(Stripes2.transform), point);
return Stripes2.PatternAt(point);
}
}
Test_Pattern::Test_Pattern() {}
Color Test_Pattern::PatternAt(Entity point) {
return Color(point.x, point.y, point.z);
}
void SetPatternTransform(Patterns& pattern, std::vector<std::vector<float>> transformMat) {
pattern.transform = transformMat;
}