瀏覽代碼

Introduce PerspectiveView.fovx

customisations
alemart 11 月之前
父節點
當前提交
cbabbe53e2
共有 2 個檔案被更改,包括 20 行新增0 行删除
  1. 8
    0
      docs/api/perspective-view.md
  2. 12
    0
      src/geometry/view.ts

+ 8
- 0
docs/api/perspective-view.md 查看文件

10
 
10
 
11
 Aspect ratio of the viewing frustum.
11
 Aspect ratio of the viewing frustum.
12
 
12
 
13
+### fovx
14
+
15
+`view.fovx: number, read-only`
16
+
17
+Horizontal field-of-view of the viewing frustum, measured in radians.
18
+
19
+*Since:* 0.3.0
20
+
13
 ### fovy
21
 ### fovy
14
 
22
 
15
 `view.fovy: number, read-only`
23
 `view.fovy: number, read-only`

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

53
     /** A 4x4 matrix that projects the viewer space into the clip space, i.e., [-1,1]^3 */
53
     /** A 4x4 matrix that projects the viewer space into the clip space, i.e., [-1,1]^3 */
54
     private readonly _projectionMatrix: SpeedyMatrix;
54
     private readonly _projectionMatrix: SpeedyMatrix;
55
 
55
 
56
+    /** Tangent of the half of the horizontal field-of-view */
57
+    private readonly _tanOfHalfFovx: number;
58
+
56
     /** Tangent of the half of the vertical field-of-view */
59
     /** Tangent of the half of the vertical field-of-view */
57
     private readonly _tanOfHalfFovy: number;
60
     private readonly _tanOfHalfFovy: number;
58
 
61
 
86
             throw new IllegalArgumentError(`View expects near < far (found near = ${this._near} and far = ${this._far})`);
89
             throw new IllegalArgumentError(`View expects near < far (found near = ${this._near} and far = ${this._far})`);
87
 
90
 
88
         this._aspect = screenSize.width / screenSize.height;
91
         this._aspect = screenSize.width / screenSize.height;
92
+        this._tanOfHalfFovx = intrinsics[U0] / intrinsics[FX];
89
         this._tanOfHalfFovy = intrinsics[V0] / intrinsics[FY];
93
         this._tanOfHalfFovy = intrinsics[V0] / intrinsics[FY];
90
         this._projectionMatrix = PerspectiveView._computeProjectionMatrix(intrinsics, this._near, this._far);
94
         this._projectionMatrix = PerspectiveView._computeProjectionMatrix(intrinsics, this._near, this._far);
91
     }
95
     }
107
     }
111
     }
108
 
112
 
109
     /**
113
     /**
114
+     * Horizontal field-of-view of the frustum, measured in radians
115
+     */
116
+    get fovx(): number
117
+    {
118
+        return 2 * Math.atan(this._tanOfHalfFovx);
119
+    }
120
+
121
+    /**
110
      * Vertical field-of-view of the frustum, measured in radians
122
      * Vertical field-of-view of the frustum, measured in radians
111
      */
123
      */
112
     get fovy(): number
124
     get fovy(): number

Loading…
取消
儲存