@openglobus/og 0.11.5 → 0.11.6

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 (145) hide show
  1. package/package.json +5 -7
  2. package/src/og/Clock.js +6 -10
  3. package/src/og/Events.js +5 -7
  4. package/src/og/Extent.js +73 -32
  5. package/src/og/ImageCanvas.js +18 -15
  6. package/src/og/LonLat.js +13 -10
  7. package/src/og/Popup.js +18 -17
  8. package/src/og/QueueArray.js +3 -4
  9. package/src/og/Rectangle.js +4 -6
  10. package/src/og/Stack.js +2 -4
  11. package/src/og/ajax.js +20 -14
  12. package/src/og/astro/earth.js +21 -15
  13. package/src/og/bv/Box.js +2 -3
  14. package/src/og/bv/Sphere.js +10 -7
  15. package/src/og/camera/Frustum.js +19 -12
  16. package/src/og/camera/PlanetCamera.js +0 -1
  17. package/src/og/control/CompassButton.js +1 -2
  18. package/src/og/control/Control.js +7 -9
  19. package/src/og/control/DebugInfo.js +0 -1
  20. package/src/og/control/KeyboardNavigation.js +9 -9
  21. package/src/og/control/LayerSwitcher.js +21 -20
  22. package/src/og/control/SegmentBoundVisualization.js +5 -6
  23. package/src/og/control/ShowFps.js +12 -7
  24. package/src/og/control/SimpleNavigation.js +5 -7
  25. package/src/og/control/Sun.js +22 -12
  26. package/src/og/control/ToggleWireframe.js +3 -3
  27. package/src/og/control/TouchNavigation.js +43 -32
  28. package/src/og/control/ZoomControl.js +40 -24
  29. package/src/og/ellipsoid/Ellipsoid.js +148 -56
  30. package/src/og/ellipsoid/wgs84.js +3 -3
  31. package/src/og/entity/BaseBillboard.js +65 -14
  32. package/src/og/entity/Billboard.js +9 -5
  33. package/src/og/entity/BillboardHandler.js +310 -64
  34. package/src/og/entity/Entity.js +39 -1
  35. package/src/og/entity/EntityCollection.js +47 -24
  36. package/src/og/entity/GeoObject.js +228 -0
  37. package/src/og/entity/GeoObjectHandler.js +910 -0
  38. package/src/og/entity/GeometryHandler.js +595 -123
  39. package/src/og/entity/Label.js +53 -18
  40. package/src/og/entity/LabelHandler.js +42 -244
  41. package/src/og/entity/LabelWorker.js +213 -0
  42. package/src/og/entity/Object3d.js +504 -0
  43. package/src/og/entity/PointCloud.js +76 -28
  44. package/src/og/entity/PointCloudHandler.js +5 -5
  45. package/src/og/entity/Ray.js +49 -16
  46. package/src/og/entity/Strip.js +72 -43
  47. package/src/og/entity/StripHandler.js +23 -23
  48. package/src/og/layer/BaseGeoImage.js +50 -19
  49. package/src/og/layer/CanvasTiles.js +16 -16
  50. package/src/og/layer/GeoImage.js +6 -6
  51. package/src/og/layer/KML.js +55 -33
  52. package/src/og/layer/Layer.js +3 -3
  53. package/src/og/layer/Vector.js +94 -48
  54. package/src/og/layer/WMS.js +33 -16
  55. package/src/og/light/LightSource.js +19 -12
  56. package/src/og/math/Mat3.js +24 -12
  57. package/src/og/math/Mat4.js +603 -603
  58. package/src/og/math/Plane.js +19 -18
  59. package/src/og/math/Ray.js +17 -12
  60. package/src/og/math/Vec2.js +24 -14
  61. package/src/og/math/Vec3.js +60 -30
  62. package/src/og/math/coder.js +7 -7
  63. package/src/og/proj/EPSG3857.js +3 -3
  64. package/src/og/proj/EPSG4326.js +3 -3
  65. package/src/og/proj/Proj.js +2 -4
  66. package/src/og/quadTree/Node.js +31 -17
  67. package/src/og/renderer/Renderer.js +23 -6
  68. package/src/og/renderer/RendererEvents.js +1 -1
  69. package/src/og/scene/BaseNode.js +2 -3
  70. package/src/og/scene/Planet.js +2 -2
  71. package/src/og/scene/RenderNode.js +15 -8
  72. package/src/og/shaders/geoObject.js +211 -0
  73. package/src/og/shaders/pointCloud.js +41 -41
  74. package/src/og/shaders/shape.js +12 -18
  75. package/src/og/shaders/skybox.js +36 -36
  76. package/src/og/shapes/BaseShape.js +107 -35
  77. package/src/og/shapes/Icosphere.js +25 -10
  78. package/src/og/shapes/Sphere.js +8 -11
  79. package/src/og/utils/TextureAtlas.js +16 -18
  80. package/src/og/utils/shared.js +1 -1
  81. package/src/og/webgl/Handler.js +68 -49
  82. package/src/og/webgl/Multisample.js +44 -16
  83. package/src/og/webgl/Program.js +78 -33
  84. package/src/og/webgl/callbacks.js +3 -3
  85. package/types/Deferred.d.ts +1 -1
  86. package/types/Events.d.ts +2 -2
  87. package/types/Extent.d.ts +1 -1
  88. package/types/Rectangle.d.ts +1 -1
  89. package/types/ajax.d.ts +1 -1
  90. package/types/bv/Box.d.ts +1 -1
  91. package/types/bv/Sphere.d.ts +1 -1
  92. package/types/camera/Camera.d.ts +5 -5
  93. package/types/camera/Frustum.d.ts +6 -6
  94. package/types/camera/PlanetCamera.d.ts +8 -8
  95. package/types/control/Control.d.ts +1 -1
  96. package/types/control/EarthCoordinates.d.ts +1 -1
  97. package/types/control/Sun.d.ts +1 -1
  98. package/types/entity/BaseBillboard.d.ts +15 -8
  99. package/types/entity/Entity.d.ts +24 -9
  100. package/types/entity/EntityCollection.d.ts +15 -9
  101. package/types/entity/GeoObject.d.ts +111 -0
  102. package/types/entity/GeoObjectHandler.d.ts +77 -0
  103. package/types/entity/Geometry.d.ts +1 -1
  104. package/types/entity/GeometryHandler.d.ts +1 -1
  105. package/types/entity/Label.d.ts +3 -3
  106. package/types/entity/LabelHandler.d.ts +2 -0
  107. package/types/entity/LabelWorker.d.ts +9 -0
  108. package/types/entity/PointCloud.d.ts +1 -1
  109. package/types/entity/Polyline.d.ts +5 -5
  110. package/types/entity/Ray.d.ts +1 -1
  111. package/types/entity/Strip.d.ts +1 -1
  112. package/types/layer/BaseGeoImage.d.ts +3 -3
  113. package/types/layer/CanvasTiles.d.ts +5 -5
  114. package/types/layer/GeoImage.d.ts +1 -1
  115. package/types/layer/GeoVideo.d.ts +1 -1
  116. package/types/layer/Layer.d.ts +5 -5
  117. package/types/layer/Vector.d.ts +9 -9
  118. package/types/layer/XYZ.d.ts +3 -3
  119. package/types/light/LightSource.d.ts +7 -7
  120. package/types/math/Plane.d.ts +1 -1
  121. package/types/math/Ray.d.ts +1 -1
  122. package/types/math/Vec2.d.ts +34 -34
  123. package/types/math/Vec3.d.ts +1 -1
  124. package/types/math/Vec4.d.ts +1 -1
  125. package/types/math/coder.d.ts +1 -1
  126. package/types/math.d.ts +1 -1
  127. package/types/proj/Proj.d.ts +2 -2
  128. package/types/quadTree/Node.d.ts +1 -1
  129. package/types/renderer/Renderer.d.ts +12 -10
  130. package/types/renderer/RendererEvents.d.ts +1 -1
  131. package/types/scene/BaseNode.d.ts +4 -4
  132. package/types/scene/Planet.d.ts +40 -40
  133. package/types/scene/RenderNode.d.ts +9 -9
  134. package/types/segment/Segment.d.ts +9 -9
  135. package/types/shaders/geoObject.d.ts +3 -0
  136. package/types/shapes/BaseShape.d.ts +5 -5
  137. package/types/terrain/EmptyTerrain.d.ts +2 -2
  138. package/types/terrain/GlobusTerrain.d.ts +4 -4
  139. package/types/utils/TextureAtlas.d.ts +4 -4
  140. package/types/utils/shared.d.ts +9 -9
  141. package/types/webgl/Framebuffer.d.ts +1 -1
  142. package/types/webgl/Handler.d.ts +16 -7
  143. package/types/webgl/Multisample.d.ts +2 -2
  144. package/types/webgl/Program.d.ts +6 -0
  145. package/types/webgl/ProgramController.d.ts +1 -1
