-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.pde
More file actions
145 lines (118 loc) · 2.97 KB
/
Matrix.pde
File metadata and controls
145 lines (118 loc) · 2.97 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
class Matrix {
public static final int KEYS_COUNT = 16;
public static final int LEFT_RIGHT_UP_DOWN = 0; // default
public static final int LEFT_RIGHT_DOWN_UP = 1;
public static final int UP_DOWN_LEFT_RIGHT = 2;
public static final int DOWN_UP_LEFT_RIGHT = 3;
private int offset2dX;
private int offset2dY;
private boolean projection3d;
private int offset3dX;
private int offset3dY;
private int rotation3dX;
private int rotation3dY;
private int rotation3dZ;
private Key[] keys;
// Constructor
Matrix(int disposition, color colorFill, String prefix,
int offset2dX, int offset2dY, int offset3dX, int offset3dY,
int rotation3dX, int rotation3dY, int rotation3dZ) {
// set matrix variables
this.offset2dX = offset2dX;
this.offset2dY = offset2dY;
projection3d = false;
this.offset3dX = offset3dX;
this.offset3dY = offset3dY;
this.rotation3dX = rotation3dX;
this.rotation3dY = rotation3dY;
this.rotation3dZ = rotation3dZ;
// init keys
keys = new Key[16];
int spacing = 40;
int offsetCenter = 60;
int x3D, y3D;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
switch (disposition) {
case LEFT_RIGHT_DOWN_UP:
x3D = i * spacing;
y3D = (3-j) * spacing;
break;
case UP_DOWN_LEFT_RIGHT:
x3D = j * spacing;
y3D = (3-i) * spacing;
break;
case DOWN_UP_LEFT_RIGHT:
x3D = j * spacing;
y3D = i * spacing;
break;
case LEFT_RIGHT_UP_DOWN:
default:
x3D = i * spacing;
y3D = j * spacing;
break;
}
x3D -= offsetCenter;
y3D -= offsetCenter;
keys[j * 4 + i] = new Key(
i * spacing - offsetCenter,
j * spacing - offsetCenter,
x3D,
y3D,
offset2dX,
offset2dY,
colorFill,
prefix + (j * 4 + i + 1)
);
}
}
}
// Draw
public void draw() {
pushMatrix();
if (projection3d) {
translate(offset3dX, offset3dY, 100);
rotateX(radians(rotation3dX));
rotateY(radians(rotation3dY));
rotateZ(radians(rotation3dZ));
} else {
translate(offset2dX, offset2dY, 100);
}
for (int i = 0; i < KEYS_COUNT; i++) {
keys[i].draw();
}
popMatrix();
}
public void clean() {
for (int i = 0; i < KEYS_COUNT; i++) {
keys[i].setPress(false);
}
}
/*
** Get
*/
public Key[] getKeys() {
return keys;
}
/*
** Set
*/
public void setProjection3d(boolean b) {
projection3d = b;
for (int i = 0; i < KEYS_COUNT; i++) {
keys[i].setProjection3d(projection3d);
}
}
/*
** Event
*/
public Key onMove(float relativeMouseX, float relativeMouseY) {
Key k = null;
for (int i = 0; i < KEYS_COUNT; i++) {
if (keys[i].onMove(relativeMouseX, relativeMouseY)) {
k = keys[i];
}
}
return k;
}
}