Viewer PositioningThe scene graph in Figure 15-3 doesn't include the view branch graph; that branch is shown in Figure 15-7. Figure 15-7. The view branch graphThe branch is created by a call to the SimpleUniverse constructor in the WrapCheckers3D( ) constructor: su = new SimpleUniverse(canvas3D); SimpleUniverse offers simplified access to the view branch graph via the ViewingPlatform and Viewer classes, which are mapped to the graph (shown as dotted rectangles in Figure 15-7). ViewingPlatform is used in initUserPosition( ) to access the transformGroup above the ViewPlatform node: ViewingPlatform vp = su.getViewingPlatform( ); TransformGroup steerTG = vp.getViewPlatformTransform( ); steerTG corresponds to the TG node in Figure 15-7. Its TRansform3D component is extracted and changed with the lookAt( ) and invert( ) methods: Transform3D t3d = new Transform3D( ); steerTG.getTransform(t3d); t3d.lookAt( USERPOSN, new Point3d(0,0,0), new Vector3d(0,1,0)); t3d.invert( ); steerTG.setTransform(t3d); lookAt( ) is a convenient way to set the viewer's position in the virtual world. The method requires the viewer's intended position, the point that she is looking at, and a vector specifying the upward direction. In this application, the viewer's position is USERPOSN (the (0, 5, 20) coordinate); she is looking toward the origin (0, 0, 0), and "up" is along the positive y-axis. This is illustrated by Figure 15-8. Figure 15-8. lookAt( ) depicted graphicallyinvert( ) is required since the position is relative to the viewer rather than an object in the scene. |