瀏覽代碼

Handle scales in camera matrices

Popov72 5 年之前
父節點
當前提交
b09bbb6b4b
共有 2 個文件被更改,包括 13 次插入11 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 12 11
      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
 

+ 12 - 11
src/Cameras/targetCamera.ts

@@ -424,23 +424,24 @@ export class TargetCamera extends Camera {
     }
 
     protected _computeViewMatrix(position: Vector3, target: Vector3, up: Vector3): void {
-        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._markSyncedWithParent();
-        } else {
-            this._globalPosition.copyFrom(position);
-            this._globalCurrentTarget.copyFrom(target);
-            this._globalCurrentUpVector.copyFrom(up);
-        }
+        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);
         }
+
+        if (this.parent) {
+            const parentWorldMatrix = this.parent.getWorldMatrix();
+            this._viewMatrix.invert();
+            this._viewMatrix.multiplyToRef(parentWorldMatrix, this._viewMatrix);
+            this._viewMatrix.getTranslationToRef(this._globalPosition);
+            this._viewMatrix.invert();
+            this._markSyncedWithParent();
+        }
     }
 
     /**