瀏覽代碼

Merge pull request #214 from kostar111/master

ArcRotateCamera - fix setPosition() error
deltakosh 11 年之前
父節點
當前提交
1ac0da154c
共有 2 個文件被更改,包括 21 次插入3 次删除
  1. 10 1
      Babylon/Cameras/babylon.arcRotateCamera.js
  2. 11 2
      Babylon/Cameras/babylon.arcRotateCamera.ts

+ 10 - 1
Babylon/Cameras/babylon.arcRotateCamera.js

@@ -344,7 +344,16 @@ var BABYLON;
             var radiusv3 = position.subtract(this._getTargetPosition());
             var radiusv3 = position.subtract(this._getTargetPosition());
             this.radius = radiusv3.length();
             this.radius = radiusv3.length();
 
 
-            this.alpha = Math.atan(radiusv3.z / radiusv3.x);
+            // Alpha
+            this.alpha = Math.acos(radiusv3.x / Math.sqrt(
+                Math.pow(radiusv3.x, 2) +
+                Math.pow(radiusv3.z, 2)
+            ));
+            if (radiusv3.z < 0) {
+                this.alpha = 2 * Math.PI - this.alpha;
+            }
+
+            // Beta
             this.beta = Math.acos(radiusv3.y / this.radius);
             this.beta = Math.acos(radiusv3.y / this.radius);
         };
         };
 
 

+ 11 - 2
Babylon/Cameras/babylon.arcRotateCamera.ts

@@ -362,7 +362,16 @@
             var radiusv3 = position.subtract(this._getTargetPosition());
             var radiusv3 = position.subtract(this._getTargetPosition());
             this.radius = radiusv3.length();
             this.radius = radiusv3.length();
 
 
-            this.alpha = Math.atan(radiusv3.z / radiusv3.x);
+            // Alpha
+            this.alpha = Math.acos(radiusv3.x / Math.sqrt(
+                Math.pow(radiusv3.x, 2) +
+                Math.pow(radiusv3.z, 2)
+            ));
+            if (radiusv3.z < 0) {
+                this.alpha = 2 * Math.PI - this.alpha;
+            }
+
+            // Beta
             this.beta = Math.acos(radiusv3.y / this.radius);
             this.beta = Math.acos(radiusv3.y / this.radius);
         }
         }
 
 
@@ -411,4 +420,4 @@
             this.maxZ = distance * 2;
             this.maxZ = distance * 2;
         }
         }
     }
     }
-} 
+}