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

Positioning and Moving the User's Viewpoint

The user's viewpoint (sometimes called the application camera) is positioned by the view branch part of the scene graph; its main elements are shown in Figure 24-3.

The view branch subgraph

Figure 24-3. The view branch subgraph

You haven't seen the view branch much up to now since it's been built automatically when I've used the SimpleUniverse utility class to create the scene graph. However, I need to attach the gun-in-hand image to the viewpoint and move it around in response to user key presses.

The viewpoint is represented by the ViewPlatform node in Figure 24-3 (the triangle) and is repositioned by applying transforms to the TG node above it (TG is short for TransformGroup). It's possible to add extra TransformGroups above the ViewPlatform node to implement more complex forms of movements, but I don't need to do that in this example.

A shape is attached to the viewpoint by storing it in a Java 3D PlatformGeometry node and connecting it to the TransformGroup above the ViewPlatform. This is the how I'll place the gun-in-hand image in front of the viewpoint.

SimpleUniverse offers access to the view branch via several utility classes: Viewer, ViewingPlatform, PlatformGeometry, and others. You've seen ViewingPlatform used several times to move the viewer's starting position.

Viewpoint Behaviors

Java 3D contains several classes that can affect the viewpoint. In previous ...

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