浏览代码

Merge pull request #9342 from nilss0n/arcrotatecamera-rebuild-angles-fix

Arcrotatecamera rebuild angles fix
David Catuhe 4 年之前
父节点
当前提交
f39e7a9c5b
共有 2 个文件被更改,包括 7 次插入0 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 6 0
      src/Cameras/arcRotateCamera.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -369,6 +369,7 @@
 - Fix issue when taking a screenshot with multi-cameras using method `CreateScreenshotUsingRenderTarget` ([#9201](https://github.com/BabylonJS/Babylon.js/issues/9201)) ([gabrielheming](https://github.com/gabrielheming))
 - Fix inTangent in animationGroup ([dad72](https://github.com/dad72))
 - Fixed bug in `QuadraticErrorSimplification` not correctly optimizing mesh. ([aWeirdo](https://github.com/aWeirdo))
+- Fixed bug in `ArcRotateCamera` where setting the position would recalculate the alpha value to a value outside the current limits. ([nilss0n](https://github.com/nilss0n))
 
 ## Breaking changes
 

+ 6 - 0
src/Cameras/arcRotateCamera.ts

@@ -985,6 +985,7 @@ export class ArcRotateCamera extends TargetCamera {
         }
 
         // Alpha
+        const previousAlpha = this.alpha;
         if (this._computationVector.x === 0 && this._computationVector.z === 0) {
             this.alpha = Math.PI / 2; // avoid division by zero when looking along up axis, and set to acos(0)
         } else {
@@ -995,6 +996,11 @@ export class ArcRotateCamera extends TargetCamera {
             this.alpha = 2 * Math.PI - this.alpha;
         }
 
+        // Calculate the number of revolutions between the new and old alpha values.
+        const alphaCorrectionTurns = Math.round((previousAlpha - this.alpha) / (2.0 * Math.PI));
+        // Adjust alpha so that its numerical representation is the closest one to the old value.
+        this.alpha += alphaCorrectionTurns * 2.0 * Math.PI;
+
         // Beta
         this.beta = Math.acos(this._computationVector.y / this.radius);