@gg-web-engine/core 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/2d/entities/controllers/entity-2d-positioning.animator.d.ts +16 -0
  2. package/dist/2d/entities/controllers/entity-2d-positioning.animator.js +26 -0
  3. package/dist/2d/entities/gg-2d-entity.d.ts +12 -6
  4. package/dist/2d/entities/gg-2d-entity.js +52 -20
  5. package/dist/2d/gg-2d-world.d.ts +3 -0
  6. package/dist/2d/gg-2d-world.js +11 -0
  7. package/dist/3d/controllers/car-keyboard.controller.d.ts +10 -10
  8. package/dist/3d/controllers/car-keyboard.controller.js +21 -20
  9. package/dist/3d/controllers/free-camera.controller.d.ts +8 -8
  10. package/dist/3d/entities/controllers/animators/camera-3d.animator.d.ts +17 -0
  11. package/dist/3d/entities/controllers/animators/camera-3d.animator.js +32 -0
  12. package/dist/3d/entities/controllers/animators/entity-3d-positioning.animator.d.ts +16 -0
  13. package/dist/3d/entities/controllers/animators/entity-3d-positioning.animator.js +26 -0
  14. package/dist/3d/entities/controllers/camera-3d.animator.d.ts +17 -0
  15. package/dist/3d/entities/controllers/camera-3d.animator.js +32 -0
  16. package/dist/3d/entities/controllers/entity-3d-positioning.animator.d.ts +16 -0
  17. package/dist/3d/entities/controllers/entity-3d-positioning.animator.js +26 -0
  18. package/dist/3d/entities/controllers/input/car-keyboard-handling.controller.d.ts +25 -0
  19. package/dist/3d/entities/controllers/input/car-keyboard-handling.controller.js +105 -0
  20. package/dist/3d/entities/controllers/input/free-camera.controller.d.ts +54 -0
  21. package/dist/3d/entities/controllers/input/free-camera.controller.js +102 -0
  22. package/dist/3d/entities/gg-3d-camera.entity.d.ts +2 -0
  23. package/dist/3d/entities/gg-3d-camera.entity.js +6 -0
  24. package/dist/3d/entities/gg-3d-entity.d.ts +7 -6
  25. package/dist/3d/entities/gg-3d-entity.js +21 -13
  26. package/dist/3d/entities/gg-3d-map-graph.entity.d.ts +10 -10
  27. package/dist/3d/entities/gg-3d-map-graph.entity.js +2 -3
  28. package/dist/3d/entities/gg-3d-raycast-vehicle.entity.d.ts +6 -5
  29. package/dist/3d/gg-3d-world.d.ts +3 -0
  30. package/dist/3d/gg-3d-world.js +12 -0
  31. package/dist/3d/inputs/car-keyboard.input.d.ts +25 -0
  32. package/dist/3d/inputs/car-keyboard.input.js +100 -0
  33. package/dist/3d/inputs/free-camera.input.d.ts +22 -0
  34. package/dist/3d/inputs/free-camera.input.js +80 -0
  35. package/dist/base/clock/clock.d.ts +25 -0
  36. package/dist/base/clock/clock.js +79 -0
  37. package/dist/base/clock/global-clock.d.ts +16 -0
  38. package/dist/base/clock/global-clock.js +36 -0
  39. package/dist/base/clock/i-clock.d.ts +7 -0
  40. package/dist/base/clock/i-clock.js +2 -0
  41. package/dist/base/clock/pausable-clock.d.ts +25 -0
  42. package/dist/base/clock/pausable-clock.js +79 -0
  43. package/dist/base/entities/base-gg-renderer.d.ts +3 -15
  44. package/dist/base/entities/base-gg-renderer.js +2 -30
  45. package/dist/base/entities/controllers/animation-mixer.d.ts +76 -0
  46. package/dist/base/entities/controllers/animation-mixer.js +143 -0
  47. package/dist/base/entities/gg-entity.d.ts +33 -1
  48. package/dist/base/entities/gg-entity.js +42 -1
  49. package/dist/base/entities/inline-controller.js +1 -7
  50. package/dist/base/entities/interfaces/i-tick-listener.d.ts +25 -1
  51. package/dist/base/entities/interfaces/i-tick-listener.js +17 -1
  52. package/dist/base/gg-viewport-manager.d.ts +4 -0
  53. package/dist/base/gg-world.d.ts +11 -6
  54. package/dist/base/gg-world.js +50 -31
  55. package/dist/base/inputs/direction.keyboard-input.d.ts +41 -0
  56. package/dist/base/inputs/direction.keyboard-input.js +85 -0
  57. package/dist/base/inputs/input.d.ts +50 -0
  58. package/dist/base/inputs/input.js +80 -0
  59. package/dist/base/inputs/keyboard.input.d.ts +45 -0
  60. package/dist/base/inputs/keyboard.input.js +130 -0
  61. package/dist/base/inputs/mouse.input.d.ts +57 -0
  62. package/dist/base/inputs/mouse.input.js +81 -0
  63. package/dist/base/math/matrix4.js +3 -3
  64. package/dist/base/math/point2.js +1 -1
  65. package/dist/base/math/point3.js +1 -1
  66. package/dist/base/math/quaternion.d.ts +83 -9
  67. package/dist/base/math/quaternion.js +93 -10
  68. package/dist/base/models/points.d.ts +9 -9
  69. package/dist/index.d.ts +13 -9
  70. package/dist/index.js +13 -9
  71. package/package.json +1 -1
  72. package/.prettierrc +0 -8
