-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcube.js
More file actions
57 lines (41 loc) · 1.29 KB
/
cube.js
File metadata and controls
57 lines (41 loc) · 1.29 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
// Class to instanciate each cube of the rubiks cube
class Cube{
constructor(mvMatrix, x,y,z, c){
this.mvMatrix = mvMatrix;
this.mvMatrixFix = mvMatrix;
this.x = x;
this.y = y;
this.z = z;
}
drawModel(){
this.mvMatrix = mult(this.mvMatrix,translationMatrix(this.x,this.y,this.z));
this.mvMatrix = mult(this.mvMatrix, scalingMatrix( 0.25, 0.25, 0.25));
var mvUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
gl.uniformMatrix4fv(mvUniform, false, new Float32Array(flatten(this.mvMatrix)));
// NEW - Aux. Function for computing the illumination
computeIllumination(this.mvMatrix);
initBuffers();
// Drawing
gl.drawArrays(gl.TRIANGLES, 0, triangleVertexPositionBuffer.numItems);
}
computeAllRot(){
this.mvMatrix = mult(this.mvMatrix, rotationXXMatrix(globalAngleX));
this.mvMatrix = mult(this.mvMatrix, rotationYYMatrix(globalAngleY));
this.mvMatrix = mult(this.mvMatrix, rotationZZMatrix(globalAngleZ));
}
setMat(mvMatrix){
this.mvMatrix = mvMatrix;
}
getMat(){
return this.mvMatrix;
}
rotationX(angle, matrix){
this.mvMatrix = mult(matrix, rotationXXMatrix(angle));
}
rotationY(angle, matrix){
this.mvMatrix = mult(matrix, rotationYYMatrix(angle));
}
rotationZ(angle){
this.mvMatrix = mult(this.mvMatrix, rotationZZMatrix(angle));
}
}