Game Development Reference
In-Depth Information
Figure 11-10. A simple scene with 25 crates, a point light, and an Euler camera in its initial position and orientation
The camera will be located at (0,1,3). We also have a white point light at (3,3,-3). The crates
are positioned in a grid from -4 to 4 on the x axis and from 0 to -8 on the z axis, with a 2-unit
distance between the centers.
How will we rotate the camera via swipes? We want the camera to rotate around the y axis
when we swipe horizontally. That is equivalent to turning your head left and right. We also want
the camera to rotate around the x axis when we swipe vertically. That's equivalent to tilting your
head up and down. We also want to be able to combine these two swipe motions. The most
straightforward way to achieve this is to check whether a finger is on the screen and, if so, to
measure the difference on each axis to the last known position of that finger on the screen. We
can then derive a change in rotation on both axes by using the difference in x for the y-axis
rotation and the difference in y for the x-axis rotation.
We also want to be able to move the camera forward by pressing an onscreen button. That's
simple; we just need to call EulerCamera.getDirection() and multiply its result by the speed
at which we want the camera to move and the delta time, so that we once again perform time-
based movement. The only thing that we need to do is draw the button (we decided to draw a
64×64 button in the bottom-left corner of the screen) and check whether it is currently touched
by a finger.
To simplify our implementation, we'll only allow the user to either swipe-rotate or move. We
could use the multitouch facilities for this, but that would complicate our implementation
quite a bit.
With this plan of attack in place, let's look at EulerCameraScreen , a GLScreen implementation
contained in a GLGame implementation called EulerCameraTest (just the usual test structure).
Listing 11-10 shows the code.
 
Search WWH ::




Custom Search