forked from maticstric/WebGL-Breakout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cube.js
65 lines (56 loc) · 2.66 KB
/
Cube.js
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
class Cube extends Model{
constructor(color) {
super(color);
if (color == null) {
color = [1, 1, 1, 1];
}
this.vertices = this.initVertices(color);
}
initVertices(color) {
var vertices = [
// Front of the cube
-1,-1, 1, 0,0, color[0],color[1],color[2],color[3], 0,0,1,
-1, 1, 1, 0,1, color[0],color[1],color[2],color[3], 0,0,1,
1, 1, 1, 1,1, color[0],color[1],color[2],color[3], 0,0,1,
-1,-1, 1, 0,0, color[0],color[1],color[2],color[3], 0,0,1,
1, 1, 1, 1,1, color[0],color[1],color[2],color[3], 0,0,1,
1,-1, 1, 1,0, color[0],color[1],color[2],color[3], 0,0,1,
// Top of the cube
-1, 1,-1, 0,0, color[0],color[1],color[2],color[3], 0,1,0,
-1, 1, 1, 0,1, color[0],color[1],color[2],color[3], 0,1,0,
1, 1, 1, 1,1, color[0],color[1],color[2],color[3], 0,1,0,
-1, 1,-1, 0,0, color[0],color[1],color[2],color[3], 0,1,0,
1, 1, 1, 1,1, color[0],color[1],color[2],color[3], 0,1,0,
1, 1,-1, 1,0, color[0],color[1],color[2],color[3], 0,1,0,
// Right of the cube
1,-1,-1, 0,0, color[0],color[1],color[2],color[3], 1,0,0,
1, 1,-1, 0,1, color[0],color[1],color[2],color[3], 1,0,0,
1, 1, 1, 1,1, color[0],color[1],color[2],color[3], 1,0,0,
1,-1,-1, 0,0, color[0],color[1],color[2],color[3], 1,0,0,
1, 1, 1, 1,1, color[0],color[1],color[2],color[3], 1,0,0,
1,-1, 1, 1,0, color[0],color[1],color[2],color[3], 1,0,0,
// Left of the cube
-1,-1,-1, 0,0, color[0],color[1],color[2],color[3], -1,0,0,
-1, 1,-1, 0,1, color[0],color[1],color[2],color[3], -1,0,0,
-1, 1, 1, 1,1, color[0],color[1],color[2],color[3], -1,0,0,
-1,-1,-1, 0,0, color[0],color[1],color[2],color[3], -1,0,0,
-1, 1, 1, 1,1, color[0],color[1],color[2],color[3], -1,0,0,
-1,-1, 1, 1,0, color[0],color[1],color[2],color[3], -1,0,0,
// Bottom of the cube
-1,-1,-1, 0,0, color[0],color[1],color[2],color[3], 0,-1,0,
-1,-1, 1, 0,1, color[0],color[1],color[2],color[3], 0,-1,0,
1,-1, 1, 1,1, color[0],color[1],color[2],color[3], 0,-1,0,
-1,-1,-1, 0,0, color[0],color[1],color[2],color[3], 0,-1,0,
1,-1, 1, 1,1, color[0],color[1],color[2],color[3], 0,-1,0,
1,-1,-1, 1,0, color[0],color[1],color[2],color[3], 0,-1,0,
// Back of the cube
-1,-1,-1, 0,0, color[0],color[1],color[2],color[3], 0,0,-1,
-1, 1,-1, 0,1, color[0],color[1],color[2],color[3], 0,0,-1,
1, 1,-1, 1,1, color[0],color[1],color[2],color[3], 0,0,-1,
-1,-1,-1, 0,0, color[0],color[1],color[2],color[3], 0,0,-1,
1, 1,-1, 1,1, color[0],color[1],color[2],color[3], 0,0,-1,
1,-1,-1, 1,0, color[0],color[1],color[2],color[3], 0,0,-1
];
return new Float32Array(vertices);
}
}