Browse Source

Merge remote-tracking branch 'RommelVR/master' into dev

Mr.doob 12 years ago
parent
commit
3faa6b6248
1 changed files with 18 additions and 35 deletions
  1. 18 35
      examples/js/controls/FirstPersonControls.js

+ 18 - 35
examples/js/controls/FirstPersonControls.js

@@ -187,59 +187,42 @@ THREE.FirstPersonControls = function ( object, domElement ) {
 	};
 
 	this.update = function( delta ) {
-		var actualMoveSpeed = 0;
 
 		if ( this.freeze ) {
 
 			return;
 
-		} else {
-
-			if ( this.heightSpeed ) {
-
-				var y = THREE.Math.clamp( this.object.position.y, this.heightMin, this.heightMax );
-				var heightDelta = y - this.heightMin;
-
-				this.autoSpeedFactor = delta * ( heightDelta * this.heightCoef );
-
-			} else {
-
-				this.autoSpeedFactor = 0.0;
+		}
 
-			}
+		if ( this.heightSpeed ) {
 
-			actualMoveSpeed = delta * this.movementSpeed;
+			var y = THREE.Math.clamp( this.object.position.y, this.heightMin, this.heightMax );
+			var heightDelta = y - this.heightMin;
 
-			if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
-			if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );
+			this.autoSpeedFactor = delta * ( heightDelta * this.heightCoef );
 
-			if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
-			if ( this.moveRight ) this.object.translateX( actualMoveSpeed );
+		} else {
 
-			if ( this.moveUp ) this.object.translateY( actualMoveSpeed );
-			if ( this.moveDown ) this.object.translateY( - actualMoveSpeed );
+			this.autoSpeedFactor = 0.0;
 
-			var actualLookSpeed = delta * this.lookSpeed;
+		}
 
-			if ( !this.activeLook ) {
+		var actualMoveSpeed = delta * this.movementSpeed;
 
-				actualLookSpeed = 0;
+		if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
+		if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );
 
-			}
+		if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
+		if ( this.moveRight ) this.object.translateX( actualMoveSpeed );
 
-			this.lon += this.mouseX * actualLookSpeed;
-			if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed; // * this.invertVertical?-1:1;
+		if ( this.moveUp ) this.object.translateY( actualMoveSpeed );
+		if ( this.moveDown ) this.object.translateY( - actualMoveSpeed );
 
-			this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
-			this.phi = THREE.Math.degToRad( 90 - this.lat );
-			this.theta = THREE.Math.degToRad( this.lon );
+		var actualLookSpeed = delta * this.lookSpeed;
 
-			var targetPosition = this.target,
-				position = this.object.position;
+		if ( !this.activeLook ) {
 
-			targetPosition.x = position.x + 100 * Math.sin( this.phi ) * Math.cos( this.theta );
-			targetPosition.y = position.y + 100 * Math.cos( this.phi );
-			targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
+			actualLookSpeed = 0;
 
 		}