Graphics Reference
In-Depth Information
color data as inputs or attributes, transforms the position by a 4 × 4
matrix, and outputs the transformed position and color.
The transformed vertex positions and primitive type are then used by the
setup and rasterization stages to rasterize the primitive into fragments. For
each fragment, the interpolated v_color will be computed and passed as
input to the fragment shader.
Example 8-1 introduces the concept of the model-view-projection (MVP)
matrix in the uniform u_mvpMatrix . As described in the Coordinate Systems
section in Chapter 7, the positions input to the vertex shader are stored in
object coordinates and the output position of the vertex shader is stored
in clip coordinates. The MVP matrix is the product of three very important
transformation matrices in 3D graphics that perform this transformation:
the model matrix, the view matrix, and the projection matrix.
The transformations performed by each of the individual matrices that
make up the MVP matrix are as follows:
• Model matrix—Transform object coordinates to world coordinates.
• View matrix—Transform world coordinates to eye coordinates.
• Projection matrix—Transform eye coordinates to clip coordinates.
Model-View Matrix
In traditional fixed-function OpenGL, the model and view matrices are
combined into a single matrix known as the model-view matrix. This
4 × 4 matrix transforms the vertex position from object coordinates
into eye coordinates. It is the combination of the transformation from
object to world coordinates and the transformation from world to eye
coordinates. In fixed-function OpenGL, the model-view matrix can
be created using functions such as glRotatef , glTranslatef , and
glScalef . Because these functions do not exist in OpenGL ES 2.0 or 3.0,
it is up to the application to handle creation of the model-view matrix.
To simply this process, we have included in the sample code framework
esTransform.c , which contains functions that perform equivalently to
the fixed-function OpenGL routines for building a model-view matrix.
These transformation functions ( esRotate , esTranslate , esScale ,
esMatrixLoadIdentity , and esMatrixMultiply ) are detailed in
Appendix C. In Example 8-1, the model-view matrix is computed as follows:
ESMatrix modelview;
// Generate a model-view matrix to rotate/translate the cube
esMatrixLoadIdentity ( &modelview );
 
Search WWH ::




Custom Search