Encode Universal Product Code version A in Online INTERACTIVITY

Using Barcode encoder for Online Control to generate, create UCC-128 image in Online applications.

TarCode.com/GS1 128

} private function _onMouseLeave(ev : Event) : void { stage.removeEventListener(MouseEvent.MOUSE_MOVE, _onMouseMove); stage.removeEventListener(Event.MOUSE_LEAVE, _onMouseLeave); } } } The preceding code is laid out in a very similar manner to the click-and-drag functionality applied to 3D objects earlier in this chapter. When the mouse button is clicked and held, the listener for MOUSE_MOVE events will activate, and when the button is released, the listener will deactivate. Notice that to stop listening for mouse movement, we actually require two event handlers: a MOUSE_UP handler for when the mouse button is released with the cursor position still over the Flash movie window and a MOUSE_LEAVE handler for when the mouse button is released with the cursor position outside the Flash movie window, after having been dragged out. To complete the interaction, we add the following code to the _onMouseMove() method to calculate the rotation of the camera when a MOUSE_MOVE event is broadcast. First, we calculate the distance the mouse has travelled since the last MOUSE_MOVE event and use that value to increment the camera rotation. Then, we prepare for the next event by storing the current mouse position in our global class variable _lastPoint. _view.camera.rotationX -= (stage.mouseY - _lastPoint.y) / 5; _view.camera.rotationY += (stage.mouseX - _lastPoint.x) / 5; _lastPoint.x = stage.mouseX; _lastPoint.y = stage.mouseY; The pitch increment of the camera is calculated using the y increment of the mouse position, and the yaw increment of the camera is calculated using the x increment of the mouse position. Converting from pixels to degrees, we divide each result by 5 to give an appropriate ratio of rotation speed to mouse movement. As we saw in the previous example, rotation of a first person camera can use standard rotation properties, so we apply our calculated pitch and yaw increments to the respective rotationX and rotationY properties of the camera object. Before compiling our FirstPersonCameraWithDrag example, we need to make sure that the first time the mouse movement is calculated in a mouse drag, the increment value starts from the point where the user started dragging (i.e., the point where the mouse button was first clicked). To achieve this, we can copy the last two lines of the preceding code snippet and add them to the start of the _onMouseDown() method so that it now looks like the following: private function _onMouseDown(ev : MouseEvent) : void { _lastPoint.x = stage.mouseX; _lastPoint.y = stage.mouseY; stage.addEventListener(MouseEvent.MOUSE_MOVE, _onMouseMove); stage.addEventListener(Event.MOUSE_LEAVE, _onMouseLeave);

Using Barcode generator for Online Control to generate, create Code 3/9 image in Online applications.

TarCode.com/Code 39 Extended

} Here, the additional lines to the _onMouseDown() method are highlighted in bold. Compile the FirstPersonCameraWithDrag example, and try clicking and dragging the mouse to look around. The camera should rotate in the direction you drag, with movement in both a horizontal and vertical direction. You are still able to walk around as before, and better still, both interactions can be used simultaneously. The left and right arrow keys (and the A and D keys) still control the camera rotation as before, but have been made redundant in this example by the introduced mouse interaction. Next, let s take a look at a different approach for using the mouse to look around.

Using Barcode maker for Online Control to generate, create ANSI/AIM Codabar image in Online applications.

TarCode.com/Rationalized Codabar

The main downside with the dragging approach to mouse controlled rotation in the previous FirstPersonCameraWithDrag example is that a user has to repeatedly click and drag the mouse to execute sharp turns, because a single drag has a finite distance and therefore executes a finite rotation. An alternative method that doesn t suffer the same limitations uses an interactive technique known as scrubbing. A scrubbing interface in an audio or video application tends to consist of a handle or wheel that can be dragged left or right to control the speed and direction of playback. The speed depends on how far off center you drag the control, and when released, the control jumps back to its center position and playback stops. The same interaction can be applied to our camera rotation control, so that when the mouse cursor is scrubbed from anywhere inside the Flash movie, the camera will rotate continuously in the direction of scrub until the mouse button is released. To implement this interaction, let s again use the FirstPersonCamera class as our starting point and extend its functionality with the following: package flash3dbook.ch08 { import flash.events.*; import flash.geom.*; import flash3dbook.ch08.*; [SWF(width="800", height="600")] public class FirstPersonCameraWithScrub extends FirstPersonCamera { private var _lastPoint:Point = new Point(); private var _scrub:Boolean; public function FirstPersonCameraWithScrub() { super(); stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown); stage.addEventListener(MouseEvent.MOUSE_UP, _onMouseUp); } private function _onMouseDown(ev : MouseEvent) : void {

Using Barcode creator for iPad Control to generate, create UPC Code image in iPad applications.

TarCode.com/UPC Code

Using Barcode generator for Software Control to generate, create UCC - 12 image in Software applications.

TarCode.com/UPC Code

Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET applications.