From fbb8665ef8d4546218f52fcd13dfbfb5fea75371 Mon Sep 17 00:00:00 2001 From: Guilherme Rossato Date: Tue, 6 Dec 2016 15:38:44 -0200 Subject: [PATCH] Syntax Formatting mrdoob has a tendency to put lines inbetween lines, I feel like there's too many lines to be efficient while editing his classes, so I removed them --- .../Classes/Controls/PointerLockControls.js | 73 ++++++------------- Script/setup.js | 5 +- 2 files changed, 27 insertions(+), 51 deletions(-) diff --git a/Script/Classes/Controls/PointerLockControls.js b/Script/Classes/Controls/PointerLockControls.js index b0d7dc8..6926e50 100644 --- a/Script/Classes/Controls/PointerLockControls.js +++ b/Script/Classes/Controls/PointerLockControls.js @@ -1,69 +1,44 @@ /** * @author mrdoob / http://mrdoob.com/ */ - -THREE.PointerLockControls = function ( camera ) { - +THREE.PointerLockControls = function(camera) { var scope = this; - - camera.rotation.set( 0, 0, 0 ); - + camera.rotation.set(0, 0, 0); var pitchObject = new THREE.Object3D(); - pitchObject.add( camera ); - + pitchObject.add(camera); var yawObject = new THREE.Object3D(); yawObject.position.y = 10; - yawObject.add( pitchObject ); - + yawObject.add(pitchObject); var PI_2 = Math.PI / 2; - - var onMouseMove = function ( event ) { - - if ( scope.enabled === false ) return; - + 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 ) ); - + 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 ); - + document.removeEventListener('mousemove', onMouseMove, false); + } + ; + document.addEventListener('mousemove', onMouseMove, false); this.enabled = false; - - this.getObject = function () { - + 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 ); - + 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; - - }; - + } + ; }(); - -}; +} +; diff --git a/Script/setup.js b/Script/setup.js index 7d9a04d..1b1e5fc 100644 --- a/Script/setup.js +++ b/Script/setup.js @@ -9,8 +9,9 @@ domInterface.appendChild(domMenu); domInterface.appendChild(domSubmenu); var menu = new Menu(domMenu,domSubmenu); var logger = new Logger(domInterface); -if (!('pointerLockElement'in document || 'mozPointerLockElement'in document || 'webkitPointerLockElement'in document)) { - logger.error("This experiment will not work correctly."); +var pointerlockSupport = ('pointerLockElement'in document || 'mozPointerLockElement'in document || 'webkitPointerLockElement'in document); +if (!pointerlockSupport) { + logger.warn("Your controls will adjust accordingly."); logger.warn("Your browser doesn't support pointer lock API."); } var centerMessage = new CenterMessage(domInterface, "Click to start","[W, A, S, D] to move up, left, down, right\n[Numeric Keys] to change selected block\n[E, ESC, I] to change selected tool (top menu)\n[Ctrl + 1, 2, 3] Also changes the selected tool\n[Ctrl + C, Ctrl + V] copy and paste selection\n[ +, - ] to change tools menu size"); \ No newline at end of file