Просмотр исходного кода

Introduce PerspectiveView.fovx

customisations
alemart 11 месяцев назад
Родитель
Сommit
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,6 +10,14 @@ A [View](view.md) that models a perspective projection.
10 10
 
11 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 21
 ### fovy
14 22
 
15 23
 `view.fovy: number, read-only`

+ 12
- 0
src/geometry/view.ts Просмотреть файл

@@ -53,6 +53,9 @@ export class PerspectiveView implements View
53 53
     /** A 4x4 matrix that projects the viewer space into the clip space, i.e., [-1,1]^3 */
54 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 59
     /** Tangent of the half of the vertical field-of-view */
57 60
     private readonly _tanOfHalfFovy: number;
58 61
 
@@ -86,6 +89,7 @@ export class PerspectiveView implements View
86 89
             throw new IllegalArgumentError(`View expects near < far (found near = ${this._near} and far = ${this._far})`);
87 90
 
88 91
         this._aspect = screenSize.width / screenSize.height;
92
+        this._tanOfHalfFovx = intrinsics[U0] / intrinsics[FX];
89 93
         this._tanOfHalfFovy = intrinsics[V0] / intrinsics[FY];
90 94
         this._projectionMatrix = PerspectiveView._computeProjectionMatrix(intrinsics, this._near, this._far);
91 95
     }
@@ -107,6 +111,14 @@ export class PerspectiveView implements View
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 122
      * Vertical field-of-view of the frustum, measured in radians
111 123
      */
112 124
     get fovy(): number

Загрузка…
Отмена
Сохранить