瀏覽代碼

ArcRotateCamera fix

new position will now be calculated correctly.
Raanan Weber 10 年之前
父節點
當前提交
75fbe66684
共有 2 個文件被更改,包括 16 次插入28 次删除
  1. 9 22
      Babylon/Cameras/babylon.arcRotateCamera.js
  2. 7 6
      Babylon/Cameras/babylon.arcRotateCamera.ts

+ 9 - 22
Babylon/Cameras/babylon.arcRotateCamera.js

@@ -1,4 +1,4 @@
-var __extends = (this && this.__extends) || function (d, b) {
+var __extends = this.__extends || function (d, b) {
     for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
     function __() { this.constructor = d; }
     __.prototype = b.prototype;
@@ -45,18 +45,17 @@ var BABYLON;
             this._newPosition = BABYLON.Vector3.Zero();
             this._onCollisionPositionChange = function (collisionId, newPosition, collidedMesh) {
                 if (collidedMesh === void 0) { collidedMesh = null; }
-                if (collisionId != null || collisionId != undefined)
+                if (_this.getScene().workerCollisions) {
                     newPosition.multiplyInPlace(_this._collider.radius);
-                if (newPosition.equalsWithEpsilon(_this.position)) {
+                }
+                if (!newPosition.equalsWithEpsilon(_this.position)) {
                     _this.position.copyFrom(_this._previousPosition);
                     _this.alpha = _this._previousAlpha;
                     _this.beta = _this._previousBeta;
                     _this.radius = _this._previousRadius;
                 }
-                else {
-                    if (_this.onCollide && collidedMesh) {
-                        _this.onCollide(collidedMesh);
-                    }
+                if (collidedMesh && _this.onCollide) {
+                    _this.onCollide(collidedMesh);
                 }
                 _this._collisionTriggered = false;
             };
@@ -91,11 +90,7 @@ var BABYLON;
         ArcRotateCamera.prototype._isSynchronizedViewMatrix = function () {
             if (!_super.prototype._isSynchronizedViewMatrix.call(this))
                 return false;
-            return this._cache.target.equals(this._getTargetPosition())
-                && this._cache.alpha === this.alpha
-                && this._cache.beta === this.beta
-                && this._cache.radius === this.radius
-                && this._cache.targetScreenOffset.equals(this.targetScreenOffset);
+            return this._cache.target.equals(this._getTargetPosition()) && this._cache.alpha === this.alpha && this._cache.beta === this.beta && this._cache.radius === this.radius && this._cache.targetScreenOffset.equals(this.targetScreenOffset);
         };
         // Methods
         ArcRotateCamera.prototype.attachControl = function (element, noPreventDefault) {
@@ -190,10 +185,7 @@ var BABYLON;
                     }
                 };
                 this._onKeyDown = function (evt) {
-                    if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
-                        _this.keysDown.indexOf(evt.keyCode) !== -1 ||
-                        _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
-                        _this.keysRight.indexOf(evt.keyCode) !== -1) {
+                    if (_this.keysUp.indexOf(evt.keyCode) !== -1 || _this.keysDown.indexOf(evt.keyCode) !== -1 || _this.keysLeft.indexOf(evt.keyCode) !== -1 || _this.keysRight.indexOf(evt.keyCode) !== -1) {
                         var index = _this._keys.indexOf(evt.keyCode);
                         if (index === -1) {
                             _this._keys.push(evt.keyCode);
@@ -206,10 +198,7 @@ var BABYLON;
                     }
                 };
                 this._onKeyUp = function (evt) {
-                    if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
-                        _this.keysDown.indexOf(evt.keyCode) !== -1 ||
-                        _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
-                        _this.keysRight.indexOf(evt.keyCode) !== -1) {
+                    if (_this.keysUp.indexOf(evt.keyCode) !== -1 || _this.keysDown.indexOf(evt.keyCode) !== -1 || _this.keysLeft.indexOf(evt.keyCode) !== -1 || _this.keysRight.indexOf(evt.keyCode) !== -1) {
                         var index = _this._keys.indexOf(evt.keyCode);
                         if (index >= 0) {
                             _this._keys.splice(index, 1);
@@ -300,7 +289,6 @@ var BABYLON;
             if (this._collisionTriggered) {
                 return;
             }
-            // Keyboard
             for (var index = 0; index < this._keys.length; index++) {
                 var keyCode = this._keys[index];
                 if (this.keysLeft.indexOf(keyCode) !== -1) {
@@ -433,4 +421,3 @@ var BABYLON;
     })(BABYLON.Camera);
     BABYLON.ArcRotateCamera = ArcRotateCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.arcRotateCamera.js.map

+ 7 - 6
Babylon/Cameras/babylon.arcRotateCamera.ts

@@ -454,19 +454,20 @@
 
         private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: AbstractMesh = null) => {
 
-            if (collisionId != null || collisionId != undefined)
+            if (this.getScene().workerCollisions) {
                 newPosition.multiplyInPlace(this._collider.radius);
+			}
 
-            if (newPosition.equalsWithEpsilon(this.position)) {
+            if (!newPosition.equalsWithEpsilon(this.position)) {
                 this.position.copyFrom(this._previousPosition);
 
                 this.alpha = this._previousAlpha;
                 this.beta = this._previousBeta;
                 this.radius = this._previousRadius;
-            } else {
-                if (this.onCollide && collidedMesh) {
-                    this.onCollide(collidedMesh);
-                }
+            } 
+			
+            if (collidedMesh && this.onCollide) {
+               this.onCollide(collidedMesh);
             }
 
             this._collisionTriggered = false;