@@ -0,0 +1,50 @@
1
+ import { Subject } from 'rxjs';
2
+ /**
3
+ * An abstract class that provides basic implementation for Input class.
4
+ * Input is an entity for handling input from user, such as mouse movements, key presses etc.
5
+ * Inputs are not bound to World-s and working independently by design.
6
+ *
7
+ * TStartParams - A type representing an array of input arguments for the start method. Items are recommended to be named.
8
+ *
9
+ * TStopParams - A type representing an array of input arguments for the stop method. Items are recommended to be named.
10
+ */
11
+ export declare abstract class Input<TStartParams extends any[] = [], TStopParams extends any[] = []> {
12
+ /**
13
+ * A private boolean that represents the running state of the process.
14
+ */
15
+ private _running;
16
+ /**
17
+ * A protected subject that emits a void value when the process is stopped.
18
+ * Subclasses, when subscribing to something using rxjs, have to add pipe takeUntil(this.stop$),
19
+ * so everything will be unsubscribed when stopping input
20
+ */
21
+ protected readonly stop$: Subject<void>;
22
+ /**
23
+ * A public getter that returns the running state of the Input.
24
+ */
25
+ get running(): boolean;
26
+ /**
27
+ * An asynchronous method that starts the input. Do not override it
28
+ * @param args - An array of input arguments for the start method.
29
+ * @returns A Promise that resolves when the input is started.
30
+ */
31
+ start(...args: TStartParams): Promise<void>;
32
+ /**
33
+ * An asynchronous method that stops the input. Do not override it
34
+ * @param args - An array of input arguments for the stop method.
35
+ * @returns A Promise that resolves when the input is stopped.
36
+ */
37
+ stop(...args: TStopParams): Promise<void>;
38
+ /**
39
+ * An abstract asynchronous method that starts the input.
40
+ * @param args - An array of input arguments for the start method.
41
+ * @returns A Promise that resolves when the process is started.
42
+ */
43
+ protected abstract startInternal(...args: TStartParams): Promise<void>;
44
+ /**
45
+ * An asynchronous method that stops the input.
46
+ * @param args - An array of input arguments for the stop method.
47
+ * @returns A Promise that resolves when the process is stopped.
48
+ */
49
+ protected stopInternal(...args: TStopParams): Promise<void>;
50
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Input = void 0;
13
+ const rxjs_1 = require("rxjs");
14
+ /**
15
+ * An abstract class that provides basic implementation for Input class.
16
+ * Input is an entity for handling input from user, such as mouse movements, key presses etc.
17
+ * Inputs are not bound to World-s and working independently by design.
18
+ *
19
+ * TStartParams - A type representing an array of input arguments for the start method. Items are recommended to be named.
20
+ *
21
+ * TStopParams - A type representing an array of input arguments for the stop method. Items are recommended to be named.
22
+ */
23
+ class Input {
24
+ constructor() {
25
+ /**
26
+ * A private boolean that represents the running state of the process.
27
+ */
28
+ this._running = false;
29
+ /**
30
+ * A protected subject that emits a void value when the process is stopped.
31
+ * Subclasses, when subscribing to something using rxjs, have to add pipe takeUntil(this.stop$),
32
+ * so everything will be unsubscribed when stopping input
33
+ */
34
+ this.stop$ = new rxjs_1.Subject();
35
+ }
36
+ /**
37
+ * A public getter that returns the running state of the Input.
38
+ */
39
+ get running() {
40
+ return this._running;
41
+ }
42
+ /**
43
+ * An asynchronous method that starts the input. Do not override it
44
+ * @param args - An array of input arguments for the start method.
45
+ * @returns A Promise that resolves when the input is started.
46
+ */
47
+ start(...args) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ if (this.running) {
50
+ return;
51
+ }
52
+ yield this.startInternal(...args);
53
+ this._running = true;
54
+ });
55
+ }
56
+ /**
57
+ * An asynchronous method that stops the input. Do not override it
58
+ * @param args - An array of input arguments for the stop method.
59
+ * @returns A Promise that resolves when the input is stopped.
60
+ */
61
+ stop(...args) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ if (!this.running) {
64
+ return;
65
+ }
66
+ this.stop$.next();
67
+ yield this.stopInternal(...args);
68
+ this._running = false;
69
+ });
70
+ }
71
+ /**
72
+ * An asynchronous method that stops the input.
73
+ * @param args - An array of input arguments for the stop method.
74
+ * @returns A Promise that resolves when the process is stopped.
75
+ */
76
+ stopInternal(...args) {
77
+ return __awaiter(this, void 0, void 0, function* () { });
78
+ }
79
+ }
80
+ exports.Input = Input;
@@ -0,0 +1,45 @@
1
+ import { Input } from './input';
2
+ import { Observable } from 'rxjs';
3
+ /**
4
+ * A main keyboard input: it does not have own key bindings, but provides an API to bind keys.
5
+ * It is responsible for listening key up/down events (when running!) and emit the events to subscribers.
6
+ * Every World entity has its own dedicated instance of Keyboard input, which is running only when the world is running
7
+ */
8
+ export declare class KeyboardInput extends Input {
9
+ private bindings;
10
+ /**
11
+ * Creates a new instance of the `KeyboardInput` class.
12
+ */
13
+ constructor();
14
+ protected startInternal(): Promise<void>;
15
+ protected stopInternal(): Promise<void>;
16
+ /**
17
+ * Creates an observable that emits a boolean whenever a key with the given code is pressed or released
18
+ * @param code The key code to bind the observable to
19
+ * @returns An observable that emits true when the key is pressed and false when it's released
20
+ */
21
+ bind(code: string): Observable<boolean>;
22
+ /**
23
+ * Creates an observable that emits a boolean indicating whether any of the keys with the given codes are pressed or released.
24
+ * Should be used when you have more than one keys, responsible for the same action.
25
+ * @param codes The key codes to bind the observable to
26
+ * @returns An observable that emits true when any of the keys are pressed and false when they're all released
27
+ */
28
+ bindMany(...codes: string[]): Observable<boolean>;
29
+ /**
30
+ * Emulates a key down event for the given key code
31
+ * @param code The key code to emulate
32
+ */
33
+ emulateKeyDown(code: string): void;
34
+ /**
35
+ * Emulates a key up event for the given key code
36
+ * @param code The key code to emulate
37
+ */
38
+ emulateKeyUp(code: string): void;
39
+ /**
40
+ * Emulates a key press event (down and up) for the given key code
41
+ * @param code The key code to emulate
42
+ */
43
+ emulateKeyPress(code: string): void;
44
+ private handleKeys;
45
+ }
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.KeyboardInput = void 0;
13
+ const input_1 = require("./input");
14
+ const rxjs_1 = require("rxjs");
15
+ const operators_1 = require("rxjs/operators");
16
+ /**
17
+ * A main keyboard input: it does not have own key bindings, but provides an API to bind keys.
18
+ * It is responsible for listening key up/down events (when running!) and emit the events to subscribers.
19
+ * Every World entity has its own dedicated instance of Keyboard input, which is running only when the world is running
20
+ */
21
+ class KeyboardInput extends input_1.Input {
22
+ /**
23
+ * Creates a new instance of the `KeyboardInput` class.
24
+ */
25
+ constructor() {
26
+ super();
27
+ this.bindings = {};
28
+ this.handleKeys = this.handleKeys.bind(this);
29
+ }
30
+ startInternal() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ window.addEventListener('keydown', this.handleKeys);
33
+ window.addEventListener('keyup', this.handleKeys);
34
+ });
35
+ }
36
+ stopInternal() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ window.removeEventListener('keydown', this.handleKeys);
39
+ window.removeEventListener('keyup', this.handleKeys);
40
+ });
41
+ }
42
+ /**
43
+ * Creates an observable that emits a boolean whenever a key with the given code is pressed or released
44
+ * @param code The key code to bind the observable to
45
+ * @returns An observable that emits true when the key is pressed and false when it's released
46
+ */
47
+ bind(code) {
48
+ if (!this.bindings[code]) {
49
+ this.bindings[code] = [];
50
+ }
51
+ const subj = new rxjs_1.BehaviorSubject(false);
52
+ this.bindings[code].push(subj);
53
+ return subj.pipe((0, rxjs_1.finalize)(() => {
54
+ this.bindings[code].splice(this.bindings[code].indexOf(subj), 1);
55
+ subj.complete();
56
+ }));
57
+ }
58
+ /**
59
+ * Creates an observable that emits a boolean indicating whether any of the keys with the given codes are pressed or released.
60
+ * Should be used when you have more than one keys, responsible for the same action.
61
+ * @param codes The key codes to bind the observable to
62
+ * @returns An observable that emits true when any of the keys are pressed and false when they're all released
63
+ */
64
+ bindMany(...codes) {
65
+ if (codes.length == 0) {
66
+ console.warn('[KeyboardController] bindMany called without any key code');
67
+ return rxjs_1.NEVER;
68
+ }
69
+ if (codes.length == 1) {
70
+ return this.bind(codes[0]);
71
+ }
72
+ const subjects = [];
73
+ for (const code of codes) {
74
+ if (!this.bindings[code]) {
75
+ this.bindings[code] = [];
76
+ }
77
+ const subj = new rxjs_1.BehaviorSubject(false);
78
+ this.bindings[code].push(subj);
79
+ subjects.push(subj);
80
+ }
81
+ return (0, rxjs_1.combineLatest)(subjects).pipe((0, rxjs_1.finalize)(() => {
82
+ for (let i = 0; i < codes.length; i++) {
83
+ this.bindings[codes[i]].splice(this.bindings[codes[i]].indexOf(subjects[i]), 1);
84
+ subjects[i].complete();
85
+ }
86
+ }), (0, operators_1.map)(values => values.includes(true)));
87
+ }
88
+ /**
89
+ * Emulates a key down event for the given key code
90
+ * @param code The key code to emulate
91
+ */
92
+ emulateKeyDown(code) {
93
+ if (!this.running) {
94
+ return;
95
+ }
96
+ for (const subj of this.bindings[code] || []) {
97
+ subj.next(true);
98
+ }
99
+ }
100
+ /**
101
+ * Emulates a key up event for the given key code
102
+ * @param code The key code to emulate
103
+ */
104
+ emulateKeyUp(code) {
105
+ if (!this.running) {
106
+ return;
107
+ }
108
+ for (const subj of this.bindings[code] || []) {
109
+ subj.next(false);
110
+ }
111
+ }
112
+ /**
113
+ * Emulates a key press event (down and up) for the given key code
114
+ * @param code The key code to emulate
115
+ */
116
+ emulateKeyPress(code) {
117
+ this.emulateKeyDown(code);
118
+ this.emulateKeyUp(code);
119
+ }
120
+ handleKeys(e) {
121
+ if (e.type != 'keydown' && e.type != 'keyup') {
122
+ return;
123
+ }
124
+ const pressed = e.type == 'keydown';
125
+ for (const subj of this.bindings[e.code] || []) {
126
+ subj.next(pressed);
127
+ }
128
+ }
129
+ }
130
+ exports.KeyboardInput = KeyboardInput;
@@ -0,0 +1,57 @@
1
+ import { Input } from './input';
2
+ import { Observable } from 'rxjs';
3
+ import { Point2 } from '../models/points';
4
+ /**
5
+ * Options for pointer lock in a MouseInput.
6
+ *
7
+ * ignoreMovementWhenNotLocked: Whether to ignore mouse movement when pointer lock is not active.
8
+ *
9
+ * canvas: The canvas element to request pointer lock on.
10
+ */
11
+ export declare type MouseInputPointLockOptions = {
12
+ ignoreMovementWhenNotLocked: boolean;
13
+ canvas: HTMLCanvasElement;
14
+ };
15
+ /**
16
+ * Options for a MouseInput.
17
+ *
18
+ * pointerLock: The options for pointer lock. Do not provide it to disable pointer lock functionality
19
+ */
20
+ export declare type MouseInputOptions = {
21
+ pointerLock?: MouseInputPointLockOptions;
22
+ };
23
+ /**
24
+ * A class representing mouse input.
25
+ */
26
+ export declare class MouseInput extends Input<[], [unlockPointer?: boolean]> {
27
+ private readonly options;
28
+ /**
29
+ * An observable of the change in the x position of the mouse.
30
+ */
31
+ get deltaX$(): Observable<number>;
32
+ /**
33
+ * An observable of the change in the y position of the mouse.
34
+ */
35
+ get deltaY$(): Observable<number>;
36
+ /**
37
+ An observable of the change in the position of the mouse.
38
+ */
39
+ get delta$(): Observable<Point2>;
40
+ private _delta$;
41
+ private stopped$;
42
+ /**
43
+ Creates an instance of MouseInput.
44
+ @param {MouseInputOptions} options - The options for the MouseInput.
45
+ */
46
+ constructor(options?: MouseInputOptions);
47
+ protected startInternal(): Promise<void>;
48
+ /**
49
+ Stop listening for mouse movement events.
50
+ @param {boolean} [unlockPointer=true] - Whether to exit pointer lock.
51
+ */
52
+ protected stopInternal(unlockPointer?: boolean): Promise<void>;
53
+ /**
54
+ Request pointer lock on the canvas element.
55
+ */
56
+ private canvasClickListener;
57
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MouseInput = void 0;
13
+ const input_1 = require("./input");
14
+ const rxjs_1 = require("rxjs");
15
+ const operators_1 = require("rxjs/operators");
16
+ /**
17
+ * A class representing mouse input.
18
+ */
19
+ class MouseInput extends input_1.Input {
20
+ /**
21
+ Creates an instance of MouseInput.
22
+ @param {MouseInputOptions} options - The options for the MouseInput.
23
+ */
24
+ constructor(options = {}) {
25
+ super();
26
+ this.options = options;
27
+ this._delta$ = new rxjs_1.Subject();
28
+ this.stopped$ = new rxjs_1.Subject();
29
+ this.canvasClickListener = this.canvasClickListener.bind(this);
30
+ }
31
+ /**
32
+ * An observable of the change in the x position of the mouse.
33
+ */
34
+ get deltaX$() {
35
+ return this._delta$.pipe((0, operators_1.map)(d => d.x));
36
+ }
37
+ /**
38
+ * An observable of the change in the y position of the mouse.
39
+ */
40
+ get deltaY$() {
41
+ return this._delta$.pipe((0, operators_1.map)(d => d.y));
42
+ }
43
+ /**
44
+ An observable of the change in the position of the mouse.
45
+ */
46
+ get delta$() {
47
+ return this._delta$.asObservable();
48
+ }
49
+ startInternal() {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ (0, rxjs_1.fromEvent)(window, 'mousemove')
52
+ .pipe((0, rxjs_1.takeUntil)(this.stopped$), (0, rxjs_1.filter)(() => !this.options.pointerLock ||
53
+ !this.options.pointerLock.ignoreMovementWhenNotLocked ||
54
+ !!document.pointerLockElement), (0, operators_1.map)((e) => ({ x: e.movementX, y: e.movementY })))
55
+ .subscribe(v => this._delta$.next(v));
56
+ if (!!this.options.pointerLock) {
57
+ this.options.pointerLock.canvas.addEventListener('click', this.canvasClickListener);
58
+ }
59
+ });
60
+ }
61
+ /**
62
+ Stop listening for mouse movement events.
63
+ @param {boolean} [unlockPointer=true] - Whether to exit pointer lock.
64
+ */
65
+ stopInternal(unlockPointer = true) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ this.stopped$.next();
68
+ if (unlockPointer && !!this.options.pointerLock) {
69
+ this.options.pointerLock.canvas.removeEventListener('click', this.canvasClickListener);
70
+ document.exitPointerLock();
71
+ }
72
+ });
73
+ }
74
+ /**
75
+ Request pointer lock on the canvas element.
76
+ */
77
+ canvasClickListener() {
78
+ this.options.pointerLock.canvas.requestPointerLock();
79
+ }
80
+ }
81
+ exports.MouseInput = MouseInput;
@@ -8,7 +8,7 @@ class Mtrx4 {
8
8
  let z = point3_1.Pnt3.sub(eye, target);
9
9
  if (point3_1.Pnt3.lenSq(z) === 0) {
10
10
  // same position
11
- z.z = 1;
11
+ z = Object.assign(Object.assign({}, z), { z: 1 });
12
12
  }
13
13
  else {
14
14
  z = point3_1.Pnt3.norm(z);
@@ -17,10 +17,10 @@ class Mtrx4 {
17
17
  if (point3_1.Pnt3.lenSq(x) === 0) {
18
18
  // up and z are parallel
19
19
  if (Math.abs(up.z) === 1) {
20
- z.x += 0.0001;
20
+ z = Object.assign(Object.assign({}, z), { x: z.x + 0.0001 });
21
21
  }
22
22
  else {
23
- z.z += 0.0001;
23
+ z = Object.assign(Object.assign({}, z), { z: z.z + 0.0001 });
24
24
  }
25
25
  z = point3_1.Pnt3.norm(z);
26
26
  x = point3_1.Pnt3.cross(up, z);
@@ -4,7 +4,7 @@ exports.Pnt2 = void 0;
4
4
  class Pnt2 {
5
5
  /** clone point */
6
6
  static clone(p) {
7
- return Object.assign({}, p);
7
+ return { x: p.x, y: p.y };
8
8
  }
9
9
  /** add point b to point a */
10
10
  static add(a, b) {
@@ -5,7 +5,7 @@ const quaternion_1 = require("./quaternion");
5
5
  class Pnt3 {
6
6
  /** clone point */
7
7
  static clone(p) {
8
- return Object.assign({}, p);
8
+ return { x: p.x, y: p.y, z: p.z };
9
9
  }
10
10
  /** add point b to point a */
11
11
  static add(a, b) {
@@ -1,28 +1,102 @@
1
1
  import { Point3, Point4 } from '../models/points';
2
+ /**
3
+ * Helper class with static functions, containing util functions, related to Quaternion (represented as Point4 type).
4
+ * In terms of rotation, a quaternion is a mathematical representation of an orientation or rotation in 3D space.
5
+ * It consists of a scalar component and a vector component, and can be written as q = w + xi + yj + zk, where w is the
6
+ * scalar component, and i, j, and k are the vector components. The scalar component, w, represents the amount of
7
+ * rotation, and the vector component, (x, y, z), represents the axis of rotation. The length of the vector component
8
+ * represents the amount of rotation around the axis. Quaternions are often used in 3D computer graphics and animation
9
+ * because they can be used to interpolate between two rotations, and they can avoid some of the issues with using
10
+ * Euler angles (such as gimbal lock).
11
+ */
2
12
  export declare class Qtrn {
3
- /** clone quaternion */
13
+ /**
14
+ * Returns a new quaternion instance with the same values as the given quaternion object.
15
+ * @param q The Point4 object to clone.
16
+ * @returns A new Point4 instance with the same values as the given Point4 object.
17
+ */
4
18
  static clone(q: Point4): Point4;
5
- /** add quaternion b to quaternion a */
19
+ /**
20
+ * Returns the sum of two Point4 objects.
21
+ * @param a The first Point4 object to add.
22
+ * @param b The second Point4 object to add.
23
+ * @returns The sum of the two Point4 objects.
24
+ */
6
25
  static add(a: Point4, b: Point4): Point4;
26
+ /**
27
+ * Returns the result of multiplying two Point4 objects. This can be used for combining rotations
28
+ * @param a The first Point4 object to multiply.
29
+ * @param b The second Point4 object to multiply.
30
+ * @returns The product of the two Point4 objects.
31
+ */
7
32
  static mult(a: Point4, b: Point4): Point4;
33
+ /**
34
+ * Combines an arbitrary number of quaternions by multiplying them together in order.
35
+ * @param quaternions The quaternions to combine.
36
+ * @returns The combined quaternion.
37
+ */
8
38
  static combineRotations(...quaternions: Point4[]): Point4;
9
- /** linear interpolation */
39
+ /**
40
+ * Performs a linear interpolation between two Point4 objects.
41
+ * @param a The first Point4 object.
42
+ * @param b The second Point4 object.
43
+ * @param t The interpolation factor.
44
+ * @returns The interpolated Point4 object.
45
+ */
10
46
  static lerp(a: Point4, b: Point4, t: number): Point4;
11
- /** spherical interpolation */
47
+ /**
48
+ * Performs a spherical linear interpolation between two Point4 objects.
49
+ * @param a The first Point4 object.
50
+ * @param b The second Point4 object.
51
+ * @param t The interpolation factor.
52
+ * @returns The interpolated Point4 object.
53
+ */
12
54
  static slerp(a: Point4, b: Point4, t: number): Point4;
13
- /** creates quaternion from simple angle around axis. Assumes that axis vector is normalized */
55
+ /**
56
+ * Converts an angle and an axis of rotation into a quaternion
57
+ * @param axis the axis of rotation
58
+ * @param angle the angle of rotation in radians
59
+ * @returns a quaternion representing the rotation
60
+ */
14
61
  static fromAngle(axis: Point3, angle: number): {
15
62
  w: number;
16
63
  x: number;
17
64
  y: number;
18
65
  z: number;
19
66
  };
20
- /** creates quaternion from 4-dimension rotation matrix */
67
+ /**
68
+ * Converts a 4x4 matrix representing a rotation into a quaternion
69
+ * @param m the matrix representing the rotation
70
+ * @returns a quaternion representing the rotation
71
+ */
21
72
  static fromMatrix4(m: number[]): Point4;
22
- /** creates a quaternion from euler */
73
+ /**
74
+ * Creates a quaternion from euler
75
+ * @param e the euler vector
76
+ * @returns a quaternion representing the rotation
77
+ */
23
78
  static fromEuler(e: Point3): Point4;
24
- /** converts a quaternion to euler */
79
+ /**
80
+ * Converts a quaternion to euler
81
+ * @param q Point4 object
82
+ * @returns an Euler vector, representing the same rotation
83
+ */
25
84
  static toEuler(q: Point4): Point3;
26
- /** creates a rotation for object, so it will look at some point in space */
85
+ /**
86
+ * Returns a quaternion that represents the rotation required to align an object to face towards a target point.
87
+ * @param eye - The position of the camera or object that needs to be rotated to face the target point.
88
+ * @param target - The target point to look at
89
+ * @param up - The up direction of the object
90
+ * @returns A new quaternion representing the rotation required to face towards the target point.
91
+ */
27
92
  static lookAt(eye: Point3, target: Point3, up: Point3): Point4;
93
+ /**
94
+ * Returns a quaternion that represents the input quaternion, rotated around provided axis vector by provided angle.
95
+ * Assumes that axis vector is already normalized
96
+ * @param q - Input quaternion.
97
+ * @param axis - Axis vector
98
+ * @param angle - Angle
99
+ * @returns A new quaternion representing the updated rotation.
100
+ */
101
+ static rotAround(q: Point4, axis: Point3, angle: number): Point4;
28
102
  }