Graphics Programs Reference
In-Depth Information
Perspective/Projection transformation
▪
Matrix .frustumM(float[ ] m, int mOffset, float left, float right,
float bottom, float top, float near, float far):
Defines a
projection
matrix
m
in terms of six clip planes
To perform these transformations, we need to associate matrices with objects (again,
an object is a primitive or a combination of same type of primitives). There are three
stages—first, we declare a new kind of input variable in our vertex shader called
uni-
form
; then we multiply this variable with an
attribute
so as to transform per-vertex
position data; finally, we “externally” pass data to this
uniform
variable. You may
have guessed that this data consists of Java
float
arrays.
We describe this with the help of an application, but first we explain an important
concept about combined transformations. In almost all cases, when working with
transformations of objects in interactive ES 2.0 applications, we have to use model-
ing transformation in combination with viewing and projection transformations. We
can use a single matrix to represent all of these transformations, and we usually call
this as
MVPmatrix
(that is,
Model-View-Projection matrix
). It bears this name to
signify the order in which we combine the transformations so they are represented
as a single matrix. We first update the
MVPmatrix
with any of the modeling trans-
formations, say using the
translateM
method. Then, we update it with the
setLookAtM
method to apply viewing transformation. Finally, using the
frust-
umM
method, we apply projection transformation. Please note that, because of the
way matrices work, this order (that is,
Model-View-Projection
) becomes important
when combining transformations.
From the source code for this chapter, import the archive file
glcube.zip
. This
loads the
GL CUBE
application into your workspace. First, turn your attention to the
onSurfaceChanged
method of the Renderer class.
named as
_*Matrix
are
float
arrays of size 16) in terms of an eye point
(-13,
5, 10)
, a center of view
(0, 0, 0)
, and an up vector
(0, 1, 0)
for
(x, y,
z)
.
Listing 3-25.
GL CUBE/src/com/apress/android/glcube/GLES20Renderer.java
float ratio = (float) width / height;
float zNear = 0.1f;
Search WWH ::
Custom Search