瀏覽代碼

Add PerspectiveView._projectionMatrixInverse

customisations
alemart 10 月之前
父節點
當前提交
c0da88e2b8
共有 1 個檔案被更改,包括 20 行新增0 行删除
  1. 20
    0
      src/geometry/view.ts

+ 20
- 0
src/geometry/view.ts 查看文件

25
 import { SpeedyMatrix } from 'speedy-vision/types/core/speedy-matrix';
25
 import { SpeedyMatrix } from 'speedy-vision/types/core/speedy-matrix';
26
 import { CameraModel, FX, FY, U0, V0 } from './camera-model';
26
 import { CameraModel, FX, FY, U0, V0 } from './camera-model';
27
 import { IllegalArgumentError } from '../utils/errors';
27
 import { IllegalArgumentError } from '../utils/errors';
28
+import { Nullable } from '../utils/utils';
28
 
29
 
29
 /** Default distance in pixels of the near plane to the optical center of the camera */
30
 /** Default distance in pixels of the near plane to the optical center of the camera */
30
 const DEFAULT_NEAR = 1;
31
 const DEFAULT_NEAR = 1;
42
 {
43
 {
43
     /** A 4x4 matrix that projects the viewer space into the clip space, i.e., [-1,1]^3 */
44
     /** A 4x4 matrix that projects the viewer space into the clip space, i.e., [-1,1]^3 */
44
     readonly projectionMatrix: SpeedyMatrix;
45
     readonly projectionMatrix: SpeedyMatrix;
46
+
47
+    /** @internal The inverse of the projection matrix */
48
+    readonly _projectionMatrixInverse: SpeedyMatrix;
45
 }
49
 }
46
 
50
 
47
 /**
51
 /**
53
     /** A 4x4 matrix that projects the viewer space into the clip space, i.e., [-1,1]^3 */
57
     /** A 4x4 matrix that projects the viewer space into the clip space, i.e., [-1,1]^3 */
54
     private readonly _projectionMatrix: SpeedyMatrix;
58
     private readonly _projectionMatrix: SpeedyMatrix;
55
 
59
 
60
+    /** The inverse of the projection matrix, computed lazily */
61
+    private _inverseProjection: Nullable<SpeedyMatrix>;
62
+
56
     /** Tangent of the half of the horizontal field-of-view */
63
     /** Tangent of the half of the horizontal field-of-view */
57
     private readonly _tanOfHalfFovx: number;
64
     private readonly _tanOfHalfFovx: number;
58
 
65
 
92
         this._tanOfHalfFovx = intrinsics[U0] / intrinsics[FX];
99
         this._tanOfHalfFovx = intrinsics[U0] / intrinsics[FX];
93
         this._tanOfHalfFovy = intrinsics[V0] / intrinsics[FY];
100
         this._tanOfHalfFovy = intrinsics[V0] / intrinsics[FY];
94
         this._projectionMatrix = PerspectiveView._computeProjectionMatrix(intrinsics, this._near, this._far);
101
         this._projectionMatrix = PerspectiveView._computeProjectionMatrix(intrinsics, this._near, this._far);
102
+        this._inverseProjection = null;
95
     }
103
     }
96
 
104
 
97
     /**
105
     /**
143
     }
151
     }
144
 
152
 
145
     /**
153
     /**
154
+     * The inverse of the projection matrix
155
+     * @internal
156
+     */
157
+    get _projectionMatrixInverse(): SpeedyMatrix
158
+    {
159
+        if(this._inverseProjection === null)
160
+            this._inverseProjection = Speedy.Matrix(this._projectionMatrix.inverse());
161
+
162
+        return this._inverseProjection;
163
+    }
164
+
165
+    /**
146
      * Compute a perspective projection matrix for WebGL
166
      * Compute a perspective projection matrix for WebGL
147
      * @param K camera intrinsics
167
      * @param K camera intrinsics
148
      * @param near distance of the near plane
168
      * @param near distance of the near plane

Loading…
取消
儲存