With android we describe what the matrix represents, and the Matrix.setLookAtM method generates a model view matrix for us. This contrasts sharply with WebGL where we have to know how to build the matrix.
153 public float[] generateViewMatrix() 154 { 155 final float[] viewMatrix = new float[16]; 156 157 // Position the camera, where we are viewing the scene from, at the origin. 158 final float cameraX = 0.0f; 159 final float cameraY = 0.0f; 160 final float cameraZ = 0.0f; 161 162 // We are looking in the -z direction 163 final float lookX = 0.0f; 164 final float lookY = 0.0f; 165 final float lookZ = -1.0f; 166 167 // Up is the y axis. 168 final float upX = 0.0f; 169 final float upY = 1.0f; 170 final float upZ = 0.0f; 171 172 // Set the view matrix. 173 Matrix.setLookAtM(viewMatrix, 0, cameraX, cameraY, cameraZ, lookX, lookY, lookZ, upX, upY, upZ); 174 175 return viewMatrix; 176 }
The Matrix class builds this matrix for us. This matches the WebGL example with the camera at the origin looking down the -z axis oriented so up is the +y direction. This yields an identity matrix as the model view matrix.
We can easily generate different views by changing these parameters. We don't need to know the details of the matrix, but of course it helps. For example, we can do a barrel roll by by modifying the up components.