In all our previous chapters, we used model transformations. We used
glMatrix
(http://glmatrix.net/) functions to calculate translation and rotation. Let's look at what we are talking about here:
// Create an identity matrix var mvMatrix=mat4.create(); // Translate the matrix by objects location and replace the matrix with the result(mat4.translate(out,in,vec3)) mat4.translate(mvMatrix, mvMatrix, stage.stageObjects[i].location); // Rotate the matrix by objects rotation X and replace the matrix with the result(mat4.rotateX(out,in,vec3)) mat4.rotateX(mvMatrix, mvMatrix, stage.stageObjects[i].rotationX); mat4.rotateY(mvMatrix, mvMatrix, stage.stageObjects[i].rotationY); mat4.rotateZ(mvMatrix, mvMatrix, stage.stageObjects[i].rotationZ);
In the preceding code, we created a ModelView matrix, mvMatrix
, which stores the translation and rotation of the object. We passed this matrix to our fragment shader using our own function, setMatrixUniforms
. When...