|
@@ -39,7 +39,7 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.keydown = function( event ) {
|
|
|
+ this.keydown = function ( event ) {
|
|
|
|
|
|
if ( event.altKey ) {
|
|
|
|
|
@@ -78,7 +78,7 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.keyup = function( event ) {
|
|
|
+ this.keyup = function ( event ) {
|
|
|
|
|
|
switch ( event.keyCode ) {
|
|
|
|
|
@@ -109,7 +109,7 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.mousedown = function( event ) {
|
|
|
+ this.mousedown = function ( event ) {
|
|
|
|
|
|
if ( this.domElement !== document ) {
|
|
|
|
|
@@ -139,16 +139,16 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.mousemove = function( event ) {
|
|
|
+ this.mousemove = function ( event ) {
|
|
|
|
|
|
if ( ! this.dragToLook || this.mouseStatus > 0 ) {
|
|
|
|
|
|
var container = this.getContainerDimensions();
|
|
|
- var halfWidth = container.size[ 0 ] / 2;
|
|
|
+ var halfWidth = container.size[ 0 ] / 2;
|
|
|
var halfHeight = container.size[ 1 ] / 2;
|
|
|
|
|
|
- this.moveState.yawLeft = - ( ( event.pageX - container.offset[ 0 ] ) - halfWidth ) / halfWidth;
|
|
|
- this.moveState.pitchDown = ( ( event.pageY - container.offset[ 1 ] ) - halfHeight ) / halfHeight;
|
|
|
+ this.moveState.yawLeft = - ( ( event.pageX - container.offset[ 0 ] ) - halfWidth ) / halfWidth;
|
|
|
+ this.moveState.pitchDown = ( ( event.pageY - container.offset[ 1 ] ) - halfHeight ) / halfHeight;
|
|
|
|
|
|
this.updateRotationVector();
|
|
|
|
|
@@ -156,7 +156,7 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.mouseup = function( event ) {
|
|
|
+ this.mouseup = function ( event ) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
event.stopPropagation();
|
|
@@ -184,7 +184,7 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.update = function( delta ) {
|
|
|
+ this.update = function ( delta ) {
|
|
|
|
|
|
var moveMult = delta * this.movementSpeed;
|
|
|
var rotMult = delta * this.rollSpeed;
|
|
@@ -202,42 +202,42 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.updateMovementVector = function() {
|
|
|
+ this.updateMovementVector = function () {
|
|
|
|
|
|
var forward = ( this.moveState.forward || ( this.autoForward && ! this.moveState.back ) ) ? 1 : 0;
|
|
|
|
|
|
- this.moveVector.x = ( - this.moveState.left + this.moveState.right );
|
|
|
- this.moveVector.y = ( - this.moveState.down + this.moveState.up );
|
|
|
+ this.moveVector.x = ( - this.moveState.left + this.moveState.right );
|
|
|
+ this.moveVector.y = ( - this.moveState.down + this.moveState.up );
|
|
|
this.moveVector.z = ( - forward + this.moveState.back );
|
|
|
|
|
|
//console.log( 'move:', [ this.moveVector.x, this.moveVector.y, this.moveVector.z ] );
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.updateRotationVector = function() {
|
|
|
+ this.updateRotationVector = function () {
|
|
|
|
|
|
this.rotationVector.x = ( - this.moveState.pitchDown + this.moveState.pitchUp );
|
|
|
- this.rotationVector.y = ( - this.moveState.yawRight + this.moveState.yawLeft );
|
|
|
+ this.rotationVector.y = ( - this.moveState.yawRight + this.moveState.yawLeft );
|
|
|
this.rotationVector.z = ( - this.moveState.rollRight + this.moveState.rollLeft );
|
|
|
|
|
|
//console.log( 'rotate:', [ this.rotationVector.x, this.rotationVector.y, this.rotationVector.z ] );
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.getContainerDimensions = function() {
|
|
|
+ this.getContainerDimensions = function () {
|
|
|
|
|
|
if ( this.domElement != document ) {
|
|
|
|
|
|
return {
|
|
|
- size : [ this.domElement.offsetWidth, this.domElement.offsetHeight ],
|
|
|
- offset : [ this.domElement.offsetLeft, this.domElement.offsetTop ]
|
|
|
+ size: [ this.domElement.offsetWidth, this.domElement.offsetHeight ],
|
|
|
+ offset: [ this.domElement.offsetLeft, this.domElement.offsetTop ]
|
|
|
};
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return {
|
|
|
- size : [ window.innerWidth, window.innerHeight ],
|
|
|
- offset : [ 0, 0 ]
|
|
|
+ size: [ window.innerWidth, window.innerHeight ],
|
|
|
+ offset: [ 0, 0 ]
|
|
|
};
|
|
|
|
|
|
}
|
|
@@ -260,7 +260,7 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.dispose = function() {
|
|
|
+ this.dispose = function () {
|
|
|
|
|
|
this.domElement.removeEventListener( 'contextmenu', contextmenu, false );
|
|
|
this.domElement.removeEventListener( 'mousedown', _mousedown, false );
|
|
@@ -282,10 +282,10 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
this.domElement.addEventListener( 'mousemove', _mousemove, false );
|
|
|
this.domElement.addEventListener( 'mousedown', _mousedown, false );
|
|
|
- this.domElement.addEventListener( 'mouseup', _mouseup, false );
|
|
|
+ this.domElement.addEventListener( 'mouseup', _mouseup, false );
|
|
|
|
|
|
window.addEventListener( 'keydown', _keydown, false );
|
|
|
- window.addEventListener( 'keyup', _keyup, false );
|
|
|
+ window.addEventListener( 'keyup', _keyup, false );
|
|
|
|
|
|
this.updateMovementVector();
|
|
|
this.updateRotationVector();
|