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

The Back Facing Camera

The back facing camera is a second ViewPlatform node, which requires its own Canvas3D object so the view can be displayed. The minimal subgraph for the camera is shown in Figure 25-11.

The minimal view branch graph

Figure 25-11. The minimal view branch graph

Attributes related to the user's head are defined in PhysicalBody, such as the position of her eyes relative to the scene. PhysicalEnvironment specifies the environment in which the view will be generated, such as whether head-tracking or wall displays are being utilized. I'm using a standard PC configuration, so these objects can be created with their default settings. The ViewPlatform represents the camera's viewpoint, and the TransformGroup above it positions the viewpoint and is the connection point between the camera and the top-level BranchGroup in the main scene.

The SecondViewPanel class creates a subgraph such as the one in Figure 25-11, and makes its TransformGroup, called canvas2TG, visible via the method getCamera2TG(). The class's other role is to embed its Canvas3D object inside a JPanel so that it can be easily inserted into the Swing-based GUI. SecondViewPanel is a subclass of JPanel, so the attachment of the Canvas3D object is carried out in its constructor:

 // globals private static final int PWIDTH = 256; // size of panel private static final int PHEIGHT = 256; private MazeManager mazeMan; private TransformGroup camera2TG; ...

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