/
cameramodifier.ts
55 lines (40 loc) · 1.36 KB
/
cameramodifier.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* spellchecker: disable */
import { vec2 } from 'gl-matrix';
import { Camera } from './camera';
/* spellchecker: enable */
export abstract class CameraModifier {
/** @see {@link camera} */
protected _camera: Camera | undefined = undefined;
/**
* Copy of a camera for ongoing camera modifications based on previous/initial camera settings.
*/
protected _reference = new Camera();
/**
* Reference to the initial point starting the camera modification.
*/
protected _initialPoint: vec2;
/**
* Reference to the current point updating the camera modification.
*/
protected _currentPoint: vec2;
/**
* Should apply all previously calculated transformations to the camera set. Note that this does not invalidate the
* rendering. Invalidation of rendering is done by the event handler (triggering a rendering update which in turn
* checks if the camera was altered, and if so, redraws).
*/
abstract update(): void;
/**
* The camera that is to be modified in response to various events.
*/
set camera(camera: Camera | undefined) {
if (this._camera === camera) {
return;
}
this._camera = camera;
if (camera === undefined) {
return;
}
Object.assign(this._reference, camera);
this.update();
}
}