This example is almost entirely the same as the last one, but it adds a camera that can fly under user control. The controls for the camera include dragging the left mouse button for rotation and the WASD keys for forward and lateral movement. Q and E control roll.
The camera is moved by putting it under the control of a FlyControls object. Note that there is nothing special about the camera; any other object could be made to fly in the same way. The following lines create and initialize this controller.
var control = new THREE.FlyControls(camera,mycanvas);
creates the FlyControls
object.
control.dragToLook = true;
requires the mouse button to remain down in order to steer with the mouse.
control.movementSpeed = 4;
control.rollSpeed = 0.5;
controls the responsiveness of the movement.
The controller needs to be able to move the camera to its current position before rendering each frame. This is accomplished by invoking the update function of the controller before each frame.