|
@@ -10,14 +10,7 @@ THREE.PointerLockControls = function ( camera, domElement ) {
|
|
|
this.domElement = domElement || document.body;
|
|
|
this.isLocked = false;
|
|
|
|
|
|
- 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 );
|
|
|
+ camera.rotation.reorder( 'YXZ' );
|
|
|
|
|
|
var PI_2 = Math.PI / 2;
|
|
|
|
|
@@ -28,10 +21,10 @@ THREE.PointerLockControls = function ( camera, domElement ) {
|
|
|
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;
|
|
|
+ camera.rotation.y -= movementX * 0.002;
|
|
|
+ camera.rotation.x -= movementY * 0.002;
|
|
|
|
|
|
- pitchObject.rotation.x = Math.max( - PI_2, Math.min( PI_2, pitchObject.rotation.x ) );
|
|
|
+ camera.rotation.x = Math.max( - PI_2, Math.min( PI_2, camera.rotation.x ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -81,22 +74,20 @@ THREE.PointerLockControls = function ( camera, domElement ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.getObject = function () {
|
|
|
+ this.getObject = function () { // retaining this method for backward compatibility
|
|
|
|
|
|
- return yawObject;
|
|
|
+ return camera;
|
|
|
|
|
|
};
|
|
|
|
|
|
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 );
|
|
|
+ rotation.set( camera.rotation.x, camera.rotation.y, 0 );
|
|
|
|
|
|
v.copy( direction ).applyEuler( rotation );
|
|
|
|