< Zurück | Inhalt | Weiter >

Implementing DOOM and DOOM−style keyboard navigation

In my experience, many of the people interested in implementing keyboard navigation would like to use it in an immersive, first−person perspective 3D scene (figure 11.3). When I set out to write the examples to illustrate keyboard behaviors, this must have been at the front of my mind, because the KeyNavigateTest example ended up looking a lot like DOOM or Id’s early favorite, Wolfenstein 3D (


Figure 11.3 The KeyNavigateTest example in action. DOOM all over again

Writing the example was a lot of fun, and it includes a number of features that should be of interest to people writing immersive, first−person perspective applications:

Simple keyboard navigation is used: forward, backward, rotate left, rotate right.

A 3D world can be created from a simple 2D map—defined using a standard image file.

Five types of objects can be dynamically created within the world: walls, bookcases, pools of water, flaming torch (animated), and Guards (animated).

Collision detection is used to ensure walls and bookcases are impenetrable.

Simple behaviors attached to the guards allow them to move around within the world.

Simple texture image techniques animate the texture images for torches to give an impression of flames.

The example is obviously fairly lengthy and cannot be discussed in depth here, so only highlights will be described. I was impressed by how functional the example became with a relatively small amount of code. This is due in part to Java 3D’s high−level features and in part to the extensive use I made of the reusable classes within the org.selman.java3d.book package.


Loading and creating the world from a 2D map
From KeyNavigateTest.java
Implementing collision detection
From KeyCollisionBehavior.java
From KeyNavigateTest.java
Simple texture image animation for flaming torches
From Light.java