summaryrefslogtreecommitdiff
path: root/three_js/dist/PointerLockControls.js
diff options
context:
space:
mode:
authorJ08nY2016-04-16 15:34:14 +0200
committerJ08nY2016-04-16 15:34:14 +0200
commit8c2c5e52e0a1d78d36743270866ef5827aa8cd4e (patch)
tree2e52d9106418d7fc7c09efaf7162d9e42574080a /three_js/dist/PointerLockControls.js
parentc5d0b945bf4dccc0e611d961f5f60dc3ded293e6 (diff)
downloadld35-8c2c5e52e0a1d78d36743270866ef5827aa8cd4e.tar.gz
ld35-8c2c5e52e0a1d78d36743270866ef5827aa8cd4e.tar.zst
ld35-8c2c5e52e0a1d78d36743270866ef5827aa8cd4e.zip
Diffstat (limited to 'three_js/dist/PointerLockControls.js')
-rw-r--r--three_js/dist/PointerLockControls.js69
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;
+
+ };
+
+ }();
+
+};