diff options
Diffstat (limited to 'three_js/dist/PointerLockControls.js')
| -rw-r--r-- | three_js/dist/PointerLockControls.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/three_js/dist/PointerLockControls.js b/three_js/dist/PointerLockControls.js new file mode 100644 index 0000000..b0d7dc8 --- /dev/null +++ b/three_js/dist/PointerLockControls.js @@ -0,0 +1,69 @@ +/** + * @author mrdoob / http://mrdoob.com/ + */ + +THREE.PointerLockControls = function ( camera ) { + + var scope = this; + + camera.rotation.set( 0, 0, 0 ); + + var pitchObject = new THREE.Object3D(); + pitchObject.add( camera ); + + var yawObject = new THREE.Object3D(); + yawObject.position.y = 10; + yawObject.add( pitchObject ); + + var PI_2 = Math.PI / 2; + + var onMouseMove = function ( event ) { + + if ( scope.enabled === false ) return; + + var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0; + var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0; + + yawObject.rotation.y -= movementX * 0.002; + pitchObject.rotation.x -= movementY * 0.002; + + pitchObject.rotation.x = Math.max( - PI_2, Math.min( PI_2, pitchObject.rotation.x ) ); + + }; + + this.dispose = function() { + + document.removeEventListener( 'mousemove', onMouseMove, false ); + + }; + + document.addEventListener( 'mousemove', onMouseMove, false ); + + this.enabled = false; + + this.getObject = function () { + + return yawObject; + + }; + + this.getDirection = function() { + + // assumes the camera itself is not rotated + + var direction = new THREE.Vector3( 0, 0, - 1 ); + var rotation = new THREE.Euler( 0, 0, 0, "YXZ" ); + + return function( v ) { + + rotation.set( pitchObject.rotation.x, yawObject.rotation.y, 0 ); + + v.copy( direction ).applyEuler( rotation ); + + return v; + + }; + + }(); + +}; |
