Graphics Programs Reference
In-Depth Information
Listing 6-17. TANK FENCE GAME 4/src/com/apress/android/tankfencegame4/
GLES20Renderer.java
if(GLES20Renderer._enemies.size() > 0) {
// initenemy();
float[] enemiesMMatrix = new float[16];
ListIterator<Enemy> enemiesIterator =
GLES20Renderer._enemies.listIterator();
while(enemiesIterator.hasNext()) {
Enemy enemy = enemiesIterator.next();
Matrix.setIdentityM(enemiesMMatrix, 0);
Matrix.translateM(enemiesMMatrix, 0,
enemy.getSourcePositionX(),
enemy.getSourcePositionY(), 0);
renderEnemies(enemiesMMatrix);
}
}
renderModel(gl);
In Listing 6-16 , if the arguments to the Enemy constructors are all set to “0”, then all
four Enemy objects will be rendered at {10.0005, 10.0, 0.1005} . In the first
constructor, the arguments passed are (10.0005f, 10.0f, 0) . This translates
the first Enemy object by 10.0005 units along x-axis and 10.0 units along y-axis. In
the second constructor, the arguments passed are (-3 * 10.0005f, 10.0f,
0) . This translates the second Enemy object by -3 * 10.0005 units along x-axis and
10.0 units along y-axis; so, this Enemy object gets rendered in the second quadrant,
as shown in Figure 6-7 . Similarly, in the third constructor the arguments passed are
(-3 * 10.0005f, -3 * 10.0f, 0) , and in the fourth constructor the argu-
ments passed are (10.0005f, -3 * 10.0f, 0) - which renders these Enemy
objects in the third and fourth quadrants respectively.
The while loop in Listing 6-17 is used to iterate over the _enemies ArrayList
to get the source positions, passed as arguments to the Enemy constructors, seen in
Listing 6-16 .
Within this while loop, the renderEnemies() method ( Listing 6-18 ) is called.
The matrix enemiesMMatrix is used to translate the Enemy objects. It is passed
 
 
Search WWH ::




Custom Search