-
Notifications
You must be signed in to change notification settings - Fork 192
/
Projector.ts
39 lines (23 loc) · 1007 Bytes
/
Projector.ts
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
import type { Vector3 } from '../math';
import type { Camera } from '../Camera';
import { Matrix4 } from '../math';
const viewProjectionMatrix = new Matrix4();
//$3Dmol Projection
export class Projector {
static unprojectVector(vector: Vector3, camera: Camera) {
camera.projectionMatrixInverse.getInverse(camera.projectionMatrix);
viewProjectionMatrix.multiplyMatrices(camera.matrixWorld, camera.projectionMatrixInverse);
return vector.applyProjection(viewProjectionMatrix);
};
static projectVector(vector: Vector3, camera: Camera) {
camera.matrixWorldInverse.getInverse(camera.matrixWorld);
viewProjectionMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
return vector.applyProjection(viewProjectionMatrix);
};
projectVector(vector: Vector3, camera: Camera) {
return Projector.projectVector(vector, camera);
}
unprojectVector(vector: Vector3, camera: Camera) {
return Projector.unprojectVector(vector, camera);
}
}