-
-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathPerspectiveCamera.ts
More file actions
35 lines (29 loc) · 834 Bytes
/
PerspectiveCamera.ts
File metadata and controls
35 lines (29 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Mat4 from "../math/Mat4";
import MathUtils from "../math/MathUtils";
import Camera from "./Camera";
export default class PerspectiveCamera extends Camera {
public fov: number;
public near: number;
public far: number;
public aspect: number;
public constructor({fov, near, far, aspect}: {fov: number; near: number; far: number; aspect: number}) {
super();
this.fov = fov;
this.near = near;
this.far = far;
this.aspect = aspect;
this.updateProjectionMatrix();
}
public updateProjectionMatrix(): void {
this.projectionMatrix = Mat4.perspective(
MathUtils.toRad(this.fov / this.zoomFactor),
this.aspect,
this.near,
this.far
);
this.updateProjectionMatrixInverse();
}
public getFocalLength(sensorHeight: number): number {
return this.projectionMatrix.values[5] * sensorHeight / 2;
}
}