@@ -1,603 +1,603 @@
1
- "use strict";
2
-
3
- import { Mat3 } from "./Mat3.js";
4
- import { Quat } from "./Quat.js";
5
- import { Vec3 } from "./Vec3.js";
6
- import { Vec4 } from "./Vec4.js";
7
-
8
- /**
9
- * Class represents a 4x4 matrix.
10
- * @class
11
- */
12
- export class Mat4 {
13
- constructor() {
14
- /**
15
- * A 4x4 matrix, indexable as a column-major order array.
16
- * @public
17
- * @type {Array.<number>}
18
- */
19
- this._m = new Array(16);
20
- }
21
-
22
- /**
23
- * Returns identity matrix instance.
24
- * @static
25
- * @returns {Mat4} -
26
- */
27
- static identity() {
28
- var res = new Mat4();
29
- res._m[0] = 1;
30
- res._m[1] = 0;
31
- res._m[2] = 0;
32
- res._m[3] = 0;
33
- res._m[4] = 0;
34
- res._m[5] = 1;
35
- res._m[6] = 0;
36
- res._m[7] = 0;
37
- res._m[8] = 0;
38
- res._m[9] = 0;
39
- res._m[10] = 1;
40
- res._m[11] = 0;
41
- res._m[12] = 0;
42
- res._m[13] = 0;
43
- res._m[14] = 0;
44
- res._m[15] = 1;
45
- return res;
46
- }
47
-
48
- /**
49
- * Sets column-major order array matrix.
50
- * @public
51
- * @param {Array.<number>} m - Matrix array.
52
- * @returns {Mat4} -
53
- */
54
- set(m) {
55
- this._m[0] = m[0];
56
- this._m[1] = m[1];
57
- this._m[2] = m[2];
58
- this._m[3] = m[3];
59
- this._m[4] = m[4];
60
- this._m[5] = m[5];
61
- this._m[6] = m[6];
62
- this._m[7] = m[7];
63
- this._m[8] = m[8];
64
- this._m[9] = m[9];
65
- this._m[10] = m[10];
66
- this._m[11] = m[11];
67
- this._m[12] = m[12];
68
- this._m[13] = m[13];
69
- this._m[14] = m[14];
70
- this._m[15] = m[15];
71
- return this;
72
- }
73
-
74
- /**
75
- * Duplicates a Matrix3 instance.
76
- * @public
77
- * @returns {Mat4} -
78
- */
79
- clone() {
80
- var res = new Mat4();
81
- res.set(this);
82
- return res;
83
- }
84
-
85
- /**
86
- * Copy matrix.
87
- * @public
88
- * @param {Mat3} a - Matrix to copy.
89
- */
90
- copy(a) {
91
- this.set(a._m);
92
- }
93
-
94
- /**
95
- * Converts to 3x3 matrix.
96
- * @public
97
- * @returns {Mat3} -
98
- */
99
- toMatrix3() {
100
- var res = new Mat3();
101
- var a = this._m,
102
- b = res._m;
103
- b[0] = a[0];
104
- b[1] = a[1];
105
- b[2] = a[2];
106
- b[3] = a[4];
107
- b[4] = a[5];
108
- b[5] = a[6];
109
- b[6] = a[8];
110
- b[7] = a[9];
111
- b[8] = a[10];
112
- return res;
113
- }
114
-
115
- /**
116
- * Multiply to 3d vector.
117
- * @public
118
- * @param {Vec3} p - 3d vector.
119
- * @returns {Vec3} -
120
- */
121
- mulVec3(p) {
122
- var d = p.x,
123
- e = p.y,
124
- g = p.z;
125
- return new Vec3(
126
- this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12],
127
- this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13],
128
- this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14]
129
- );
130
- }
131
-
132
- /**
133
- * Multiply to 4d vector.
134
- * @public
135
- * @param {Vec4} p - 4d vector.
136
- * @returns {Vec4} -
137
- */
138
- mulVec4(p) {
139
- var d = p.x,
140
- e = p.y,
141
- g = p.z,
142
- f = p.w;
143
- return new Vec4(
144
- this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12] * f,
145
- this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13] * f,
146
- this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14] * f,
147
- this._m[3] * d + this._m[7] * e + this._m[11] * g + this._m[15] * f
148
- );
149
- }
150
-
151
- /**
152
- * Creates an inversed 3x3 matrix of the current.
153
- * @public
154
- * @returns {Mat3} -
155
- */
156
- toInverseMatrix3() {
157
- var a = this._m;
158
- var c = a[0],
159
- d = a[1],
160
- e = a[2],
161
- g = a[4],
162
- f = a[5],
163
- h = a[6],
164
- i = a[8],
165
- j = a[9],
166
- k = a[10],
167
- l = k * f - h * j,
168
- o = -k * g + h * i,
169
- m = j * g - f * i,
170
- n = c * l + d * o + e * m;
171
-
172
- if (!n) {
173
- return null;
174
- }
175
-
176
- n = 1 / n;
177
-
178
- var res = new Mat3();
179
- res._m[0] = l * n;
180
- res._m[1] = (-k * d + e * j) * n;
181
- res._m[2] = (h * d - e * f) * n;
182
- res._m[3] = o * n;
183
- res._m[4] = (k * c - e * i) * n;
184
- res._m[5] = (-h * c + e * g) * n;
185
- res._m[6] = m * n;
186
- res._m[7] = (-j * c + d * i) * n;
187
- res._m[8] = (f * c - d * g) * n;
188
- return res;
189
- }
190
-
191
- /**
192
- * Creates an inversed matrix of the current.
193
- * @public
194
- * @returns {Mat4} -
195
- */
196
- inverseTo(res) {
197
- var c = this._m[0],
198
- d = this._m[1],
199
- e = this._m[2],
200
- g = this._m[3],
201
- f = this._m[4],
202
- h = this._m[5],
203
- i = this._m[6],
204
- j = this._m[7],
205
- k = this._m[8],
206
- l = this._m[9],
207
- o = this._m[10],
208
- m = this._m[11],
209
- n = this._m[12],
210
- p = this._m[13],
211
- r = this._m[14],
212
- s = this._m[15],
213
- A = c * h - d * f,
214
- B = c * i - e * f,
215
- t = c * j - g * f,
216
- u = d * i - e * h,
217
- v = d * j - g * h,
218
- w = e * j - g * i,
219
- x = k * p - l * n,
220
- y = k * r - o * n,
221
- z = k * s - m * n,
222
- C = l * r - o * p,
223
- D = l * s - m * p,
224
- E = o * s - m * r,
225
- q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x);
226
-
227
- res = res || new Mat4();
228
-
229
- res._m[0] = (h * E - i * D + j * C) * q;
230
- res._m[1] = (-d * E + e * D - g * C) * q;
231
- res._m[2] = (p * w - r * v + s * u) * q;
232
- res._m[3] = (-l * w + o * v - m * u) * q;
233
- res._m[4] = (-f * E + i * z - j * y) * q;
234
- res._m[5] = (c * E - e * z + g * y) * q;
235
- res._m[6] = (-n * w + r * t - s * B) * q;
236
- res._m[7] = (k * w - o * t + m * B) * q;
237
- res._m[8] = (f * D - h * z + j * x) * q;
238
- res._m[9] = (-c * D + d * z - g * x) * q;
239
- res._m[10] = (n * v - p * t + s * A) * q;
240
- res._m[11] = (-k * v + l * t - m * A) * q;
241
- res._m[12] = (-f * C + h * y - i * x) * q;
242
- res._m[13] = (c * C - d * y + e * x) * q;
243
- res._m[14] = (-n * u + p * B - r * A) * q;
244
- res._m[15] = (k * u - l * B + o * A) * q;
245
- return res;
246
- }
247
-
248
- /**
249
- * Creates a trasposed matrix of the current.
250
- * @public
251
- * @returns {Mat4} -
252
- */
253
- transposeTo() {
254
- var res = new Mat4();
255
- res._m[0] = this._m[0];
256
- res._m[1] = this._m[4];
257
- res._m[2] = this._m[8];
258
- res._m[3] = this._m[12];
259
- res._m[4] = this._m[1];
260
- res._m[5] = this._m[5];
261
- res._m[6] = this._m[9];
262
- res._m[7] = this._m[13];
263
- res._m[8] = this._m[2];
264
- res._m[9] = this._m[6];
265
- res._m[10] = this._m[10];
266
- res._m[11] = this._m[14];
267
- res._m[12] = this._m[3];
268
- res._m[13] = this._m[7];
269
- res._m[14] = this._m[11];
270
- res._m[15] = this._m[15];
271
- return res;
272
- }
273
-
274
- /**
275
- * Sets matrix to identity.
276
- * @public
277
- * @returns {Mat4} -
278
- */
279
- setIdentity() {
280
- this._m[0] = 1;
281
- this._m[1] = 0;
282
- this._m[2] = 0;
283
- this._m[3] = 0;
284
- this._m[4] = 0;
285
- this._m[5] = 1;
286
- this._m[6] = 0;
287
- this._m[7] = 0;
288
- this._m[8] = 0;
289
- this._m[9] = 0;
290
- this._m[10] = 1;
291
- this._m[11] = 0;
292
- this._m[12] = 0;
293
- this._m[13] = 0;
294
- this._m[14] = 0;
295
- this._m[15] = 1;
296
- return this;
297
- }
298
-
299
- /**
300
- * Computes the product of two matrices.
301
- * @public
302
- * @param {Mat4} mx - Matrix to multiply.
303
- * @returns {Mat4} -
304
- */
305
- mul(mx) {
306
- let d = this._m[0],
307
- e = this._m[1],
308
- g = this._m[2],
309
- f = this._m[3],
310
- h = this._m[4],
311
- i = this._m[5],
312
- j = this._m[6],
313
- k = this._m[7],
314
- l = this._m[8],
315
- o = this._m[9],
316
- m = this._m[10],
317
- n = this._m[11],
318
- p = this._m[12],
319
- r = this._m[13],
320
- s = this._m[14],
321
- a = this._m[15];
322
-
323
- let A = mx._m[0],
324
- B = mx._m[1],
325
- t = mx._m[2],
326
- u = mx._m[3],
327
- v = mx._m[4],
328
- w = mx._m[5],
329
- x = mx._m[6],
330
- y = mx._m[7],
331
- z = mx._m[8],
332
- C = mx._m[9],
333
- D = mx._m[10],
334
- E = mx._m[11],
335
- q = mx._m[12],
336
- F = mx._m[13],
337
- G = mx._m[14],
338
- b = mx._m[15];
339
-
340
- var res = new Mat4();
341
- res._m[0] = A * d + B * h + t * l + u * p;
342
- res._m[1] = A * e + B * i + t * o + u * r;
343
- res._m[2] = A * g + B * j + t * m + u * s;
344
- res._m[3] = A * f + B * k + t * n + u * a;
345
- res._m[4] = v * d + w * h + x * l + y * p;
346
- res._m[5] = v * e + w * i + x * o + y * r;
347
- res._m[6] = v * g + w * j + x * m + y * s;
348
- res._m[7] = v * f + w * k + x * n + y * a;
349
- res._m[8] = z * d + C * h + D * l + E * p;
350
- res._m[9] = z * e + C * i + D * o + E * r;
351
- res._m[10] = z * g + C * j + D * m + E * s;
352
- res._m[11] = z * f + C * k + D * n + E * a;
353
- res._m[12] = q * d + F * h + G * l + b * p;
354
- res._m[13] = q * e + F * i + G * o + b * r;
355
- res._m[14] = q * g + F * j + G * m + b * s;
356
- res._m[15] = q * f + F * k + G * n + b * a;
357
- return res;
358
- }
359
-
360
- /**
361
- * Add translation vector to the current matrix.
362
- * @public
363
- * @param {Vec3} v - Translate vector.
364
- * @returns {Mat4} -
365
- */
366
- translate(v) {
367
- var d = v.x,
368
- e = v.y,
369
- b = v.z;
370
- var a = this._m;
371
- a[12] = a[0] * d + a[4] * e + a[8] * b + a[12];
372
- a[13] = a[1] * d + a[5] * e + a[9] * b + a[13];
373
- a[14] = a[2] * d + a[6] * e + a[10] * b + a[14];
374
- a[15] = a[3] * d + a[7] * e + a[11] * b + a[15];
375
- return this;
376
- }
377
-
378
- /**
379
- * Sets translation matrix to the position.
380
- * @public
381
- * @param {Vec3} v - Translate to position.
382
- * @returns {Mat4} -
383
- */
384
- translateToPosition(v) {
385
- var a = this._m;
386
- a[12] = v.x;
387
- a[13] = v.y;
388
- a[14] = v.z;
389
- return this;
390
- }
391
-
392
- /**
393
- * Rotate currrent matrix around the aligned axis and angle.
394
- * @public
395
- * @param {Vec3} u - Aligned axis.
396
- * @param {number} angle - Aligned axis angle in radians.
397
- * @returns {Mat4} -
398
- * @todo: OPTIMIZE: reveal multiplication
399
- */
400
- rotate(u, angle) {
401
- var c = Math.cos(angle),
402
- s = Math.sin(angle);
403
- var rot = new Mat4();
404
- var mx = rot._m;
405
- mx[0] = c + (1 - c) * u.x * u.x;
406
- mx[1] = (1 - c) * u.y * u.x - s * u.z;
407
- mx[2] = (1 - c) * u.z * u.x + s * u.y;
408
- mx[3] = 0;
409
- mx[4] = (1 - c) * u.x * u.y + s * u.z;
410
- mx[5] = c + (1 - c) * u.y * u.y;
411
- mx[6] = (1 - c) * u.z * u.y - s * u.x;
412
- mx[7] = 0;
413
- mx[8] = (1 - c) * u.x * u.z - s * u.y;
414
- mx[9] = (1 - c) * u.y * u.z + s * u.x;
415
- mx[10] = c + (1 - c) * u.z * u.z;
416
- mx[11] = 0;
417
- mx[12] = 0;
418
- mx[13] = 0;
419
- mx[14] = 0;
420
- mx[15] = 1;
421
- return this.mul(rot);
422
- }
423
-
424
- /**
425
- * Sets current rotation matrix around the aligned axis and angle.
426
- * @public
427
- * @param {Vec3} u - Aligned axis.
428
- * @param {number} angle - Aligned axis angle in radians.
429
- * @returns {Mat4} -
430
- */
431
- setRotation(u, angle) {
432
- var c = Math.cos(angle),
433
- s = Math.sin(angle);
434
- var mx = this._m;
435
- mx[0] = c + (1 - c) * u.x * u.x;
436
- mx[1] = (1 - c) * u.y * u.x - s * u.z;
437
- mx[2] = (1 - c) * u.z * u.x + s * u.y;
438
- mx[3] = 0;
439
- mx[4] = (1 - c) * u.x * u.y + s * u.z;
440
- mx[5] = c + (1 - c) * u.y * u.y;
441
- mx[6] = (1 - c) * u.z * u.y - s * u.x;
442
- mx[7] = 0;
443
- mx[8] = (1 - c) * u.x * u.z - s * u.y;
444
- mx[9] = (1 - c) * u.y * u.z + s * u.x;
445
- mx[10] = c + (1 - c) * u.z * u.z;
446
- mx[11] = 0;
447
- mx[12] = 0;
448
- mx[13] = 0;
449
- mx[14] = 0;
450
- mx[15] = 1;
451
- return this;
452
- }
453
-
454
- /**
455
- * Gets the rotation matrix from one vector to another.
456
- * @public
457
- * @param {Vec3} a - Firtst vector.
458
- * @param {Vec3} b - Second vector.
459
- * @returns {Mat4} -
460
- */
461
- rotateBetweenVectors(a, b) {
462
- var q = Quat.getRotationBetweenVectors(a, b);
463
- return q.getMat4();
464
- }
465
-
466
- /**
467
- * Scale current matrix to the vector values.
468
- * @public
469
- * @param {Vec3} v - Scale vector.
470
- * @returns {Mat4} -
471
- */
472
- scale(v) {
473
- var mx = this._m;
474
- mx[0] = mx[0] * v.x;
475
- mx[1] = mx[1] * v.x;
476
- mx[2] = mx[2] * v.x;
477
- mx[3] = mx[3] * v.x;
478
- mx[4] = mx[4] * v.y;
479
- mx[5] = mx[5] * v.y;
480
- mx[6] = mx[6] * v.y;
481
- mx[7] = mx[7] * v.y;
482
- mx[8] = mx[8] * v.z;
483
- mx[9] = mx[9] * v.z;
484
- mx[10] = mx[10] * v.z;
485
- mx[11] = mx[11] * v.z;
486
- return this;
487
- }
488
-
489
- /**
490
- * Sets perspective projection matrix frustum values.
491
- * @public
492
- * @param {number} left -
493
- * @param {number} right -
494
- * @param {number} bottom -
495
- * @param {number} top -
496
- * @param {number} near -
497
- * @param {number} far -
498
- * @returns {Mat4} -
499
- */
500
- setPerspective(left, right, bottom, top, near, far) {
501
- var h = right - left,
502
- i = top - bottom,
503
- j = far - near;
504
- this._m[0] = (near * 2) / h;
505
- this._m[1] = 0;
506
- this._m[2] = 0;
507
- this._m[3] = 0;
508
- this._m[4] = 0;
509
- this._m[5] = (near * 2) / i;
510
- this._m[6] = 0;
511
- this._m[7] = 0;
512
- this._m[8] = (right + left) / h;
513
- this._m[9] = (top + bottom) / i;
514
- this._m[10] = -(far + near) / j;
515
- this._m[11] = -1;
516
- this._m[12] = 0;
517
- this._m[13] = 0;
518
- this._m[14] = -(far * near * 2) / j;
519
- this._m[15] = 0;
520
- return this;
521
- }
522
-
523
- /**
524
- * Creates current orthographic projection matrix.
525
- * @public
526
- * @param {number} left -
527
- * @param {number} right -
528
- * @param {number} bottom -
529
- * @param {number} top -
530
- * @param {number} near -
531
- * @param {number} far -
532
- * @return {Mat4} -
533
- */
534
- setOrtho(left, right, bottom, top, near, far) {
535
- var lr = 1.0 / (left - right),
536
- bt = 1.0 / (bottom - top),
537
- nf = 1.0 / (near - far),
538
- m = this._m;
539
-
540
- m[0] = -2.0 * lr;
541
- m[1] = 0;
542
- m[2] = 0;
543
- m[3] = 0;
544
- m[4] = 0;
545
- m[5] = -2.0 * bt;
546
- m[6] = 0;
547
- m[7] = 0;
548
- m[8] = 0;
549
- m[9] = 0;
550
- m[10] = 2.0 * nf;
551
- m[11] = 0;
552
- m[12] = (left + right) * lr;
553
- m[13] = (top + bottom) * bt;
554
- m[14] = (far + near) * nf;
555
- m[15] = 1.0;
556
- return this;
557
- }
558
-
559
- /**
560
- * Sets current rotation matrix by euler's angles.
561
- * @public
562
- * @param {number} ax - Rotation angle in radians arond X axis.
563
- * @param {number} ay - Rotation angle in radians arond Y axis.
564
- * @param {number} az - Rotation angle in radians arond Z axis.
565
- * @returns {Mat4} -
566
- */
567
- eulerToMatrix(ax, ay, az) {
568
- var a = Math.cos(ax),
569
- b = Math.sin(ax),
570
- c = Math.cos(ay),
571
- d = Math.sin(ay),
572
- e = Math.cos(az),
573
- f = Math.sin(az);
574
-
575
- var ad = a * d,
576
- bd = b * d;
577
-
578
- var mat = this._m;
579
-
580
- mat[0] = c * e;
581
- mat[1] = -c * f;
582
- mat[2] = -d;
583
- mat[4] = -bd * e + a * f;
584
- mat[5] = bd * f + a * e;
585
- mat[6] = -b * c;
586
- mat[8] = ad * e + b * f;
587
- mat[9] = -ad * f + b * e;
588
- mat[10] = a * c;
589
- mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
590
- mat[15] = 1;
591
-
592
- return this;
593
- }
594
- }
595
-
596
- /**
597
- * Mat4 factory.
598
- * @static
599
- * @returns {Mat4} -
600
- */
601
- export function mat4() {
602
- return new Mat4();
603
- }
1
+ "use strict";
2
+
3
+ import { Mat3 } from "./Mat3.js";
4
+ import { Quat } from "./Quat.js";
5
+ import { Vec3 } from "./Vec3.js";
6
+ import { Vec4 } from "./Vec4.js";
7
+
8
+ /**
9
+ * Class represents a 4x4 matrix.
10
+ * @class
11
+ */
12
+ export class Mat4 {
13
+ constructor() {
14
+ /**
15
+ * A 4x4 matrix, indexable as a column-major order array.
16
+ * @public
17
+ * @type {Array.<number>}
18
+ */
19
+ this._m = new Array(16);
20
+ }
21
+
22
+ /**
23
+ * Returns identity matrix instance.
24
+ * @static
25
+ * @returns {Mat4} -
26
+ */
27
+ static identity() {
28
+ var res = new Mat4();
29
+ res._m[0] = 1;
30
+ res._m[1] = 0;
31
+ res._m[2] = 0;
32
+ res._m[3] = 0;
33
+ res._m[4] = 0;
34
+ res._m[5] = 1;
35
+ res._m[6] = 0;
36
+ res._m[7] = 0;
37
+ res._m[8] = 0;
38
+ res._m[9] = 0;
39
+ res._m[10] = 1;
40
+ res._m[11] = 0;
41
+ res._m[12] = 0;
42
+ res._m[13] = 0;
43
+ res._m[14] = 0;
44
+ res._m[15] = 1;
45
+ return res;
46
+ }
47
+
48
+ /**
49
+ * Sets column-major order array matrix.
50
+ * @public
51
+ * @param {Array.<number>} m - Matrix array.
52
+ * @returns {Mat4} -
53
+ */
54
+ set(m) {
55
+ this._m[0] = m[0];
56
+ this._m[1] = m[1];
57
+ this._m[2] = m[2];
58
+ this._m[3] = m[3];
59
+ this._m[4] = m[4];
60
+ this._m[5] = m[5];
61
+ this._m[6] = m[6];
62
+ this._m[7] = m[7];
63
+ this._m[8] = m[8];
64
+ this._m[9] = m[9];
65
+ this._m[10] = m[10];
66
+ this._m[11] = m[11];
67
+ this._m[12] = m[12];
68
+ this._m[13] = m[13];
69
+ this._m[14] = m[14];
70
+ this._m[15] = m[15];
71
+ return this;
72
+ }
73
+
74
+ /**
75
+ * Duplicates a Matrix3 instance.
76
+ * @public
77
+ * @returns {Mat4} -
78
+ */
79
+ clone() {
80
+ var res = new Mat4();
81
+ res.set(this);
82
+ return res;
83
+ }
84
+
85
+ /**
86
+ * Copy matrix.
87
+ * @public
88
+ * @param {Mat3} a - Matrix to copy.
89
+ */
90
+ copy(a) {
91
+ this.set(a._m);
92
+ }
93
+
94
+ /**
95
+ * Converts to 3x3 matrix.
96
+ * @public
97
+ * @returns {Mat3} -
98
+ */
99
+ toMatrix3() {
100
+ var res = new Mat3();
101
+ var a = this._m,
102
+ b = res._m;
103
+ b[0] = a[0];
104
+ b[1] = a[1];
105
+ b[2] = a[2];
106
+ b[3] = a[4];
107
+ b[4] = a[5];
108
+ b[5] = a[6];
109
+ b[6] = a[8];
110
+ b[7] = a[9];
111
+ b[8] = a[10];
112
+ return res;
113
+ }
114
+
115
+ /**
116
+ * Multiply to 3d vector.
117
+ * @public
118
+ * @param {Vec3} p - 3d vector.
119
+ * @returns {Vec3} -
120
+ */
121
+ mulVec3(p) {
122
+ var d = p.x,
123
+ e = p.y,
124
+ g = p.z;
125
+ return new Vec3(
126
+ this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12],
127
+ this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13],
128
+ this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14]
129
+ );
130
+ }
131
+
132
+ /**
133
+ * Multiply to 4d vector.
134
+ * @public
135
+ * @param {Vec4} p - 4d vector.
136
+ * @returns {Vec4} -
137
+ */
138
+ mulVec4(p) {
139
+ var d = p.x,
140
+ e = p.y,
141
+ g = p.z,
142
+ f = p.w;
143
+ return new Vec4(
144
+ this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12] * f,
145
+ this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13] * f,
146
+ this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14] * f,
147
+ this._m[3] * d + this._m[7] * e + this._m[11] * g + this._m[15] * f
148
+ );
149
+ }
150
+
151
+ /**
152
+ * Creates an inversed 3x3 matrix of the current.
153
+ * @public
154
+ * @returns {Mat3} -
155
+ */
156
+ toInverseMatrix3() {
157
+ var a = this._m;
158
+ var c = a[0],
159
+ d = a[1],
160
+ e = a[2],
161
+ g = a[4],
162
+ f = a[5],
163
+ h = a[6],
164
+ i = a[8],
165
+ j = a[9],
166
+ k = a[10],
167
+ l = k * f - h * j,
168
+ o = -k * g + h * i,
169
+ m = j * g - f * i,
170
+ n = c * l + d * o + e * m;
171
+
172
+ if (!n) {
173
+ return null;
174
+ }
175
+
176
+ n = 1 / n;
177
+
178
+ var res = new Mat3();
179
+ res._m[0] = l * n;
180
+ res._m[1] = (-k * d + e * j) * n;
181
+ res._m[2] = (h * d - e * f) * n;
182
+ res._m[3] = o * n;
183
+ res._m[4] = (k * c - e * i) * n;
184
+ res._m[5] = (-h * c + e * g) * n;
185
+ res._m[6] = m * n;
186
+ res._m[7] = (-j * c + d * i) * n;
187
+ res._m[8] = (f * c - d * g) * n;
188
+ return res;
189
+ }
190
+
191
+ /**
192
+ * Creates an inversed matrix of the current.
193
+ * @public
194
+ * @returns {Mat4} -
195
+ */
196
+ inverseTo(res) {
197
+ var c = this._m[0],
198
+ d = this._m[1],
199
+ e = this._m[2],
200
+ g = this._m[3],
201
+ f = this._m[4],
202
+ h = this._m[5],
203
+ i = this._m[6],
204
+ j = this._m[7],
205
+ k = this._m[8],
206
+ l = this._m[9],
207
+ o = this._m[10],
208
+ m = this._m[11],
209
+ n = this._m[12],
210
+ p = this._m[13],
211
+ r = this._m[14],
212
+ s = this._m[15],
213
+ A = c * h - d * f,
214
+ B = c * i - e * f,
215
+ t = c * j - g * f,
216
+ u = d * i - e * h,
217
+ v = d * j - g * h,
218
+ w = e * j - g * i,
219
+ x = k * p - l * n,
220
+ y = k * r - o * n,
221
+ z = k * s - m * n,
222
+ C = l * r - o * p,
223
+ D = l * s - m * p,
224
+ E = o * s - m * r,
225
+ q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x);
226
+
227
+ res = res || new Mat4();
228
+
229
+ res._m[0] = (h * E - i * D + j * C) * q;
230
+ res._m[1] = (-d * E + e * D - g * C) * q;
231
+ res._m[2] = (p * w - r * v + s * u) * q;
232
+ res._m[3] = (-l * w + o * v - m * u) * q;
233
+ res._m[4] = (-f * E + i * z - j * y) * q;
234
+ res._m[5] = (c * E - e * z + g * y) * q;
235
+ res._m[6] = (-n * w + r * t - s * B) * q;
236
+ res._m[7] = (k * w - o * t + m * B) * q;
237
+ res._m[8] = (f * D - h * z + j * x) * q;
238
+ res._m[9] = (-c * D + d * z - g * x) * q;
239
+ res._m[10] = (n * v - p * t + s * A) * q;
240
+ res._m[11] = (-k * v + l * t - m * A) * q;
241
+ res._m[12] = (-f * C + h * y - i * x) * q;
242
+ res._m[13] = (c * C - d * y + e * x) * q;
243
+ res._m[14] = (-n * u + p * B - r * A) * q;
244
+ res._m[15] = (k * u - l * B + o * A) * q;
245
+ return res;
246
+ }
247
+
248
+ /**
249
+ * Creates a trasposed matrix of the current.
250
+ * @public
251
+ * @returns {Mat4} -
252
+ */
253
+ transposeTo() {
254
+ var res = new Mat4();
255
+ res._m[0] = this._m[0];
256
+ res._m[1] = this._m[4];
257
+ res._m[2] = this._m[8];
258
+ res._m[3] = this._m[12];
259
+ res._m[4] = this._m[1];
260
+ res._m[5] = this._m[5];
261
+ res._m[6] = this._m[9];
262
+ res._m[7] = this._m[13];
263
+ res._m[8] = this._m[2];
264
+ res._m[9] = this._m[6];
265
+ res._m[10] = this._m[10];
266
+ res._m[11] = this._m[14];
267
+ res._m[12] = this._m[3];
268
+ res._m[13] = this._m[7];
269
+ res._m[14] = this._m[11];
270
+ res._m[15] = this._m[15];
271
+ return res;
272
+ }
273
+
274
+ /**
275
+ * Sets matrix to identity.
276
+ * @public
277
+ * @returns {Mat4} -
278
+ */
279
+ setIdentity() {
280
+ this._m[0] = 1;
281
+ this._m[1] = 0;
282
+ this._m[2] = 0;
283
+ this._m[3] = 0;
284
+ this._m[4] = 0;
285
+ this._m[5] = 1;
286
+ this._m[6] = 0;
287
+ this._m[7] = 0;
288
+ this._m[8] = 0;
289
+ this._m[9] = 0;
290
+ this._m[10] = 1;
291
+ this._m[11] = 0;
292
+ this._m[12] = 0;
293
+ this._m[13] = 0;
294
+ this._m[14] = 0;
295
+ this._m[15] = 1;
296
+ return this;
297
+ }
298
+
299
+ /**
300
+ * Computes the product of two matrices.
301
+ * @public
302
+ * @param {Mat4} mx - Matrix to multiply.
303
+ * @returns {Mat4} -
304
+ */
305
+ mul(mx) {
306
+ let d = this._m[0],
307
+ e = this._m[1],
308
+ g = this._m[2],
309
+ f = this._m[3],
310
+ h = this._m[4],
311
+ i = this._m[5],
312
+ j = this._m[6],
313
+ k = this._m[7],
314
+ l = this._m[8],
315
+ o = this._m[9],
316
+ m = this._m[10],
317
+ n = this._m[11],
318
+ p = this._m[12],
319
+ r = this._m[13],
320
+ s = this._m[14],
321
+ a = this._m[15];
322
+
323
+ let A = mx._m[0],
324
+ B = mx._m[1],
325
+ t = mx._m[2],
326
+ u = mx._m[3],
327
+ v = mx._m[4],
328
+ w = mx._m[5],
329
+ x = mx._m[6],
330
+ y = mx._m[7],
331
+ z = mx._m[8],
332
+ C = mx._m[9],
333
+ D = mx._m[10],
334
+ E = mx._m[11],
335
+ q = mx._m[12],
336
+ F = mx._m[13],
337
+ G = mx._m[14],
338
+ b = mx._m[15];
339
+
340
+ var res = new Mat4();
341
+ res._m[0] = A * d + B * h + t * l + u * p;
342
+ res._m[1] = A * e + B * i + t * o + u * r;
343
+ res._m[2] = A * g + B * j + t * m + u * s;
344
+ res._m[3] = A * f + B * k + t * n + u * a;
345
+ res._m[4] = v * d + w * h + x * l + y * p;
346
+ res._m[5] = v * e + w * i + x * o + y * r;
347
+ res._m[6] = v * g + w * j + x * m + y * s;
348
+ res._m[7] = v * f + w * k + x * n + y * a;
349
+ res._m[8] = z * d + C * h + D * l + E * p;
350
+ res._m[9] = z * e + C * i + D * o + E * r;
351
+ res._m[10] = z * g + C * j + D * m + E * s;
352
+ res._m[11] = z * f + C * k + D * n + E * a;
353
+ res._m[12] = q * d + F * h + G * l + b * p;
354
+ res._m[13] = q * e + F * i + G * o + b * r;
355
+ res._m[14] = q * g + F * j + G * m + b * s;
356
+ res._m[15] = q * f + F * k + G * n + b * a;
357
+ return res;
358
+ }
359
+
360
+ /**
361
+ * Add translation vector to the current matrix.
362
+ * @public
363
+ * @param {Vec3} v - Translate vector.
364
+ * @returns {Mat4} -
365
+ */
366
+ translate(v) {
367
+ var d = v.x,
368
+ e = v.y,
369
+ b = v.z;
370
+ var a = this._m;
371
+ a[12] = a[0] * d + a[4] * e + a[8] * b + a[12];
372
+ a[13] = a[1] * d + a[5] * e + a[9] * b + a[13];
373
+ a[14] = a[2] * d + a[6] * e + a[10] * b + a[14];
374
+ a[15] = a[3] * d + a[7] * e + a[11] * b + a[15];
375
+ return this;
376
+ }
377
+
378
+ /**
379
+ * Sets translation matrix to the position.
380
+ * @public
381
+ * @param {Vec3} v - Translate to position.
382
+ * @returns {Mat4} -
383
+ */
384
+ translateToPosition(v) {
385
+ var a = this._m;
386
+ a[12] = v.x;
387
+ a[13] = v.y;
388
+ a[14] = v.z;
389
+ return this;
390
+ }
391
+
392
+ /**
393
+ * Rotate currrent matrix around the aligned axis and angle.
394
+ * @public
395
+ * @param {Vec3} u - Aligned axis.
396
+ * @param {number} angle - Aligned axis angle in radians.
397
+ * @returns {Mat4} -
398
+ * @todo: OPTIMIZE: reveal multiplication
399
+ */
400
+ rotate(u, angle) {
401
+ var c = Math.cos(angle),
402
+ s = Math.sin(angle);
403
+ var rot = new Mat4();
404
+ var mx = rot._m;
405
+ mx[0] = c + (1 - c) * u.x * u.x;
406
+ mx[1] = (1 - c) * u.y * u.x - s * u.z;
407
+ mx[2] = (1 - c) * u.z * u.x + s * u.y;
408
+ mx[3] = 0;
409
+ mx[4] = (1 - c) * u.x * u.y + s * u.z;
410
+ mx[5] = c + (1 - c) * u.y * u.y;
411
+ mx[6] = (1 - c) * u.z * u.y - s * u.x;
412
+ mx[7] = 0;
413
+ mx[8] = (1 - c) * u.x * u.z - s * u.y;
414
+ mx[9] = (1 - c) * u.y * u.z + s * u.x;
415
+ mx[10] = c + (1 - c) * u.z * u.z;
416
+ mx[11] = 0;
417
+ mx[12] = 0;
418
+ mx[13] = 0;
419
+ mx[14] = 0;
420
+ mx[15] = 1;
421
+ return this.mul(rot);
422
+ }
423
+
424
+ /**
425
+ * Sets current rotation matrix around the aligned axis and angle.
426
+ * @public
427
+ * @param {Vec3} u - Aligned axis.
428
+ * @param {number} angle - Aligned axis angle in radians.
429
+ * @returns {Mat4} -
430
+ */
431
+ setRotation(u, angle) {
432
+ var c = Math.cos(angle),
433
+ s = Math.sin(angle);
434
+ var mx = this._m;
435
+ mx[0] = c + (1 - c) * u.x * u.x;
436
+ mx[1] = (1 - c) * u.y * u.x - s * u.z;
437
+ mx[2] = (1 - c) * u.z * u.x + s * u.y;
438
+ mx[3] = 0;
439
+ mx[4] = (1 - c) * u.x * u.y + s * u.z;
440
+ mx[5] = c + (1 - c) * u.y * u.y;
441
+ mx[6] = (1 - c) * u.z * u.y - s * u.x;
442
+ mx[7] = 0;
443
+ mx[8] = (1 - c) * u.x * u.z - s * u.y;
444
+ mx[9] = (1 - c) * u.y * u.z + s * u.x;
445
+ mx[10] = c + (1 - c) * u.z * u.z;
446
+ mx[11] = 0;
447
+ mx[12] = 0;
448
+ mx[13] = 0;
449
+ mx[14] = 0;
450
+ mx[15] = 1;
451
+ return this;
452
+ }
453
+
454
+ /**
455
+ * Gets the rotation matrix from one vector to another.
456
+ * @public
457
+ * @param {Vec3} a - Firtst vector.
458
+ * @param {Vec3} b - Second vector.
459
+ * @returns {Mat4} -
460
+ */
461
+ rotateBetweenVectors(a, b) {
462
+ var q = Quat.getRotationBetweenVectors(a, b);
463
+ return q.getMat4();
464
+ }
465
+
466
+ /**
467
+ * Scale current matrix to the vector values.
468
+ * @public
469
+ * @param {Vec3} v - Scale vector.
470
+ * @returns {Mat4} -
471
+ */
472
+ scale(v) {
473
+ var mx = this._m;
474
+ mx[0] = mx[0] * v.x;
475
+ mx[1] = mx[1] * v.x;
476
+ mx[2] = mx[2] * v.x;
477
+ mx[3] = mx[3] * v.x;
478
+ mx[4] = mx[4] * v.y;
479
+ mx[5] = mx[5] * v.y;
480
+ mx[6] = mx[6] * v.y;
481
+ mx[7] = mx[7] * v.y;
482
+ mx[8] = mx[8] * v.z;
483
+ mx[9] = mx[9] * v.z;
484
+ mx[10] = mx[10] * v.z;
485
+ mx[11] = mx[11] * v.z;
486
+ return this;
487
+ }
488
+
489
+ /**
490
+ * Sets perspective projection matrix frustum values.
491
+ * @public
492
+ * @param {number} left -
493
+ * @param {number} right -
494
+ * @param {number} bottom -
495
+ * @param {number} top -
496
+ * @param {number} near -
497
+ * @param {number} far -
498
+ * @returns {Mat4} -
499
+ */
500
+ setPerspective(left, right, bottom, top, near, far) {
501
+ var h = right - left,
502
+ i = top - bottom,
503
+ j = far - near;
504
+ this._m[0] = (near * 2) / h;
505
+ this._m[1] = 0;
506
+ this._m[2] = 0;
507
+ this._m[3] = 0;
508
+ this._m[4] = 0;
509
+ this._m[5] = (near * 2) / i;
510
+ this._m[6] = 0;
511
+ this._m[7] = 0;
512
+ this._m[8] = (right + left) / h;
513
+ this._m[9] = (top + bottom) / i;
514
+ this._m[10] = -(far + near) / j;
515
+ this._m[11] = -1;
516
+ this._m[12] = 0;
517
+ this._m[13] = 0;
518
+ this._m[14] = -(far * near * 2) / j;
519
+ this._m[15] = 0;
520
+ return this;
521
+ }
522
+
523
+ /**
524
+ * Creates current orthographic projection matrix.
525
+ * @public
526
+ * @param {number} left -
527
+ * @param {number} right -
528
+ * @param {number} bottom -
529
+ * @param {number} top -
530
+ * @param {number} near -
531
+ * @param {number} far -
532
+ * @return {Mat4} -
533
+ */
534
+ setOrtho(left, right, bottom, top, near, far) {
535
+ var lr = 1.0 / (left - right),
536
+ bt = 1.0 / (bottom - top),
537
+ nf = 1.0 / (near - far),
538
+ m = this._m;
539
+
540
+ m[0] = -2.0 * lr;
541
+ m[1] = 0;
542
+ m[2] = 0;
543
+ m[3] = 0;
544
+ m[4] = 0;
545
+ m[5] = -2.0 * bt;
546
+ m[6] = 0;
547
+ m[7] = 0;
548
+ m[8] = 0;
549
+ m[9] = 0;
550
+ m[10] = 2.0 * nf;
551
+ m[11] = 0;
552
+ m[12] = (left + right) * lr;
553
+ m[13] = (top + bottom) * bt;
554
+ m[14] = (far + near) * nf;
555
+ m[15] = 1.0;
556
+ return this;
557
+ }
558
+
559
+ /**
560
+ * Sets current rotation matrix by euler's angles.
561
+ * @public
562
+ * @param {number} ax - Rotation angle in radians arond X axis.
563
+ * @param {number} ay - Rotation angle in radians arond Y axis.
564
+ * @param {number} az - Rotation angle in radians arond Z axis.
565
+ * @returns {Mat4} -
566
+ */
567
+ eulerToMatrix(ax, ay, az) {
568
+ var a = Math.cos(ax),
569
+ b = Math.sin(ax),
570
+ c = Math.cos(ay),
571
+ d = Math.sin(ay),
572
+ e = Math.cos(az),
573
+ f = Math.sin(az);
574
+
575
+ var ad = a * d,
576
+ bd = b * d;
577
+
578
+ var mat = this._m;
579
+
580
+ mat[0] = c * e;
581
+ mat[1] = -c * f;
582
+ mat[2] = -d;
583
+ mat[4] = -bd * e + a * f;
584
+ mat[5] = bd * f + a * e;
585
+ mat[6] = -b * c;
586
+ mat[8] = ad * e + b * f;
587
+ mat[9] = -ad * f + b * e;
588
+ mat[10] = a * c;
589
+ mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
590
+ mat[15] = 1;
591
+
592
+ return this;
593
+ }
594
+ }
595
+
596
+ /**
597
+ * Mat4 factory.
598
+ * @static
599
+ * @returns {Mat4} -
600
+ */
601
+ export function mat4() {
602
+ return new Mat4();
603
+ }