/
ICustomCameraControls.ts
166 lines (159 loc) · 5.68 KB
/
ICustomCameraControls.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { LngLatAlt } from "../../api/interfaces/LngLatAlt";
import { IViewer } from "./IViewer";
/**
* @interface
*
* @description Interface for custom camera controls.
* This is a specification for implementers to model:
* it is not an exported method or class.
*
* Custom camera controls allow the API user to freely
* move the viewer's camera and define the camera
* projection used. These camera properties are used
* to render the viewer 3D scene directly into the
* viewer's GL context.
*
* Custom camera controls must implement the
* onActivate, onAnimationFrame, onAttach, onDeactivate,
* onDetach, onReference, and onResize methods.
*
* Custom camera controls trigger rerendering
* automatically when the camera pose or projection
* is changed through the projectionMatrix and
* viewMatrix callbacks.
*
* See the
* [model view projection article]{@link https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_model_view_projection}
* on MDN for an introduction to view and projection matrices.
*
* Custom camera controls can choose to make updates on
* each animation frame or only based on user input.
* Invoking updates on each camera frame is more resource
* intensive.
*
* Only a single custom camera control instance can be
* attached to the viewer at any given time.
*/
export interface ICustomCameraControls {
/**
* Method called when the camera controls have been
* activated and is responsible for moving the
* viewer's camera and defining its projection. This
* method gives the camera controls a chance to initialize
* resources, perform any transitions, and determine
* initial state.
*
* @description Use the {@link Viewer.getContainer} method
* to get the container for determining the viewer size
* and aspect as well as for attaching event handlers.
*
* Use the view matrix to determine initial properties such
* as camera position, forward vector, and up vector.
*
* Use the projection matrix to determine the initial
* projection properties.
*
* Store the reference coordiante translations
* during future reference reference changes.
*
* @param {IViewer} viewer - The viewer this custom
* camera controls instance was just added to.
* @param {Array<number>} viewMatrix - The viewer's view matrix.
* @param {Array<number>} projectionMatrix - The viewers's
* projection matrix.
* @param {LngLatAlt} reference - The viewer's reference.
*/
onActivate(
viewer: IViewer,
viewMatrix: number[],
projectionMatrix: number[],
reference: LngLatAlt): void;
/**
* Method called for each animation frame.
*
* @desdcription Custom camera controls can choose to
* make updates on each animation frame or only based on
* user input. Invoking updates on each animation frame is
* more resource intensive.
*
* @param {IViewer} viewer - The viewer this custom
* camera controls instance is attached to.
*
* @param {number} frameId - The request animation frame's id.
*/
onAnimationFrame(
viewer: IViewer,
frameId: number): void;
/**
* Method called when the camera controls have been
* attached to the viewer.
* This gives the camera controls a chance to initialize
* resources.
*
* @description Camera controls are attached to the
* viewer with the with {@link Viewer.attachCustomCameraControls}
* method.
*
* Use the matrix callback functions
* to modify the camera pose and projection of the
* viewer's camera.
*
* Invoking the matrix callbacks has no effect if the
* custom camera controls have not been activated.
*
* @param {IViewer} viewer - The viewer this custom
* camera controls instance was just added to.
*/
onAttach(
viewer: IViewer,
viewMatrixCallback: (viewMatrix: number[]) => void,
projectionMatrixCallback: (projectionMatrix: number[]) => void,
): void;
/**
* Method called when the camera controls have been deactivated.
* This gives the camera controls a chance to clean up resources
* and event listeners.
*
* @param {IViewer} viewer - The viewer this custom camera controls
* instance is attached to.
*/
onDeactivate(viewer: IViewer): void;
/**
* Method called when the camera controls have been detached from
* the viewer. This gives the camera controls a chance to clean
* up resources and event listeners.
*
* @description Camera controls are attached to the
* viewer with the with {@link Viewer.detachCustomCameraControls}
* method.
*
* @param {IViewer} viewer - The viewer this custom camera
* controls instance was just detached from.
*/
onDetach(viewer: IViewer): void;
/**
* Method called when the viewer's reference position has changed.
* This gives the custom camera controls a chance to reposition
* the camera.
*
* @description Calculate the updated topocentric positions
* for scene objects using the previous reference, the
* new provided reference as well as the
* {@link geodeticToEnu} and
* {@link enuToGeodetic} functions.
*
* @param {IViewer} viewer - The viewer this custom renderer
* is added to.
* @param {LngLatAlt} reference - The viewer's current
* reference position.
*/
onReference(
viewer: IViewer,
reference: LngLatAlt): void;
/**
* Method called when the viewer has been resized.
*
* @description Use this method to modify the projection.
*/
onResize(viewer: IViewer): void;
}