Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | import type { Quaternion } from "./math"; import { Object3D } from "./core"; import { Matrix4, Vector3 } from "./math"; /* * Simplified Perspective Camera */ /** @constructor */ export class Camera extends Object3D { projectionMatrix = new Matrix4(); projectionMatrixInverse = new Matrix4(); matrixWorldInverse = new Matrix4(); right: number; left: number; top: number; bottom: number; ortho: boolean; fov: number; aspect: number; near: number; far: number; z: number; constructor(fov = 50, aspect = 1, near = 0.1, far = 2000, ortho = false) { super(); this.fov = fov; this.aspect = aspect; this.near = near; this.far = far; var center = this.position.z; this.right = center * Math.tan((Math.PI / 180) * fov); this.left = -this.right; this.top = this.right / this.aspect; this.bottom = -this.top; this.ortho = !!ortho; this.updateProjectionMatrix(); } lookAt(vector: Vector3) { //Why is the parameter order switched (compared to Object3D)? this.matrix.lookAt(this.position, vector, this.up); Iif (this.rotationAutoUpdate) { if (this.useQuaternion === false && this.rotation instanceof Vector3) { this.rotation.setEulerFromRotationMatrix(this.matrix, this.eulerOrder); } else { this.quaternion.copy(this.matrix.decompose()[1] as Quaternion); } } } updateProjectionMatrix() { if (this.ortho) { this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far ); } else { this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far ); } this.projectionMatrixInverse.getInverse(this.projectionMatrix); } } |