瀏覽代碼

Merge pull request #8303 from Popov72/handle-scale-in-camera-matrix

Handle scales in camera matrices
David Catuhe 5 年之前
父節點
當前提交
cf19c29b7c
共有 2 個文件被更改,包括 11 次插入14 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 10 14
      src/Cameras/targetCamera.ts

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

@@ -65,6 +65,7 @@
 - handle reattachment of panning button for `ArcRotateCamera` ([cedricguillemet](https://github.com/cedricguillemet))
 - Added flag to TargetCamera to invert rotation direction and multiplier to adjust speed ([Exolun](https://github.com/Exolun))
 - Added upwards and downwards keyboard input to `FreeCamera` ([Pheater](https://github.com/pheater))
+- Handle scales in camera matrices ([Popov72](https://github.com/Popov72))
 
 ### Sprites
 

+ 10 - 14
src/Cameras/targetCamera.ts

@@ -87,9 +87,6 @@ export class TargetCamera extends Camera {
     /** @hidden */
     public _transformedReferencePoint = Vector3.Zero();
 
-    protected _globalCurrentTarget = Vector3.Zero();
-    protected _globalCurrentUpVector = Vector3.Zero();
-
     /** @hidden */
     public _reset: () => void;
 
@@ -424,22 +421,21 @@ export class TargetCamera extends Camera {
     }
 
     protected _computeViewMatrix(position: Vector3, target: Vector3, up: Vector3): void {
+        if (this.getScene().useRightHandedSystem) {
+            Matrix.LookAtRHToRef(position, target, up, this._viewMatrix);
+        } else {
+            Matrix.LookAtLHToRef(position, target, up, this._viewMatrix);
+        }
+
         if (this.parent) {
             const parentWorldMatrix = this.parent.getWorldMatrix();
-            Vector3.TransformCoordinatesToRef(position, parentWorldMatrix, this._globalPosition);
-            Vector3.TransformCoordinatesToRef(target, parentWorldMatrix, this._globalCurrentTarget);
-            Vector3.TransformNormalToRef(up, parentWorldMatrix, this._globalCurrentUpVector);
+            this._viewMatrix.invert();
+            this._viewMatrix.multiplyToRef(parentWorldMatrix, this._viewMatrix);
+            this._viewMatrix.getTranslationToRef(this._globalPosition);
+            this._viewMatrix.invert();
             this._markSyncedWithParent();
         } else {
             this._globalPosition.copyFrom(position);
-            this._globalCurrentTarget.copyFrom(target);
-            this._globalCurrentUpVector.copyFrom(up);
-        }
-
-        if (this.getScene().useRightHandedSystem) {
-            Matrix.LookAtRHToRef(this._globalPosition, this._globalCurrentTarget, this._globalCurrentUpVector, this._viewMatrix);
-        } else {
-            Matrix.LookAtLHToRef(this._globalPosition, this._globalCurrentTarget, this._globalCurrentUpVector, this._viewMatrix);
         }
     }