@gg-web-engine/core 0.0.2 → 0.0.3

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 (44) 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 +9 -1
  4. package/dist/2d/entities/gg-2d-entity.js +50 -17
  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/camera-3d.animator.d.ts +17 -0
  11. package/dist/3d/entities/controllers/camera-3d.animator.js +32 -0
  12. package/dist/3d/entities/controllers/entity-3d-positioning.animator.d.ts +16 -0
  13. package/dist/3d/entities/controllers/entity-3d-positioning.animator.js +26 -0
  14. package/dist/3d/entities/gg-3d-camera.entity.d.ts +2 -0
  15. package/dist/3d/entities/gg-3d-camera.entity.js +6 -0
  16. package/dist/3d/entities/gg-3d-entity.d.ts +4 -1
  17. package/dist/3d/entities/gg-3d-entity.js +19 -10
  18. package/dist/3d/entities/gg-3d-map-graph.entity.d.ts +7 -5
  19. package/dist/3d/entities/gg-3d-map-graph.entity.js +1 -1
  20. package/dist/3d/entities/gg-3d-raycast-vehicle.entity.d.ts +6 -5
  21. package/dist/3d/gg-3d-world.d.ts +3 -0
  22. package/dist/3d/gg-3d-world.js +12 -0
  23. package/dist/base/clock/clock.d.ts +25 -0
  24. package/dist/base/clock/clock.js +79 -0
  25. package/dist/base/clock/global-clock.d.ts +15 -0
  26. package/dist/base/clock/global-clock.js +36 -0
  27. package/dist/base/entities/controllers/animation-mixer.d.ts +83 -0
  28. package/dist/base/entities/controllers/animation-mixer.js +152 -0
  29. package/dist/base/entities/gg-entity.d.ts +4 -1
  30. package/dist/base/entities/gg-entity.js +7 -0
  31. package/dist/base/entities/inline-controller.js +0 -1
  32. package/dist/base/gg-viewport-manager.d.ts +4 -0
  33. package/dist/base/gg-world.d.ts +3 -1
  34. package/dist/base/gg-world.js +6 -5
  35. package/dist/base/math/matrix4.js +3 -3
  36. package/dist/base/math/point2.js +1 -1
  37. package/dist/base/math/point3.js +1 -1
  38. package/dist/base/math/quaternion.d.ts +83 -9
  39. package/dist/base/math/quaternion.js +93 -10
  40. package/dist/base/models/points.d.ts +9 -9
  41. package/dist/index.d.ts +6 -2
  42. package/dist/index.js +6 -2
  43. package/package.json +1 -1
  44. package/.prettierrc +0 -8
@@ -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
  }
@@ -3,12 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Qtrn = void 0;
4
4
  const point3_1 = require("./point3");
5
5
  const matrix4_1 = require("./matrix4");
