Graphics Programs Reference
In-Depth Information
float zFar = 1000;
float fov = 0.75f; // 0.2 to 1.0
float size = (float) (zNear * Math.tan(fov / 2));
Matrix.setLookAtM(_ViewMatrix, 0, -13, 5, 10, 0, 0, 0,
0, 1, 0);
Matrix.frustumM(_ProjectionMatrix, 0, -size, size,
-size / ratio, size / ratio, zNear, zFar);
Matrix.multiplyMM(_MVPMatrix, 0, _ProjectionMatrix, 0,
_ViewMatrix, 0);
In Listing 3-25 , the code snippet used above the setLookAtM method (that is,
the lines of code from “float ratio = (float) width/height” to “float size = (float)
(zNear * Math.tan(fov / 2))”) is used to prepare the arguments for the frustumM
method. This method defines the viewing volume in terms of left-right, bottom-
top, and near-far planes. Finally, using another utility method multiplyMM from
the android.opengl.Matrix class, the result of _ProjectionMatrix *
_ViewMatrix is stored in _MVPMatrix .
In the GL CUBE application, if any modeling transformation was used (for example,
rotation), the last line in Listing 3-25 would look similar to Listing 3-26
( Chapter4/gltankfenceelements1.zip ). Effectively, this would store the
result of _ProjectionMatrix * _ViewMatrix * _RMatrix in
_MVPMatrix . Here ( Listing 3-26 ), the _RMatrix stores the modeling transform-
ation of type rotation.
Listing 3-26. TANK FENCE ELEMENTS 1/src/com/apress/android/tank-
fenceelements1/GLES20Renderer.java
Matrix.multiplyMM(_MVPMatrix, 0, _ViewMatrix, 0,
_RMatrix, 0);
Matrix.multiplyMM(_MVPMatrix, 0, _ProjectionMatrix, 0,
_MVPMatrix, 0);
Inside the vertex shader ( Listing 3-27 ) , a uniform variable is declared (similar
to the way we declare an attribute). Uniforms are variables that store read only
values. They are generally used to store values, such as transformation matrices,
that need to be updated “externally.” They are read only within the vertex shader;
however, if any geometric transformation needs performed on a frame by frame
 
 
 
Search WWH ::




Custom Search