|
@@ -26,6 +26,10 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
// internals
|
|
// internals
|
|
|
|
|
|
|
|
+ var scope = this;
|
|
|
|
+ var changeEvent = { type: "change" };
|
|
|
|
+ var EPS = 0.000001;
|
|
|
|
+
|
|
this.tmpQuaternion = new THREE.Quaternion();
|
|
this.tmpQuaternion = new THREE.Quaternion();
|
|
|
|
|
|
this.mouseStatus = 0;
|
|
this.mouseStatus = 0;
|
|
@@ -179,23 +183,40 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
- this.update = function ( delta ) {
|
|
|
|
|
|
+ this.update = function () {
|
|
|
|
|
|
- var moveMult = delta * this.movementSpeed;
|
|
|
|
- var rotMult = delta * this.rollSpeed;
|
|
|
|
|
|
+ var lastQuaternion = new THREE.Quaternion();
|
|
|
|
+ var lastPosition = new THREE.Vector3();
|
|
|
|
|
|
- this.object.translateX( this.moveVector.x * moveMult );
|
|
|
|
- this.object.translateY( this.moveVector.y * moveMult );
|
|
|
|
- this.object.translateZ( this.moveVector.z * moveMult );
|
|
|
|
|
|
+ return function ( delta ) {
|
|
|
|
|
|
- this.tmpQuaternion.set( this.rotationVector.x * rotMult, this.rotationVector.y * rotMult, this.rotationVector.z * rotMult, 1 ).normalize();
|
|
|
|
- this.object.quaternion.multiply( this.tmpQuaternion );
|
|
|
|
|
|
+ var moveMult = delta * scope.movementSpeed;
|
|
|
|
+ var rotMult = delta * scope.rollSpeed;
|
|
|
|
|
|
- // expose the rotation vector for convenience
|
|
|
|
- this.object.rotation.setFromQuaternion( this.object.quaternion, this.object.rotation.order );
|
|
|
|
|
|
+ scope.object.translateX( scope.moveVector.x * moveMult );
|
|
|
|
+ scope.object.translateY( scope.moveVector.y * moveMult );
|
|
|
|
+ scope.object.translateZ( scope.moveVector.z * moveMult );
|
|
|
|
|
|
|
|
+ scope.tmpQuaternion.set( scope.rotationVector.x * rotMult, scope.rotationVector.y * rotMult, scope.rotationVector.z * rotMult, 1 ).normalize();
|
|
|
|
+ scope.object.quaternion.multiply( scope.tmpQuaternion );
|
|
|
|
|
|
- };
|
|
|
|
|
|
+ // expose the rotation vector for convenience
|
|
|
|
+ scope.object.rotation.setFromQuaternion( scope.object.quaternion, scope.object.rotation.order );
|
|
|
|
+
|
|
|
|
+ if (
|
|
|
|
+ lastPosition.distanceToSquared( scope.object.position ) > EPS ||
|
|
|
|
+ 8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS
|
|
|
|
+ ) {
|
|
|
|
+
|
|
|
|
+ scope.dispatchEvent( changeEvent );
|
|
|
|
+ lastQuaternion.copy( scope.object.quaternion );
|
|
|
|
+ lastPosition.copy( scope.object.position );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ }();
|
|
|
|
|
|
this.updateMovementVector = function () {
|
|
this.updateMovementVector = function () {
|
|
|
|
|
|
@@ -286,3 +307,6 @@ THREE.FlyControls = function ( object, domElement ) {
|
|
this.updateRotationVector();
|
|
this.updateRotationVector();
|
|
|
|
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+THREE.FlyControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
|
|
|
+THREE.FlyControls.prototype.constructor = THREE.FlyControls;
|