Game Development Reference
In-Depth Information
Equipped with all of these values, we then check whether a finger is actually touching the
screen. If so, we first check whether it is touching the button, which spans the coordinates (0,0)
to (64,64) in the 2D UI system. If that is the case, we fetch the current direction of the camera
and add it to its position, multiplied by the current delta time. Since the direction vector is a
unit-length vector, this means that the camera will move one unit per second.
If the button is not touched, we interpret the touch as a swipe gesture. For this to work, we need
to have a valid last known touch coordinate. The first time the user puts his or her finger down,
the lastX and lastY members will have a value of -1, indicating that we can't create a difference
between the last and current touch coordinates because we only have a single data point.
Therefore, we just store the current touch coordinates and return from the update() method.
If we recorded touch coordinates the last time update() was invoked, we simply take the
difference on the x and y axes between the current and the last touch coordinates. We directly
translate these into increments of the rotation angles. To slow down the rotation a little, we divide
the differences by 10. The only thing left is to call the EulerCamera.rotate() method, which will
adjust the rotation angles accordingly.
Finally, if no finger is currently touching the screen, we set the lastX and lastY members to -1,
to indicate that we have to await the first touch event before we can do any swipe-gesture
processing.
@Override
public void present( float deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClear(GL10. GL_COLOR_BUFFER_BIT | GL10. GL_DEPTH_BUFFER_BIT );
gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());
camera.setMatrices(gl);
gl.glEnable(GL10. GL_DEPTH_TEST );
gl.glEnable(GL10. GL_TEXTURE_2D );
gl.glEnable(GL10. GL_LIGHTING );
crateTexture.bind();
cube.bind();
light.enable(gl, GL10. GL_LIGHT0 );
for ( int z = 0; z >= -8; z-=2) {
for ( int x = -4; x<=4; x+=2 ) {
gl.glPushMatrix();
gl.glTranslatef(x, 0, z);
cube.draw(GL10. GL_TRIANGLES , 0, 6 * 2 * 3);
gl.glPopMatrix();
}
}
cube.unbind();
gl.glDisable(GL10. GL_LIGHTING );
gl.glDisable(GL10. GL_DEPTH_TEST );
 
Search WWH ::




Custom Search