Class Diagrams for Maze3D


Moving the Viewpoint

FPShooter3D moves the viewpoint by attaching a KeyBehavior object to ViewPlatform's TRansformGroup:

     ViewingPlatform vp = su.getViewingPlatform(  );         KeyBehavior keyBeh = new KeyBehavior( ammoMan );            // keyBeh can ask the ammoManager to fire a beam     keyBeh.setSchedulingBounds(bounds);     vp.setViewPlatformBehavior(keyBeh); 

KeyBehavior's internals are similar to earlier keyboard-based behaviors developed for the Tour3D and AnimTour3D examples in Chapters 18 and 19. A key press triggers the behavior, and the associated KeyEvent object is used to determine the type of movement to carry out.

Similarities aside though, one difference between KeyBehavior and earlier classes is that this class extends ViewPlatformBehavior so it can work upon ViewPlatform's transformGroup, called targetTG. targetTG is available to the methods defined in KeyBehavior tHRough inheritance.

Another difference is that the Tour3D and AnimTour3D behaviors pass the responsibility for movement and rotation to objects in the scene (i.e., to the sprites). KeyBehavior carries out those operations for itself, by manipulating targetTG. KeyBehavior detects key presses of the arrow keys, optionally combined with the alt key to move forward, back, left, right, up, down, and rotate around the y-axis. The f key requests beam firing.

processStimulus( ) calls processKeyEvent( ) when a key is detected:

     private void processKeyEvent(KeyEvent eventKey)     { int keyCode = eventKey.getKeyCode(  );       if(eventKey.isAltDown(  ))   // key + <alt>         altMove(keyCode);       else         standardMove(keyCode);     } 

altMove( ) and standardMove( ) are multi-way branches calling doMove( ) or rotateY( ) (or AmmoManager's fireBeam( ), when the key is f). rotateY( ) applies a rotation to targetTG:

     private void rotateY(double radians)     { targetTG.getTransform(t3d);       toRot.rotY(radians);       t3d.mul(toRot);       targetTG.setTransform(t3d);     } 

t3d and toRot are globals to avoid the overhead of temporary object creation.



Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net