Преглед изворни кода

Add PerspectiveView._projectionMatrixInverse

customisations
alemart пре 10 месеци
родитељ
комит
c0da88e2b8
1 измењених фајлова са 20 додато и 0 уклоњено
  1. 20
    0
      src/geometry/view.ts

+ 20
- 0
src/geometry/view.ts Прегледај датотеку

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

Loading…
Откажи
Сачувај