-
Notifications
You must be signed in to change notification settings - Fork 33
/
p5.easycam.d.ts
534 lines (534 loc) · 18 KB
/
p5.easycam.d.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
import p5 from "p5";
type Vec3 = [number, number, number];
type Vec4 = [number, number, number, number];
/** @namespace */
export declare namespace Dw {
/**
* EasyCam
*
* <pre>
*
* new Dw.EasyCam(p5.RendererGL, {
* distance : z, // scalar
* center : [x, y, z], // vector
* rotation : [q0, q1, q2, q3], // quaternion
* viewport : [x, y, w, h], // array
* }
*
* </pre>
*
* @param {p5.RendererGL} renderer - p5 WEBGL renderer
* @param {Object} args - {distance, center, rotation, viewport}
*
*/
class EasyCam {
INFO: {
LIBRARY: string;
VERSION: string;
AUTHOR: string;
SOURCE: string;
toString(): string;
};
cam: this;
LOOK: Vec3;
UP: Vec3;
AXIS: {
YAW: number;
PITCH: number;
ALL: any;
ROLL: number;
};
SHIFT_CONSTRAINT: number;
FIXED_CONSTRAINT: number;
DRAG_CONSTRAINT: number;
scale_rotation: number;
scale_pan: number;
scale_zoom: number;
scale_zoomwheel: number;
distance_min_limit: number;
distance_min: number;
distance_max: number;
state: {
distance: number;
center: Vec3;
rotation: Vec4;
copy: () => any;
};
state_reset: any;
state_pushed: any;
viewport: Vec4;
offset: [number, number];
mouse: any;
auto_update: boolean;
dampedPanX: DampedAction;
dampedZoom: DampedAction;
dampedPanY: DampedAction;
pushed_uMVMatrix: any;
dampedRotX: DampedAction;
dampedRotY: DampedAction;
timedRot: Interpolation;
timedPan: Interpolation;
timedzoom: Interpolation;
renderer: any;
graphics: {
_pInst: any;
} | undefined;
P5: {
pixelDensity: () => any;
mouseX: number;
mouseY: number;
registerMethod: (arg0: string, arg1: () => void) => void;
};
camEYE: Vec3;
camLAT: Vec3;
camRUP: Vec3;
dampedRotZ: any;
pushed_uPMatrix: any;
pushed_rendererState: any;
/**
* @constructor
*/
constructor(renderer: {
elt: {
getBoundingClientRect: () => any;
};
width: number;
height: number;
}, args?: {
distance: number;
center: Vec3;
rotation: Vec4;
viewport: Vec4;
offset: [number, number];
});
/**
* sets the WEBGL renderer the camera is working on
*
* @param {p5.RendererGL} renderer ... p5 WEBGL renderer
*/
setCanvas(renderer: p5.RendererGL): void;
/** @return {p5.RendererGL} the currently used renderer */
getCanvas(): p5.RendererGL;
attachListener(el: any, ev: any, fx: {
el: {
addEventListener: (arg0: any, arg1: any, arg2: any) => void;
};
ev: any;
op: any;
}, op: any): void;
detachListener(fx: {
el: {
removeEventListener: (arg0: any, arg1: any, arg2: any) => void;
} | undefined;
ev: any;
op: any;
}): void;
/** attaches input-listeners (mouse, touch, key) to the used renderer */
attachMouseListeners(renderer?: {
elt: any;
}): void;
/** detaches all attached input-listeners */
removeMouseListeners(): void;
/** Disposes/releases the camera. */
dispose(): void;
/** @return {boolean} the current autoUpdate state */
getAutoUpdate(): boolean;
/**
* If true, the EasyCam will update automatically in a pre-draw step.
* This updates the camera state and updates the renderers
* modelview/camera matrix.
*
* If false, the update() needs to be called manually. */
setAutoUpdate(status: boolean): void;
/**
* Updates the camera state (interpolated / damped animations) and updates
* the renderers' modelview/camera matrix.
*
* if "auto_update" is true, this is called automatically in a pre-draw call.
*/
update(): void;
/**
* Applies the current camera state to the renderers' modelview/camera matrix.
* If no argument is given, then the cameras currently set renderer is used.
*/
apply(renderer?: {
_curCamera: {
camera: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any) => void;
};
camera: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any) => void;
}): void;
/** */
setViewport(viewport: Vec4): void;
/** @returns {[number, number, number,number]} the current viewport-def, as [x,y,w,h] */
getViewport(): Vec4;
/** implemented zoom-cb for mouswheel handler.*/
mouseWheelZoom(): void;
/** implemented zoom-cb for mousedrag/touch handler.*/
mouseDragZoom(): void;
/** implemented pan-cb for mousedrag/touch handler.*/
mouseDragPan(): void;
/** implemented rotate-cb for mousedrag/touch handler.*/
mouseDragRotate(): void;
/** (private) returns the used zoom -multiplier for damped actions. */
getZoomMult(): number;
/** (private) returns the used pan-multiplier for damped actions. */
getPanMult(): number;
/** (private) returns the used rotate-multiplier for damped actions. */
getRotationMult(): number;
/** Applies a change to the current zoom. */
zoom(dz: number): void;
/** Applies a change to the current pan-xValue. */
panX(dx: number): void;
/** Applies a change to the current pan-yValue. */
panY(dy: number): void;
/** Applies a change to the current pan-value. */
pan(dx: number, dy: number): void;
/** Applies a change to the current xRotation. */
rotateX(rx: number): void;
/** Applies a change to the current yRotation. */
rotateY(ry: number): void;
/** Applies a change to the current zRotation. */
rotateZ(rz: number): void;
/** Applies a change to the current rotation, using the given axis/angle. */
rotate(axis: Vec3, angle?: number): void;
/** Sets the new camera-distance, interpolated (t) between given A and B. */
setInterpolatedDistance(valA: number, valB: number, t: number): void;
/** Sets the new camera-center, interpolated (t) between given A and B. */
setInterpolatedCenter(valA: Vec3, valB: Vec3, t: number): void;
/** Sets the new camera-rotation, interpolated (t) between given A and B. */
setInterpolatedRotation(valA: Vec4, valB: Vec4, t: number): void;
/** Sets the minimum camera distance. */
setDistanceMin(distance_min: number): void;
/** Sets the maximum camera distance. */
setDistanceMax(distance_max: number): void;
/**
* Sets the new camera distance.
*
* @param {double} distance new distance.
* @param {long} duration animation time in millis.
*/
setDistance(distance: number, duration: number): void;
/** @returns {double} the current camera distance. */
getDistance(): number;
/**
* Sets the new camera center.
*
*/
setCenter(center: Vec3, duration: number): void;
/** @returns {double[]} the current camera center. */
getCenter(...args: any[][]): Vec3;
/**
* Sets the new camera rotation (quaternion).
*
*/
setRotation(rotation: Vec4, duration: number): void;
/** @returns {double[]} the current camera rotation as quat[q0,q1,q2,q3]. */
getRotation(): Vec4;
/** @returns {double[]} the current camera position, aka. the eye position. */
getPosition(dst: Vec3): Vec3;
/** @returns {double[]} the current camera up vector. */
getUpVector(dst: Vec3): Vec3;
/** @returns {Object} a copy of the camera state {distance,center,rotation} */
getState(): {
distance: number;
center: Vec3;
rotation: Vec4;
copy: () => any;
};
/**
* @param {Object} other new camera state {distance,center,rotation}.
*/
setState(other: {
distance: number;
center: Vec3;
rotation: Vec4;
}, duration: number): void;
pushState(): {
distance: number;
center: Vec3;
rotation: Vec4;
copy: () => any;
};
popState(duration: number): void;
/** sets the current state as reset-state. */
pushResetState(): {
distance: number;
center: Vec3;
rotation: Vec4;
copy: () => any;
};
/** resets the camera, by applying the reset-state. */
reset(duration?: number): void;
/** sets the rotation scale/speed. */
setRotationScale(scale_rotation: number): void;
/** sets the pan scale/speed. */
setPanScale(scale_pan: number): void;
/** sets the zoom scale/speed. */
setZoomScale(scale_zoom: number): void;
/** sets the wheel scale/speed. */
setWheelScale(wheelScale: number): void;
/** @returns the rotation scale/speed. */
getRotationScale(): number;
/** @returns the pan scale/speed. */
getPanScale(): number;
/** @returns the zoom scale/speed. */
getZoomScale(): number;
/** @returns the wheel scale/speed. */
getWheelScale(): number;
/** sets the default damping scale/speed. */
setDamping(damping: any): void;
/** sets the default interpolation time in millis. */
setDefaultInterpolationTime(duration: number): void;
/**
* sets the rotation constraint for each axis separately.
*
* @param {boolean} yaw constraint
* @param {boolean} pitch constraint
* @param {boolean} roll constraint
*/
setRotationConstraint(yaw: boolean, pitch: boolean, roll: boolean): void;
/**
*
* begin screen-aligned 2D-drawing.
*
* <pre>
* beginHUD()
* disabled depth test
* ortho
* ... your code is executed here ...
* endHUD()
* </pre>
*
*/
beginHUD(renderer: {
push: () => any;
drawingContext: any;
width: any;
height: any;
uMVMatrix: {
copy: () => any;
};
uPMatrix: {
copy: () => any;
};
resetMatrix: () => void;
_curCamera: {
ortho: (arg0: number, arg1: any, arg2: number, arg3: number, arg4: number, arg5: number) => void;
};
}, w: undefined, h: number | undefined): void;
/**
*
* end screen-aligned 2D-drawing.
*
*/
endHUD(renderer: {
drawingContext: any;
uMVMatrix: {
set: (arg0: any) => void;
};
uPMatrix: {
set: (arg0: any) => void;
};
pop: (arg0: any) => void;
}): void;
}
/**
* Damped callback, that accepts the resulting damped/smooth value.
*
* @callback dampedCallback
* @param {double} value - the damped/smoothed value
*
*/
/**
*
* DampedAction, for smoothly changing a value to zero.
*
* @param {dampedCallback} cb - callback that accepts the damped value as argument.
*/
class DampedAction {
value: number;
damping: number;
action: (arg0: any) => void;
/** @constructor */
constructor(cb: {
(d: any): void;
(d: any): void;
(d: any): void;
(d: any): void;
(d: any): void;
(d: any): void;
});
/** adds a value to the current value beeing damped.
* @param {double} force - the value beeing added.
*/
addForce(force: any): void;
/** updates the damping and calls {@link damped-callback}. */
update(): boolean;
/** stops the damping. */
stop(): void;
}
/**
* Interpolation callback, that implements any form of interpolation between
* two values A and B and the interpolationparameter t.
* <pre>
* linear: A * (1-t) + B * t
* smooth, etc...
* </pre>
* @callback interpolationCallback
* @param {Object} A - First Value
* @param {Object} B - Second Value
* @param {double} t - interpolation parameter [0, 1]
*
*/
/**
*
* Interpolation, for smoothly changing a value by interpolating it over time.
*
* @param {interpolationCallback} cb - callback for interpolating between two values.
*/
class Interpolation {
default_duration: number;
action: (arg0: any, arg1: any, arg2: any) => void;
valA: any;
valB: any;
duration: number;
timer: number;
active: boolean;
/** @constructor */
constructor(cb: any);
/** starts the interpolation.
* If the given interpolation-duration is 0, then
* {@link interpolation-callback} is called immediately.
*/
start(valA: any, valB: any, duration?: number, actions?: DampedAction[]): void;
/** updates the interpolation and calls {@link interpolation-callback}.*/
update(): void;
interpolate(t: number): void;
/** stops the interpolation. */
stop(): void;
}
/**
* Rotation as Quaternion [q0, q1, q2, q3]
*
* Note: Only functions that were required for the EasyCam to work are implemented.
*
* @namespace
*/
namespace Rotation {
function assert(dst?: Vec4): Vec4;
/** returns an identity rotation [1,0,0,0] */
function identity(): Vec4;
/**
* Applies the rotation to a vector and returns dst or a new vector.
*
* @param rot - Rotation (Quaternion)
* @param vec - vector to be rotated by rot
* @param dst - resulting vector
* @returns dst- resulting vector
*/
function applyToVec3(rot: Vec4, vec: Vec3, dst?: Vec3): Vec3;
/**
* Applies the rotation to another rotation and returns dst or a new rotation.
*
* @param rotA - RotationA (Quaternion)
* @param rotB - RotationB (Quaternion)
* @param dst - resulting rotation
* @returns dst - resulting rotation
*/
function applyToRotation(rotA: Vec4, rotB: Vec4, dst: Vec4): Vec4;
/**
* Interpolates a rotation.
*
* @param rotA - RotationA (Quaternion)
* @param rotB - RotationB (Quaternion)
* @param t - interpolation parameter
* @param dst - resulting rotation
* @returns dst - resulting rotation
*/
function slerp(rotA: Vec4, rotB: Vec4, t: number, dst: Vec4): Vec4;
/**
* Creates/Initiates a new Rotation
*
* <pre>
*
* 1) Axis,Angle:
* {
* axis : [x, y, z],
* angle: double
* }
*
* 2) Another Rotation:
* {
* rotation : [q0, q1, q2, q3],
* normalize: boolean
* }
*
* 3) 3 euler angles, XYZ-order:
* {
* angles_xyz : [rX, rY, rZ]
* }
*
* </pre>
*
*
* @param {Object} def - Definition, for creating the new Rotation
* @param dst - resulting rotation
* @returns dst - resulting rotation
*/
function create(def: {
axis?: Vec3;
angle?: number;
rotation?: Vec4;
normalize?: boolean;
angles_xyz?: Vec3;
}, dst?: Vec4): Vec4;
}
/**
* Scalar as a simple number.
*
* Note: Only functions that were required for the EasyCam to work are implemented.
*
* @namespace
*/
namespace Scalar {
/**
* Linear interpolation between A and B using t[0,1]
*/
function mix(a: number, b: number, t: number): number;
/**
* modifying t as a function of smoothstep(0,1,t);
*/
function smoothstep(x: number): number;
/**
* modifying t as a function of smootherstep(0,1,t);
*/
function smootherstep(x: number): number;
}
/**
* Vec3 as a 3D vector (Array)
*
* @namespace
*/
namespace Vec3 {
function assert(dst?: Vec3): Vec3;
function isScalar(arg: any): boolean;
/** addition: <pre> dst = a + b </pre> */
function add(a: Vec3, b: Vec3 | number, dst: Vec3): Vec3;
/** componentwise multiplication: <pre> dst = a * b </pre> */
function mult(a: Vec3, b: Vec3 | number, dst: Vec3): Vec3;
/** squared length */
function magSq(a: Vec3): number;
/** length */
function mag(a: Vec3): number;
/** dot-product */
function dot(a: Vec3, b: Vec3): number;
/** cross-product */
function cross(a: Vec3, b: Vec3, dst?: Vec3): Vec3;
/** angle */
function angle(v1: Vec3, v2: Vec3): number;
/** linear interpolation: <pre> dst = a * (1 - t) + b * t </pre> */
function mix(a: Vec3, b: Vec3, t: number, dst?: Vec3): Vec3;
}
}
export declare function createEasyCam(): Dw.EasyCam;
export {};