O'Reilly logo

Killer Game Programming in Java by Andrew Davison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Viewpoint Creation

Various viewpoint manipulations are carried out by WrapMaze3D's prepareViewPoint():

Positioning and orientation

The viewpoint's position is specified using the maze's starting point (represented by an s in the maze plan). The viewpoint is rotated to face along the positive z-axis. There's no reason for doing this, except to show how I can change the default orientation (which is along the negative z-axis).

Movement control

A KeyBehavior object is connected to the viewpoint so key presses can move it during execution.

A Spotlight

The maze is cast into stygian gloom, so a Spotlight node is connected to the viewpoint to help the users see what they're doing. It'll move with the viewpoint, giving the impression that the player is holding a spotlight.

Adjustments to the view parameters

The FOV is widened, so the user can see more of the scene in front of them. The front and back clip distances are adjusted, primarily so the user can move right up to a block or cylinder without it being clipped.

An avatar

Many first-person games include a player avatar (a visible representation of the user, or part of the user); the "gun-in-hand" image in Chapter 24 is a simple example. I've decided not to include an avatar in the Maze3D application, but I'll discuss how to add one later in this section. The example code adds a 3D cone to the viewpoint.

The FOV

The FOV specifies how much of the scene is visible in terms of an angular spread around the viewpoint. The default is 45 degrees ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required