Moving the Viewpoint
This chapter's KeyBehavior class is similar to the one described in Chapter 24, since both control the user's viewpoint. They both extend ViewPlatformBehavior, so they can access the ViewPlatform's TransformGroup. They both use the same key presses to trigger movement and rotation.
Movement can be forward, backward, left, right, up, or down, by one unit step, excluding jaunts through the walls or floor. Rotations are carried out in 90-degree turns left or right, which simplifies the implementation of the BirdsEye class. BirdsEye's main task is to calculate the position and orientation of an arrow drawn on top of the overview image when the viewpoint moves or rotates.
KeyBehavior is complicated by being involved in the manipulation of two cameras and the BirdsEye view. The movement/rotation of the cameras are done inside KeyBehavior by affecting their TransformGroups, but the BirdsEye object carries out its own changes. These additional responsibilities can be seen in standardMove() that calls the moveBy() and doRotateY() methods with extra arguments for the extra views:
private void standardMove(int keycode)
{
if(keycode == forwardKey)
moveBy(VFWD, FORWARD, VBACK);
else if(keycode == backKey)
moveBy(VBACK, BACK, VFWD);
else if(keycode == leftKey)
doRotateY(ROT_AMT, LEFT);
else if(keycode == rightKey)
doRotateY(-ROT_AMT, RIGHT);
}The arguments of moveBy() are constants related to the main camera, the bird's-eye view, and the back facing camera. When the main camera ...