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; ...

Get Killer Game Programming in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.