Bladeren bron

Fixed detachControl bug for FreeCameraMouseInput

David Catuhe 9 jaren geleden
bovenliggende
commit
d9b1906586

File diff suppressed because it is too large
+ 11 - 11
dist/preview release/babylon.core.js


File diff suppressed because it is too large
+ 1786 - 1785
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 19 - 19
dist/preview release/babylon.js


+ 8 - 8
dist/preview release/babylon.max.js

@@ -11275,12 +11275,11 @@ var BABYLON;
         }
         FreeCameraMouseInput.prototype.attachControl = function (element, noPreventDefault) {
             var _this = this;
-            var previousPosition;
             if (this._onMouseDown === undefined) {
                 var camera = this.camera;
                 var engine = this.camera.getEngine();
                 this._onMouseDown = function (evt) {
-                    previousPosition = {
+                    _this.previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
@@ -11289,26 +11288,26 @@ var BABYLON;
                     }
                 };
                 this._onMouseUp = function (evt) {
-                    previousPosition = null;
+                    _this.previousPosition = null;
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
                 this._onMouseOut = function (evt) {
-                    previousPosition = null;
+                    _this.previousPosition = null;
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
                 this._onMouseMove = function (evt) {
-                    if (!previousPosition && !engine.isPointerLock) {
+                    if (!_this.previousPosition && !engine.isPointerLock) {
                         return;
                     }
                     var offsetX;
                     var offsetY;
                     if (!engine.isPointerLock) {
-                        offsetX = evt.clientX - previousPosition.x;
-                        offsetY = evt.clientY - previousPosition.y;
+                        offsetX = evt.clientX - _this.previousPosition.x;
+                        offsetY = evt.clientY - _this.previousPosition.y;
                     }
                     else {
                         offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
@@ -11316,7 +11315,7 @@ var BABYLON;
                     }
                     camera.cameraRotation.y += offsetX / _this.angularSensibility;
                     camera.cameraRotation.x += offsetY / _this.angularSensibility;
-                    previousPosition = {
+                    _this.previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
@@ -11332,6 +11331,7 @@ var BABYLON;
         };
         FreeCameraMouseInput.prototype.detachControl = function (element) {
             if (this._onMouseDown && element) {
+                this.previousPosition = null;
                 element.removeEventListener("mousedown", this._onMouseDown);
                 element.removeEventListener("mouseup", this._onMouseUp);
                 element.removeEventListener("mouseout", this._onMouseOut);

File diff suppressed because it is too large
+ 11 - 11
dist/preview release/babylon.noworker.js


+ 8 - 8
src/Cameras/Inputs/babylon.freecamera.input.mouse.js

@@ -12,12 +12,11 @@ var BABYLON;
         }
         FreeCameraMouseInput.prototype.attachControl = function (element, noPreventDefault) {
             var _this = this;
-            var previousPosition;
             if (this._onMouseDown === undefined) {
                 var camera = this.camera;
                 var engine = this.camera.getEngine();
                 this._onMouseDown = function (evt) {
-                    previousPosition = {
+                    _this.previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
@@ -26,26 +25,26 @@ var BABYLON;
                     }
                 };
                 this._onMouseUp = function (evt) {
-                    previousPosition = null;
+                    _this.previousPosition = null;
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
                 this._onMouseOut = function (evt) {
-                    previousPosition = null;
+                    _this.previousPosition = null;
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
                 this._onMouseMove = function (evt) {
-                    if (!previousPosition && !engine.isPointerLock) {
+                    if (!_this.previousPosition && !engine.isPointerLock) {
                         return;
                     }
                     var offsetX;
                     var offsetY;
                     if (!engine.isPointerLock) {
-                        offsetX = evt.clientX - previousPosition.x;
-                        offsetY = evt.clientY - previousPosition.y;
+                        offsetX = evt.clientX - _this.previousPosition.x;
+                        offsetY = evt.clientY - _this.previousPosition.y;
                     }
                     else {
                         offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
@@ -53,7 +52,7 @@ var BABYLON;
                     }
                     camera.cameraRotation.y += offsetX / _this.angularSensibility;
                     camera.cameraRotation.x += offsetY / _this.angularSensibility;
-                    previousPosition = {
+                    _this.previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
@@ -69,6 +68,7 @@ var BABYLON;
         };
         FreeCameraMouseInput.prototype.detachControl = function (element) {
             if (this._onMouseDown && element) {
+                this.previousPosition = null;
                 element.removeEventListener("mousedown", this._onMouseDown);
                 element.removeEventListener("mouseup", this._onMouseUp);
                 element.removeEventListener("mouseout", this._onMouseOut);

+ 12 - 12
src/Cameras/Inputs/babylon.freecamera.input.mouse.ts

@@ -9,16 +9,15 @@ module BABYLON {
         private _onMouseUp: (e: MouseEvent) => any;
         private _onMouseOut: (e: MouseEvent) => any;
         private _onMouseMove: (e: MouseEvent) => any;
-        
-        attachControl(element: HTMLElement, noPreventDefault?: boolean){     
-            var previousPosition;
-                
+        private previousPosition: { x: number, y: number };
+
+        attachControl(element: HTMLElement, noPreventDefault?: boolean){                     
             if (this._onMouseDown === undefined) {
                 var camera = this.camera;
                 var engine = this.camera.getEngine();
                 
                 this._onMouseDown = evt => {
-                    previousPosition = {
+                    this.previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
@@ -29,14 +28,14 @@ module BABYLON {
                 };
 
                 this._onMouseUp = evt => {
-                    previousPosition = null;
+                    this.previousPosition = null;
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
 
                 this._onMouseOut = evt => {
-                    previousPosition = null;
+                    this.previousPosition = null;
                     
                     if (!noPreventDefault) {
                         evt.preventDefault();
@@ -44,7 +43,7 @@ module BABYLON {
                 };
 
                 this._onMouseMove = evt => {
-                    if (!previousPosition && !engine.isPointerLock) {
+                    if (!this.previousPosition && !engine.isPointerLock) {
                         return;
                     }
 
@@ -52,8 +51,8 @@ module BABYLON {
                     var offsetY;
 
                     if (!engine.isPointerLock) {
-                        offsetX = evt.clientX - previousPosition.x;
-                        offsetY = evt.clientY - previousPosition.y;
+                        offsetX = evt.clientX - this.previousPosition.x;
+                        offsetY = evt.clientY - this.previousPosition.y;
                     } else {
                         offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
                         offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
@@ -62,7 +61,7 @@ module BABYLON {
                     camera.cameraRotation.y += offsetX / this.angularSensibility;
                     camera.cameraRotation.x += offsetY / this.angularSensibility;
 
-                    previousPosition = {
+                    this.previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
@@ -81,7 +80,8 @@ module BABYLON {
         }
         
         detachControl(element : HTMLElement){   
-            if (this._onMouseDown && element){
+            if (this._onMouseDown && element) {
+                this.previousPosition = null;
                 element.removeEventListener("mousedown", this._onMouseDown);
                 element.removeEventListener("mouseup", this._onMouseUp);
                 element.removeEventListener("mouseout", this._onMouseOut);