-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojection.js
77 lines (56 loc) · 1.68 KB
/
projection.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
66
67
68
69
70
71
72
73
74
75
76
/*
* Te3ds
* by Bipeen Acharya, Olivier Mahame, Suraj Bajracharya
* Submitted to: Dr. Joshua Stough
* Date: April 9th, 2014
*/
function projectionSquare() {
var squareNormal = normalize(vec3(0.0, 0.0, 1.0));
projectionPoints.push(vec4(0.0, 1.0, 0.0, 1.0));
projectionNormals.push(squareNormal);
projectionPoints.push(vec4(-1.0, 1.0, 0.0, 1.0));
projectionNormals.push(squareNormal);
projectionPoints.push(vec4(-1.0, 0.0, 0.0, 1.0));
projectionNormals.push(squareNormal);
projectionPoints.push(vec4(0.0, 1.0, 0.0, 1.0));
projectionNormals.push(squareNormal);
projectionPoints.push(vec4(0.0, 0.0, 0.0, 1.0));
projectionNormals.push(squareNormal);
projectionPoints.push(vec4(-1.0, 0.0, 0.0, 1.0));
projectionNormals.push(squareNormal);
return 6;
}
function cubeProjection(cube){
var size = projectionSquare();
var obj = object("SQUARE",1,size);
var pZ =0;
var tempZ =[];
for( var i=0;i<LAST_PIECE_START_INDEX;i++){
if(table[i].pos[0]== cube.pos[0]&&table[i].pos[1]== cube.pos[1] && table[i].pos[2]< cube.pos[2]){
tempZ.push(table[i].pos[2]);
}
}
if(tempZ.length >0){
pZ = Math.max.apply(Math, tempZ)+1.01;
}
if (pZ >= 20) {
gameOver();
return;
}
obj.ctm = translate(cube.pos[0], cube.pos[1], pZ);
obj.pos = vec3(cube.pos[0], cube.pos[1], pZ);
var pColor = vec4(0.05 * (20 - pZ),0.05 * (20 - pZ),0.05 * (20 - pZ),1.0);
obj.materialDiffuse = pColor
obj.materialSpecular = pColor;
obj.materialAmbient= pColor;
projectionTable.push(obj);
}
function lastBlockProjection(){
projectionTable = [];
projectionPoints =[];
projectionNormals =[];
for( var i=LAST_PIECE_START_INDEX;i< table.length;i++){
cubeProjection(table[i]);
}
bufferData();
}