Skip to content

Commit 3faa6b6

Browse files
committed
Merge remote-tracking branch 'RommelVR/master' into dev
2 parents 675d9f2 + 8c53e15 commit 3faa6b6

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

examples/js/controls/FirstPersonControls.js

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -187,59 +187,42 @@ THREE.FirstPersonControls = function ( object, domElement ) {
187187
};
188188

189189
this.update = function( delta ) {
190-
var actualMoveSpeed = 0;
191190

192191
if ( this.freeze ) {
193192

194193
return;
195194

196-
} else {
197-
198-
if ( this.heightSpeed ) {
199-
200-
var y = THREE.Math.clamp( this.object.position.y, this.heightMin, this.heightMax );
201-
var heightDelta = y - this.heightMin;
202-
203-
this.autoSpeedFactor = delta * ( heightDelta * this.heightCoef );
204-
205-
} else {
206-
207-
this.autoSpeedFactor = 0.0;
195+
}
208196

209-
}
197+
if ( this.heightSpeed ) {
210198

211-
actualMoveSpeed = delta * this.movementSpeed;
199+
var y = THREE.Math.clamp( this.object.position.y, this.heightMin, this.heightMax );
200+
var heightDelta = y - this.heightMin;
212201

213-
if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
214-
if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );
202+
this.autoSpeedFactor = delta * ( heightDelta * this.heightCoef );
215203

216-
if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
217-
if ( this.moveRight ) this.object.translateX( actualMoveSpeed );
204+
} else {
218205

219-
if ( this.moveUp ) this.object.translateY( actualMoveSpeed );
220-
if ( this.moveDown ) this.object.translateY( - actualMoveSpeed );
206+
this.autoSpeedFactor = 0.0;
221207

222-
var actualLookSpeed = delta * this.lookSpeed;
208+
}
223209

224-
if ( !this.activeLook ) {
210+
var actualMoveSpeed = delta * this.movementSpeed;
225211

226-
actualLookSpeed = 0;
212+
if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
213+
if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );
227214

228-
}
215+
if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
216+
if ( this.moveRight ) this.object.translateX( actualMoveSpeed );
229217

230-
this.lon += this.mouseX * actualLookSpeed;
231-
if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed; // * this.invertVertical?-1:1;
218+
if ( this.moveUp ) this.object.translateY( actualMoveSpeed );
219+
if ( this.moveDown ) this.object.translateY( - actualMoveSpeed );
232220

233-
this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
234-
this.phi = THREE.Math.degToRad( 90 - this.lat );
235-
this.theta = THREE.Math.degToRad( this.lon );
221+
var actualLookSpeed = delta * this.lookSpeed;
236222

237-
var targetPosition = this.target,
238-
position = this.object.position;
223+
if ( !this.activeLook ) {
239224

240-
targetPosition.x = position.x + 100 * Math.sin( this.phi ) * Math.cos( this.theta );
241-
targetPosition.y = position.y + 100 * Math.cos( this.phi );
242-
targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
225+
actualLookSpeed = 0;
243226

244227
}
245228

0 commit comments

Comments
 (0)