6
+ /**
7
+ * Helper class with static functions, containing util functions, related to Quaternion (represented as Point4 type).
8
+ * In terms of rotation, a quaternion is a mathematical representation of an orientation or rotation in 3D space.
9
+ * It consists of a scalar component and a vector component, and can be written as q = w + xi + yj + zk, where w is the
10
+ * scalar component, and i, j, and k are the vector components. The scalar component, w, represents the amount of
11
+ * rotation, and the vector component, (x, y, z), represents the axis of rotation. The length of the vector component
12
+ * represents the amount of rotation around the axis. Quaternions are often used in 3D computer graphics and animation
13
+ * because they can be used to interpolate between two rotations, and they can avoid some of the issues with using
14
+ * Euler angles (such as gimbal lock).
15
+ */
6
16
  class Qtrn {
7
- /** clone quaternion */
17
+ /**
18
+ * Returns a new quaternion instance with the same values as the given quaternion object.
19
+ * @param q The Point4 object to clone.
20
+ * @returns A new Point4 instance with the same values as the given Point4 object.
21
+ */
8
22
  static clone(q) {
9
- return Object.assign({}, q);
23
+ return { x: q.x, y: q.y, z: q.z, w: q.w };
10
24
  }
11
- /** add quaternion b to quaternion a */
25
+ /**
26
+ * Returns the sum of two Point4 objects.
27
+ * @param a The first Point4 object to add.
28
+ * @param b The second Point4 object to add.
29
+ * @returns The sum of the two Point4 objects.
30
+ */
12
31
  static add(a, b) {
13
32
  const w = a.w + b.w;
14
33
  const x = a.x + b.x;
@@ -17,6 +36,12 @@ class Qtrn {
17
36
  const magnitude = Math.sqrt(w * w + x * x + y * y + z * z);
18
37
  return { w: w / magnitude, x: x / magnitude, y: y / magnitude, z: z / magnitude };
19
38
  }
39
+ /**
40
+ * Returns the result of multiplying two Point4 objects. This can be used for combining rotations
41
+ * @param a The first Point4 object to multiply.
42
+ * @param b The second Point4 object to multiply.
43
+ * @returns The product of the two Point4 objects.
44
+ */
20
45
  static mult(a, b) {
21
46
  return {
22
47
  w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
@@ -25,6 +50,11 @@ class Qtrn {
25
50
  z: a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
26
51
  };
27
52
  }
53
+ /**
54
+ * Combines an arbitrary number of quaternions by multiplying them together in order.
55
+ * @param quaternions The quaternions to combine.
56
+ * @returns The combined quaternion.
57
+ */
28
58
  static combineRotations(...quaternions) {
29
59
  let result = { w: 1, x: 0, y: 0, z: 0 };
30
60
  for (const quat of quaternions) {
@@ -32,7 +62,13 @@ class Qtrn {
32
62
  }
33
63
  return result;
34
64
  }
35
- /** linear interpolation */
65
+ /**
66
+ * Performs a linear interpolation between two Point4 objects.
67
+ * @param a The first Point4 object.
68
+ * @param b The second Point4 object.
69
+ * @param t The interpolation factor.
70
+ * @returns The interpolated Point4 object.
71
+ */
36
72
  static lerp(a, b, t) {
37
73
  return {
38
74
  x: a.x + t * (b.x - a.x),
@@ -41,7 +77,13 @@ class Qtrn {
41
77
  w: a.w + t * (b.w - a.w),
42
78
  };
43
79
  }
44
- /** spherical interpolation */
80
+ /**
81
+ * Performs a spherical linear interpolation between two Point4 objects.
82
+ * @param a The first Point4 object.
83
+ * @param b The second Point4 object.
84
+ * @param t The interpolation factor.
85
+ * @returns The interpolated Point4 object.
86
+ */
45
87
  static slerp(a, b, t) {
46
88
  let dot = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
47
89
  let theta = Math.acos(dot);
@@ -56,13 +98,22 @@ class Qtrn {
56
98
  }
57
99
  return { x, y, z, w };
58
100
  }
59
- /** creates quaternion from simple angle around axis. Assumes that axis vector is normalized */
101
+ /**
102
+ * Converts an angle and an axis of rotation into a quaternion
103
+ * @param axis the axis of rotation
104
+ * @param angle the angle of rotation in radians
105
+ * @returns a quaternion representing the rotation
106
+ */
60
107
  static fromAngle(axis, angle) {
61
108
  // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
62
109
  const halfAngle = angle / 2, s = Math.sin(halfAngle);
63
110
  return Object.assign(Object.assign({}, point3_1.Pnt3.scalarMult(axis, s)), { w: Math.cos(halfAngle) });
64
111
  }
65
- /** creates quaternion from 4-dimension rotation matrix */
112
+ /**
113
+ * Converts a 4x4 matrix representing a rotation into a quaternion
114
+ * @param m the matrix representing the rotation
115
+ * @returns a quaternion representing the rotation
116
+ */
66
117
  static fromMatrix4(m) {
67
118
  // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
68
119
  // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
@@ -104,7 +155,11 @@ class Qtrn {
104
155
  };
105
156
  }
106
157
  }
107
- /** creates a quaternion from euler */
158
+ /**
159
+ * Creates a quaternion from euler
160
+ * @param e the euler vector
161
+ * @returns a quaternion representing the rotation
162
+ */
108
163
  static fromEuler(e) {
109
164
  const roll = e.x;
110
165
  const pitch = e.y;
@@ -121,7 +176,11 @@ class Qtrn {
121
176
  const qz = cr * cp * sy - sr * sp * cy;
122
177
  return { w: qw, x: qx, y: qy, z: qz };
123
178
  }
124
- /** converts a quaternion to euler */
179
+ /**
180
+ * Converts a quaternion to euler
181
+ * @param q Point4 object
182
+ * @returns an Euler vector, representing the same rotation
183
+ */
125
184
  static toEuler(q) {
126
185
  const qw = q.w;
127
186
  const qx = q.x;
@@ -137,9 +196,33 @@ class Qtrn {
137
196
  const yaw = Math.atan2(siny_cosp, cosy_cosp);
138
197
  return { x: roll, y: pitch, z: yaw };
139
198
  }
140
- /** creates a rotation for object, so it will look at some point in space */
199
+ /**
200
+ * Returns a quaternion that represents the rotation required to align an object to face towards a target point.
201
+ * @param eye - The position of the camera or object that needs to be rotated to face the target point.
202
+ * @param target - The target point to look at
203
+ * @param up - The up direction of the object
204
+ * @returns A new quaternion representing the rotation required to face towards the target point.
205
+ */
141
206
  static lookAt(eye, target, up) {
142
207
  return this.fromMatrix4(matrix4_1.Mtrx4.lookAt(eye, target, up));
143
208
  }
209
+ /**
210
+ * Returns a quaternion that represents the input quaternion, rotated around provided axis vector by provided angle.
211
+ * Assumes that axis vector is already normalized
212
+ * @param q - Input quaternion.
213
+ * @param axis - Axis vector
214
+ * @param angle - Angle
215
+ * @returns A new quaternion representing the updated rotation.
216
+ */
217
+ static rotAround(q, axis, angle) {
218
+ const sinHalfAngle = Math.sin(angle / 2);
219
+ const rotationQuat = {
220
+ w: Math.cos(angle / 2),
221
+ x: axis.x * sinHalfAngle,
222
+ y: axis.y * sinHalfAngle,
223
+ z: axis.z * sinHalfAngle,
224
+ };
225
+ return this.mult(rotationQuat, q);
226
+ }
144
227
  }
145
228
  exports.Qtrn = Qtrn;
@@ -1,15 +1,15 @@
1
1
  export declare type Point2 = {
2
- x: number;
3
- y: number;
2
+ readonly x: number;
3
+ readonly y: number;
4
4
  };
5
5
  export declare type Point3 = {
6
- x: number;
7
- y: number;
8
- z: number;
6
+ readonly x: number;
7
+ readonly y: number;
8
+ readonly z: number;
9
9
  };
10
10
  export declare type Point4 = {
11
- x: number;
12
- y: number;
13
- z: number;
14
- w: number;
11
+ readonly x: number;
12
+ readonly y: number;
13
+ readonly z: number;
14
+ readonly w: number;
15
15
  };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- export * from './base/clock';
1
+ export * from './base/clock/clock';
2
+ export * from './base/clock/global-clock';
2
3
  export * from './base/gg-viewport';
3
4
  export * from './base/gg-viewport-manager';
5
+ export * from './base/entities/controllers/animation-mixer';
4
6
  export * from './base/entities/interfaces/i-tick-listener';
5
7
  export * from './base/entities/gg-entity';
6
8
  export * from './base/entities/base-gg-renderer';
@@ -25,6 +27,7 @@ export * from './base/controllers/common';
25
27
  export * from './base/controllers/i-controller';
26
28
  export * from './base/controllers/keyboard.controller';
27
29
  export * from './base/controllers/mouse.controller';
30
+ export * from './2d/entities/controllers/entity-2d-positioning.animator';
28
31
  export * from './2d/entities/gg-2d-entity';
29
32
  export * from './2d/entities/gg-positionable-2d-entity';
30
33
  export * from './2d/entities/gg-2d-trigger.entity';
@@ -35,7 +38,8 @@ export * from './2d/factories';
35
38
  export * from './2d/gg-2d-world';
36
39
  export * from './3d/controllers/car-keyboard.controller';
37
40
  export * from './3d/controllers/free-camera.controller';
38
- export * from './3d/entities/controllers/entity-motion.controller';
41
+ export * from './3d/entities/controllers/camera-3d.animator';
42
+ export * from './3d/entities/controllers/entity-3d-positioning.animator';
39
43
  export * from './3d/entities/gg-3d-entity';
40
44
  export * from './3d/entities/gg-positionable-3d-entity';
41
45
  export * from './3d/entities/gg-3d-camera.entity';
package/dist/index.js CHANGED
@@ -14,9 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./base/clock"), exports);
17
+ __exportStar(require("./base/clock/clock"), exports);
18
+ __exportStar(require("./base/clock/global-clock"), exports);
18
19
  __exportStar(require("./base/gg-viewport"), exports);
19
20
  __exportStar(require("./base/gg-viewport-manager"), exports);
21
+ __exportStar(require("./base/entities/controllers/animation-mixer"), exports);
20
22
  __exportStar(require("./base/entities/interfaces/i-tick-listener"), exports);
21
23
  __exportStar(require("./base/entities/gg-entity"), exports);
22
24
  __exportStar(require("./base/entities/base-gg-renderer"), exports);
@@ -41,6 +43,7 @@ __exportStar(require("./base/controllers/common"), exports);
41
43
  __exportStar(require("./base/controllers/i-controller"), exports);
42
44
  __exportStar(require("./base/controllers/keyboard.controller"), exports);
43
45
  __exportStar(require("./base/controllers/mouse.controller"), exports);
46
+ __exportStar(require("./2d/entities/controllers/entity-2d-positioning.animator"), exports);
44
47
  __exportStar(require("./2d/entities/gg-2d-entity"), exports);
45
48
  __exportStar(require("./2d/entities/gg-positionable-2d-entity"), exports);
46
49
  __exportStar(require("./2d/entities/gg-2d-trigger.entity"), exports);
@@ -51,7 +54,8 @@ __exportStar(require("./2d/factories"), exports);
51
54
  __exportStar(require("./2d/gg-2d-world"), exports);
52
55
  __exportStar(require("./3d/controllers/car-keyboard.controller"), exports);
53
56
  __exportStar(require("./3d/controllers/free-camera.controller"), exports);
54
- __exportStar(require("./3d/entities/controllers/entity-motion.controller"), exports);
57
+ __exportStar(require("./3d/entities/controllers/camera-3d.animator"), exports);
58
+ __exportStar(require("./3d/entities/controllers/entity-3d-positioning.animator"), exports);
55
59
  __exportStar(require("./3d/entities/gg-3d-entity"), exports);
56
60
  __exportStar(require("./3d/entities/gg-positionable-3d-entity"), exports);
57
61
  __exportStar(require("./3d/entities/gg-3d-camera.entity"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gg-web-engine/core",
3
- "version": "0.0.02",
3
+ "version": "0.0.03",
4
4
  "description": "An attempt to create open source game engine for browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/.prettierrc DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "semi": true,
3
- "trailingComma": "all",
4
- "singleQuote": true,
5
- "bracketSameLine":true,
6
- "printWidth": 120,
7
- "arrowParens": "avoid"
8
- }