October 2018
Intermediate to advanced
464 pages
15h 17m
English
First, we modify the vertexShaderCode to include a matrix variable. We calculate the matrix in the onSurfaceChanged() callback using the height and width, which are passed in as parameters. We pass the transformation matrix to the draw() method to use it when calculating the position to draw.
Before we call the draw() method, we calculate the camera view. These two lines of code calculate the camera view:
Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
Without this code, there would actually be no triangle drawn as the camera perspective would not "see" our vertices. (This goes back to our discussion on how the order of the vertices ...