@openglobus/og 0.11.1 → 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 (255) hide show
  1. package/package.json +18 -20
  2. package/src/og/Clock.js +11 -11
  3. package/src/og/Deferred.js +1 -1
  4. package/src/og/Events.js +9 -7
  5. package/src/og/Extent.js +117 -72
  6. package/src/og/Globe.js +35 -22
  7. package/src/og/ImageCanvas.js +24 -18
  8. package/src/og/Lock.js +2 -2
  9. package/src/og/LonLat.js +40 -37
  10. package/src/og/Popup.js +21 -15
  11. package/src/og/QueueArray.js +7 -3
  12. package/src/og/Rectangle.js +11 -6
  13. package/src/og/Stack.js +8 -5
  14. package/src/og/ajax.js +21 -33
  15. package/src/og/astro/astro.js +5 -5
  16. package/src/og/astro/earth.js +23 -17
  17. package/src/og/astro/jd.js +44 -39
  18. package/src/og/astro/orbit.js +20 -18
  19. package/src/og/astro/rotation.js +17 -8
  20. package/src/og/bv/Box.js +7 -3
  21. package/src/og/bv/Sphere.js +17 -9
  22. package/src/og/camera/Camera.js +137 -86
  23. package/src/og/camera/Frustum.js +30 -19
  24. package/src/og/camera/PlanetCamera.js +30 -26
  25. package/src/og/control/CompassButton.js +8 -2
  26. package/src/og/control/Control.js +13 -11
  27. package/src/og/control/DebugInfo.js +4 -1
  28. package/src/og/control/EarthCoordinates.js +62 -41
  29. package/src/og/control/EarthNavigation.js +20 -22
  30. package/src/og/control/GeoImageDragControl.js +1 -1
  31. package/src/og/control/KeyboardNavigation.js +12 -12
  32. package/src/og/control/LayerSwitcher.js +24 -23
  33. package/src/og/control/Lighting.js +1 -1
  34. package/src/og/control/MouseNavigation.js +1 -1
  35. package/src/og/control/ScaleControl.js +1 -1
  36. package/src/og/control/SegmentBoundVisualization.js +8 -9
  37. package/src/og/control/ShowFps.js +15 -10
  38. package/src/og/control/SimpleNavigation.js +8 -10
  39. package/src/og/control/Sun.js +25 -15
  40. package/src/og/control/ToggleWireframe.js +5 -5
  41. package/src/og/control/TouchNavigation.js +58 -45
  42. package/src/og/control/ZoomControl.js +41 -25
  43. package/src/og/control/index.js +4 -0
  44. package/src/og/ellipsoid/Ellipsoid.js +181 -85
  45. package/src/og/ellipsoid/wgs84.js +4 -4
  46. package/src/og/entity/BaseBillboard.js +97 -44
  47. package/src/og/entity/Billboard.js +15 -11
  48. package/src/og/entity/BillboardHandler.js +314 -64
  49. package/src/og/entity/Entity.js +106 -74
  50. package/src/og/entity/EntityCollection.js +72 -49
  51. package/src/og/entity/GeoObject.js +228 -0
  52. package/src/og/entity/GeoObjectHandler.js +910 -0
  53. package/src/og/entity/Geometry.js +29 -26
  54. package/src/og/entity/GeometryHandler.js +598 -126
  55. package/src/og/entity/Label.js +74 -40
  56. package/src/og/entity/LabelHandler.js +47 -246
  57. package/src/og/entity/LabelWorker.js +213 -0
  58. package/src/og/entity/Object3d.js +504 -0
  59. package/src/og/entity/PointCloud.js +81 -33
  60. package/src/og/entity/PointCloudHandler.js +9 -9
  61. package/src/og/entity/Polyline.js +39 -39
  62. package/src/og/entity/Ray.js +61 -28
  63. package/src/og/entity/ShapeHandler.js +1 -1
  64. package/src/og/entity/Strip.js +77 -48
  65. package/src/og/entity/StripHandler.js +27 -27
  66. package/src/og/entity/index.js +8 -16
  67. package/src/og/input/KeyboardHandler.js +107 -104
  68. package/src/og/input/MouseHandler.js +81 -78
  69. package/src/og/input/TouchHandler.js +55 -51
  70. package/src/og/layer/BaseGeoImage.js +61 -30
  71. package/src/og/layer/CanvasTiles.js +26 -24
  72. package/src/og/layer/GeoImage.js +10 -10
  73. package/src/og/layer/GeoTexture2d.js +1 -1
  74. package/src/og/layer/GeoVideo.js +3 -3
  75. package/src/og/layer/KML.js +66 -40
  76. package/src/og/layer/Layer.js +27 -17
  77. package/src/og/layer/Material.js +93 -61
  78. package/src/og/layer/Vector.js +118 -72
  79. package/src/og/layer/WMS.js +36 -19
  80. package/src/og/layer/XYZ.js +55 -48
  81. package/src/og/light/LightSource.js +47 -40
  82. package/src/og/math/Line2.js +24 -24
  83. package/src/og/math/Line3.js +103 -102
  84. package/src/og/math/Mat3.js +134 -121
  85. package/src/og/math/Mat4.js +603 -459
  86. package/src/og/math/Plane.js +21 -20
  87. package/src/og/math/Quat.js +980 -927
  88. package/src/og/math/Ray.js +195 -187
  89. package/src/og/math/Vec2.js +127 -117
  90. package/src/og/math/Vec3.js +206 -176
  91. package/src/og/math/Vec4.js +49 -53
  92. package/src/og/math/coder.js +18 -18
  93. package/src/og/math.js +12 -12
  94. package/src/og/mercator.js +11 -11
  95. package/src/og/proj/EPSG3857.js +4 -4
  96. package/src/og/proj/EPSG4326.js +4 -4
  97. package/src/og/proj/Proj.js +31 -31
  98. package/src/og/quadTree/EntityCollectionNode.js +310 -300
  99. package/src/og/quadTree/Node.js +1008 -993
  100. package/src/og/renderer/Renderer.js +768 -747
  101. package/src/og/renderer/RendererEvents.js +9 -6
  102. package/src/og/scene/Axes.js +1 -1
  103. package/src/og/scene/BaseNode.js +8 -9
  104. package/src/og/scene/Planet.js +115 -87
  105. package/src/og/scene/RenderNode.js +29 -22
  106. package/src/og/scene/SkyBox.js +1 -1
  107. package/src/og/segment/Segment.js +1886 -1878
  108. package/src/og/segment/SegmentLonLat.js +298 -268
  109. package/src/og/segment/segmentHelper.js +11 -11
  110. package/src/og/shaders/bloom.js +1 -1
  111. package/src/og/shaders/blur.js +2 -2
  112. package/src/og/shaders/depth.js +1 -1
  113. package/src/og/shaders/geoObject.js +211 -0
  114. package/src/og/shaders/label.js +1 -1
  115. package/src/og/shaders/lumFilter.js +1 -1
  116. package/src/og/shaders/pointCloud.js +42 -42
  117. package/src/og/shaders/screenFrame.js +1 -1
  118. package/src/og/shaders/shape.js +15 -21
  119. package/src/og/shaders/skybox.js +37 -37
  120. package/src/og/shaders/toneMapping.js +1 -1
  121. package/src/og/shapes/BaseShape.js +129 -57
  122. package/src/og/shapes/Icosphere.js +30 -15
  123. package/src/og/shapes/Sphere.js +13 -16
  124. package/src/og/terrain/BilTerrain.js +2 -1
  125. package/src/og/terrain/EmptyTerrain.js +2 -2
  126. package/src/og/terrain/Geoid.js +2 -2
  127. package/src/og/terrain/GlobusTerrain.js +10 -10
  128. package/src/og/terrain/MapboxTerrain.js +1 -1
  129. package/src/og/utils/GeoImageCreator.js +9 -9
  130. package/src/og/utils/Loader.js +6 -6
  131. package/src/og/utils/NormalMapCreator.js +13 -13
  132. package/src/og/utils/TerrainWorker.js +1 -1
  133. package/src/og/utils/TextureAtlas.js +20 -22
  134. package/src/og/utils/VectorTileCreator.js +5 -5
  135. package/src/og/utils/earcut.js +1 -1
  136. package/src/og/utils/shared.js +15 -15
  137. package/src/og/webgl/Framebuffer.js +101 -53
  138. package/src/og/webgl/Handler.js +125 -85
  139. package/src/og/webgl/Multisample.js +55 -27
  140. package/src/og/webgl/Program.js +80 -35
  141. package/src/og/webgl/ProgramController.js +27 -23
  142. package/src/og/webgl/callbacks.js +8 -8
  143. package/types/Clock.d.ts +6 -2
  144. package/types/Deferred.d.ts +1 -1
  145. package/types/Events.d.ts +8 -4
  146. package/types/Extent.d.ts +37 -33
  147. package/types/Globe.d.ts +15 -13
  148. package/types/ImageCanvas.d.ts +5 -3
  149. package/types/LonLat.d.ts +24 -24
  150. package/types/Popup.d.ts +4 -0
  151. package/types/QueueArray.d.ts +6 -2
  152. package/types/Rectangle.d.ts +10 -4
  153. package/types/Stack.d.ts +4 -0
  154. package/types/ajax.d.ts +1 -1
  155. package/types/astro/earth.d.ts +3 -2
  156. package/types/bv/Box.d.ts +10 -5
  157. package/types/bv/Sphere.d.ts +13 -7
  158. package/types/camera/Camera.d.ts +90 -81
  159. package/types/camera/Frustum.d.ts +26 -22
  160. package/types/camera/PlanetCamera.d.ts +49 -53
  161. package/types/control/CompassButton.d.ts +4 -4
  162. package/types/control/Control.d.ts +7 -4
  163. package/types/control/DebugInfo.d.ts +3 -4
  164. package/types/control/EarthCoordinates.d.ts +6 -6
  165. package/types/control/EarthNavigation.d.ts +42 -0
  166. package/types/control/KeyboardNavigation.d.ts +3 -4
  167. package/types/control/LayerSwitcher.d.ts +3 -5
  168. package/types/control/Lighting.d.ts +3 -3
  169. package/types/control/MouseNavigation.d.ts +47 -0
  170. package/types/control/ScaleControl.d.ts +3 -3
  171. package/types/control/ShowFps.d.ts +3 -4
  172. package/types/control/SimpleNavigation.d.ts +3 -6
  173. package/types/control/Sun.d.ts +8 -10
  174. package/types/control/ToggleWireframe.d.ts +3 -3
  175. package/types/control/TouchNavigation.d.ts +48 -0
  176. package/types/control/ZoomControl.d.ts +3 -4
  177. package/types/control/index.d.ts +3 -1
  178. package/types/ellipsoid/Ellipsoid.d.ts +47 -43
  179. package/types/ellipsoid/wgs84.d.ts +3 -2
  180. package/types/entity/BaseBillboard.d.ts +41 -34
  181. package/types/entity/Billboard.d.ts +7 -7
  182. package/types/entity/BillboardHandler.d.ts +4 -0
  183. package/types/entity/Entity.d.ts +101 -83
  184. package/types/entity/EntityCollection.d.ts +57 -43
  185. package/types/entity/GeoObject.d.ts +111 -0
  186. package/types/entity/GeoObjectHandler.d.ts +77 -0
  187. package/types/entity/Geometry.d.ts +9 -7
  188. package/types/entity/GeometryHandler.d.ts +2 -2
  189. package/types/entity/Label.d.ts +24 -29
  190. package/types/entity/LabelHandler.d.ts +9 -2
  191. package/types/entity/LabelWorker.d.ts +9 -0
  192. package/types/entity/PointCloud.d.ts +8 -8
  193. package/types/entity/PointCloudHandler.d.ts +3 -3
  194. package/types/entity/Polyline.d.ts +58 -55
  195. package/types/entity/Ray.d.ts +19 -18
  196. package/types/entity/Strip.d.ts +8 -7
  197. package/types/entity/StripHandler.d.ts +3 -3
  198. package/types/entity/index.d.ts +7 -7
  199. package/types/input/KeyboardHandler.d.ts +10 -0
  200. package/types/input/MouseHandler.d.ts +5 -0
  201. package/types/input/TouchHandler.d.ts +5 -0
  202. package/types/layer/BaseGeoImage.d.ts +23 -35
  203. package/types/layer/CanvasTiles.d.ts +15 -22
  204. package/types/layer/GeoImage.d.ts +5 -18
  205. package/types/layer/GeoVideo.d.ts +5 -30
  206. package/types/layer/KML.d.ts +20 -15
  207. package/types/layer/Layer.d.ts +326 -0
  208. package/types/layer/Material.d.ts +45 -0
  209. package/types/layer/Vector.d.ts +208 -0
  210. package/types/layer/WMS.d.ts +4 -7
  211. package/types/layer/XYZ.d.ts +19 -25
  212. package/types/light/LightSource.d.ts +54 -53
  213. package/types/math/Line2.d.ts +11 -0
  214. package/types/math/Line3.d.ts +10 -0
  215. package/types/math/Mat3.d.ts +30 -18
  216. package/types/math/Mat4.d.ts +71 -52
  217. package/types/math/Plane.d.ts +5 -4
  218. package/types/math/Quat.d.ts +379 -0
  219. package/types/math/Ray.d.ts +82 -0
  220. package/types/math/Vec2.d.ts +102 -101
  221. package/types/math/Vec3.d.ts +143 -142
  222. package/types/math/Vec4.d.ts +40 -39
  223. package/types/math/coder.d.ts +12 -11
  224. package/types/math.d.ts +8 -8
  225. package/types/mercator.d.ts +3 -3
  226. package/types/proj/EPSG3857.d.ts +3 -2
  227. package/types/proj/EPSG4326.d.ts +3 -2
  228. package/types/proj/Proj.d.ts +42 -0
  229. package/types/quadTree/EntityCollectionNode.d.ts +34 -0
  230. package/types/quadTree/Node.d.ts +61 -0
  231. package/types/renderer/Renderer.d.ts +300 -0
  232. package/types/renderer/RendererEvents.d.ts +10 -7
  233. package/types/scene/BaseNode.d.ts +9 -9
  234. package/types/scene/Planet.d.ts +131 -126
  235. package/types/scene/RenderNode.d.ts +22 -23
  236. package/types/segment/Segment.d.ts +279 -0
  237. package/types/segment/SegmentLonLat.d.ts +16 -0
  238. package/types/shaders/geoObject.d.ts +3 -0
  239. package/types/shapes/BaseShape.d.ts +43 -40
  240. package/types/shapes/Sphere.d.ts +7 -7
  241. package/types/terrain/BilTerrain.d.ts +0 -1
  242. package/types/terrain/EmptyTerrain.d.ts +4 -4
  243. package/types/terrain/GlobusTerrain.d.ts +17 -54
  244. package/types/terrain/MapboxTerrain.d.ts +0 -1
  245. package/types/utils/GeoImageCreator.d.ts +3 -2
  246. package/types/utils/TextureAtlas.d.ts +8 -8
  247. package/types/utils/shared.d.ts +25 -24
  248. package/types/webgl/Framebuffer.d.ts +5 -5
  249. package/types/webgl/Handler.d.ts +68 -43
  250. package/types/webgl/Multisample.d.ts +5 -5
  251. package/types/webgl/Program.d.ts +8 -2
  252. package/types/webgl/ProgramController.d.ts +18 -13
  253. package/src/og/inherits.js +0 -8
  254. package/src/og/utils/polylabel.js +0 -176
  255. package/types/inherits.d.ts +0 -4
@@ -1,459 +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
- const Mat4 = function () {
13
- /**
14
- * A 4x4 matrix, indexable as a column-major order array.
15
- * @public
16
- * @type {Array.<number>}
17
- */
18
- this._m = new Array(16);
19
- };
20
-
21
- /**
22
- * Mat4 factory.
23
- * @static
24
- * @returns {og.Mat4} -
25
- */
26
- export function mat4() {
27
- return new og.Mat4();
28
- };
29
-
30
- /**
31
- * Returns identity matrix instance.
32
- * @static
33
- * @returns {og.Mat4} -
34
- */
35
- Mat4.identity = function () {
36
- var res = new Mat4();
37
- res._m[0] = 1; res._m[1] = 0; res._m[2] = 0; res._m[3] = 0;
38
- res._m[4] = 0; res._m[5] = 1; res._m[6] = 0; res._m[7] = 0;
39
- res._m[8] = 0; res._m[9] = 0; res._m[10] = 1; res._m[11] = 0;
40
- res._m[12] = 0; res._m[13] = 0; res._m[14] = 0; res._m[15] = 1;
41
- return res;
42
- };
43
-
44
- /**
45
- * Sets column-major order array matrix.
46
- * @public
47
- * @param {Array.<number>} m - Matrix array.
48
- * @returns {og.Mat4} -
49
- */
50
- Mat4.prototype.set = function (m) {
51
- this._m[0] = m[0];
52
- this._m[1] = m[1];
53
- this._m[2] = m[2];
54
- this._m[3] = m[3];
55
- this._m[4] = m[4];
56
- this._m[5] = m[5];
57
- this._m[6] = m[6];
58
- this._m[7] = m[7];
59
- this._m[8] = m[8];
60
- this._m[9] = m[9];
61
- this._m[10] = m[10];
62
- this._m[11] = m[11];
63
- this._m[12] = m[12];
64
- this._m[13] = m[13];
65
- this._m[14] = m[14];
66
- this._m[15] = m[15];
67
- return this;
68
- };
69
-
70
- /**
71
- * Duplicates a Matrix3 instance.
72
- * @public
73
- * @returns {og.Mat4} -
74
- */
75
- Mat4.prototype.clone = function () {
76
- var res = new Mat4();
77
- res.set(this);
78
- return res;
79
- };
80
-
81
- /**
82
- * Copy matrix.
83
- * @public
84
- * @param {og.Mat3} a - Matrix to copy.
85
- */
86
- Mat4.prototype.copy = function (a) {
87
- this.set(a._m);
88
- };
89
-
90
- /**
91
- * Converts to 3x3 matrix.
92
- * @public
93
- * @returns {og.Mat3} -
94
- */
95
- Mat4.prototype.toMatrix3 = function () {
96
- var res = new Mat3();
97
- var a = this._m,
98
- b = res._m;
99
- b[0] = a[0];
100
- b[1] = a[1];
101
- b[2] = a[2];
102
- b[3] = a[4];
103
- b[4] = a[5];
104
- b[5] = a[6];
105
- b[6] = a[8];
106
- b[7] = a[9];
107
- b[8] = a[10];
108
- return res;
109
- };
110
-
111
- /**
112
- * Multiply to 3d vector.
113
- * @public
114
- * @param {og.Vec3} p - 3d vector.
115
- * @returns {og.Vec3} -
116
- */
117
- Mat4.prototype.mulVec3 = function (p) {
118
- var d = p.x, e = p.y, g = p.z;
119
- return new Vec3(
120
- this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12],
121
- this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13],
122
- this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14]
123
- );
124
- };
125
-
126
- /**
127
- * Multiply to 4d vector.
128
- * @public
129
- * @param {og.Vec4} p - 4d vector.
130
- * @returns {og.Vec4} -
131
- */
132
- Mat4.prototype.mulVec4 = function (p) {
133
- var d = p.x, e = p.y, g = p.z, f = p.w;
134
- return new Vec4(
135
- this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12] * f,
136
- this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13] * f,
137
- this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14] * f,
138
- this._m[3] * d + this._m[7] * e + this._m[11] * g + this._m[15] * f
139
- );
140
- };
141
-
142
- /**
143
- * Creates an inversed 3x3 matrix of the current.
144
- * @public
145
- * @returns {og.Mat3} -
146
- */
147
- Mat4.prototype.toInverseMatrix3 = function () {
148
- var a = this._m;
149
- var c = a[0], d = a[1], e = a[2],
150
- g = a[4], f = a[5], h = a[6],
151
- i = a[8], j = a[9], k = a[10],
152
- l = k * f - h * j,
153
- o = -k * g + h * i,
154
- m = j * g - f * i,
155
- n = c * l + d * o + e * m;
156
-
157
- if (!n) {
158
- return null;
159
- }
160
-
161
- n = 1 / n;
162
-
163
- var res = new Mat3();
164
- res._m[0] = l * n;
165
- res._m[1] = (-k * d + e * j) * n;
166
- res._m[2] = (h * d - e * f) * n;
167
- res._m[3] = o * n;
168
- res._m[4] = (k * c - e * i) * n;
169
- res._m[5] = (-h * c + e * g) * n;
170
- res._m[6] = m * n;
171
- res._m[7] = (-j * c + d * i) * n;
172
- res._m[8] = (f * c - d * g) * n;
173
- return res;
174
- };
175
-
176
- /**
177
- * Creates an inversed matrix of the current.
178
- * @public
179
- * @returns {og.Mat4} -
180
- */
181
- Mat4.prototype.inverseTo = function (res) {
182
- var c = this._m[0], d = this._m[1], e = this._m[2], g = this._m[3],
183
- f = this._m[4], h = this._m[5], i = this._m[6], j = this._m[7],
184
- k = this._m[8], l = this._m[9], o = this._m[10], m = this._m[11],
185
- n = this._m[12], p = this._m[13], r = this._m[14], s = this._m[15],
186
- A = c * h - d * f,
187
- B = c * i - e * f,
188
- t = c * j - g * f,
189
- u = d * i - e * h,
190
- v = d * j - g * h,
191
- w = e * j - g * i,
192
- x = k * p - l * n,
193
- y = k * r - o * n,
194
- z = k * s - m * n,
195
- C = l * r - o * p,
196
- D = l * s - m * p,
197
- E = o * s - m * r,
198
- q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x),
199
- res = res || new Mat4();
200
-
201
- res._m[0] = (h * E - i * D + j * C) * q; res._m[1] = (-d * E + e * D - g * C) * q; res._m[2] = (p * w - r * v + s * u) * q; res._m[3] = (-l * w + o * v - m * u) * q;
202
- res._m[4] = (-f * E + i * z - j * y) * q; res._m[5] = (c * E - e * z + g * y) * q; res._m[6] = (-n * w + r * t - s * B) * q; res._m[7] = (k * w - o * t + m * B) * q;
203
- res._m[8] = (f * D - h * z + j * x) * q; res._m[9] = (-c * D + d * z - g * x) * q; res._m[10] = (n * v - p * t + s * A) * q; res._m[11] = (-k * v + l * t - m * A) * q;
204
- res._m[12] = (-f * C + h * y - i * x) * q; res._m[13] = (c * C - d * y + e * x) * q; res._m[14] = (-n * u + p * B - r * A) * q; res._m[15] = (k * u - l * B + o * A) * q;
205
- return res;
206
- };
207
-
208
- /**
209
- * Creates a trasposed matrix of the current.
210
- * @public
211
- * @returns {og.Mat4} -
212
- */
213
- Mat4.prototype.transposeTo = function () {
214
- var res = new Mat4();
215
- res._m[0] = this._m[0]; res._m[1] = this._m[4]; res._m[2] = this._m[8]; res._m[3] = this._m[12];
216
- res._m[4] = this._m[1]; res._m[5] = this._m[5]; res._m[6] = this._m[9]; res._m[7] = this._m[13];
217
- res._m[8] = this._m[2]; res._m[9] = this._m[6]; res._m[10] = this._m[10]; res._m[11] = this._m[14];
218
- res._m[12] = this._m[3]; res._m[13] = this._m[7]; res._m[14] = this._m[11]; res._m[15] = this._m[15];
219
- return res;
220
- };
221
-
222
- /**
223
- * Sets matrix to identity.
224
- * @public
225
- * @returns {og.Mat4} -
226
- */
227
- Mat4.prototype.setIdentity = function () {
228
- this._m[0] = 1; this._m[1] = 0; this._m[2] = 0; this._m[3] = 0;
229
- this._m[4] = 0; this._m[5] = 1; this._m[6] = 0; this._m[7] = 0;
230
- this._m[8] = 0; this._m[9] = 0; this._m[10] = 1; this._m[11] = 0;
231
- this._m[12] = 0; this._m[13] = 0; this._m[14] = 0; this._m[15] = 1;
232
- return this;
233
- };
234
-
235
- /**
236
- * Computes the product of two matrices.
237
- * @public
238
- * @param {og.Mat4} mx - Matrix to multiply.
239
- * @returns {og.Mat4} -
240
- */
241
- Mat4.prototype.mul = function (mx) {
242
- let d = this._m[0], e = this._m[1], g = this._m[2], f = this._m[3],
243
- h = this._m[4], i = this._m[5], j = this._m[6], k = this._m[7],
244
- l = this._m[8], o = this._m[9], m = this._m[10], n = this._m[11],
245
- p = this._m[12], r = this._m[13], s = this._m[14], a = this._m[15];
246
-
247
- let A = mx._m[0], B = mx._m[1], t = mx._m[2], u = mx._m[3],
248
- v = mx._m[4], w = mx._m[5], x = mx._m[6], y = mx._m[7],
249
- z = mx._m[8], C = mx._m[9], D = mx._m[10], E = mx._m[11],
250
- q = mx._m[12], F = mx._m[13], G = mx._m[14], b = mx._m[15];
251
-
252
- var res = new Mat4();
253
- res._m[0] = A * d + B * h + t * l + u * p; res._m[1] = A * e + B * i + t * o + u * r; res._m[2] = A * g + B * j + t * m + u * s; res._m[3] = A * f + B * k + t * n + u * a;
254
- res._m[4] = v * d + w * h + x * l + y * p; res._m[5] = v * e + w * i + x * o + y * r; res._m[6] = v * g + w * j + x * m + y * s; res._m[7] = v * f + w * k + x * n + y * a;
255
- res._m[8] = z * d + C * h + D * l + E * p; res._m[9] = z * e + C * i + D * o + E * r; res._m[10] = z * g + C * j + D * m + E * s; res._m[11] = z * f + C * k + D * n + E * a;
256
- res._m[12] = q * d + F * h + G * l + b * p; res._m[13] = q * e + F * i + G * o + b * r; res._m[14] = q * g + F * j + G * m + b * s; res._m[15] = q * f + F * k + G * n + b * a;
257
- return res;
258
- };
259
-
260
- /**
261
- * Add translation vector to the current matrix.
262
- * @public
263
- * @param {og.Vec3} v - Translate vector.
264
- * @returns {og.Mat4} -
265
- */
266
- Mat4.prototype.translate = function (v) {
267
- var d = v.x, e = v.y, b = v.z;
268
- var a = this._m;
269
- a[12] = a[0] * d + a[4] * e + a[8] * b + a[12];
270
- a[13] = a[1] * d + a[5] * e + a[9] * b + a[13];
271
- a[14] = a[2] * d + a[6] * e + a[10] * b + a[14];
272
- a[15] = a[3] * d + a[7] * e + a[11] * b + a[15];
273
- return this;
274
- };
275
-
276
- /**
277
- * Sets translation matrix to the position.
278
- * @public
279
- * @param {og.Vec3} v - Translate to position.
280
- * @returns {og.Mat4} -
281
- */
282
- Mat4.prototype.translateToPosition = function (v) {
283
- var a = this._m;
284
- a[12] = v.x;
285
- a[13] = v.y;
286
- a[14] = v.z;
287
- return this;
288
- };
289
-
290
- /**
291
- * Rotate currrent matrix around the aligned axis and angle.
292
- * @public
293
- * @param {og.Vec3} u - Aligned axis.
294
- * @param {number} angle - Aligned axis angle in radians.
295
- * @returns {og.Mat4} -
296
- * @todo: OPTIMIZE: reveal multiplication
297
- */
298
- Mat4.prototype.rotate = function (u, angle) {
299
- var c = Math.cos(angle),
300
- s = Math.sin(angle);
301
- var rot = new Mat4();
302
- var mx = rot._m;
303
- mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
304
- mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
305
- mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
306
- mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
307
- return this.mul(rot);
308
- };
309
-
310
- /**
311
- * Sets current rotation matrix around the aligned axis and angle.
312
- * @public
313
- * @param {og.Vec3} u - Aligned axis.
314
- * @param {number} angle - Aligned axis angle in radians.
315
- * @returns {og.Mat4} -
316
- */
317
- Mat4.prototype.setRotation = function (u, angle) {
318
- var c = Math.cos(angle),
319
- s = Math.sin(angle);
320
- var mx = this._m;
321
- mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
322
- mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
323
- mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
324
- mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
325
- return this;
326
- };
327
-
328
- /**
329
- * Gets the rotation matrix from one vector to another.
330
- * @public
331
- * @param {og.Vec3} a - Firtst vector.
332
- * @param {og.Vec3} b - Second vector.
333
- * @returns {og.Mat4} -
334
- */
335
- Mat4.prototype.rotateBetweenVectors = function (a, b) {
336
- var q = Quat.getRotationBetweenVectors(a, b);
337
- return q.getMat4();
338
- };
339
-
340
- /**
341
- * Scale current matrix to the vector values.
342
- * @public
343
- * @param {og.Vec3} v - Scale vector.
344
- * @returns {og.Mat4} -
345
- */
346
- Mat4.prototype.scale = function (v) {
347
- var mx = this._m;
348
- mx[0] = mx[0] * v.x; mx[1] = mx[1] * v.x; mx[2] = mx[2] * v.x; mx[3] = mx[3] * v.x;
349
- mx[4] = mx[4] * v.y; mx[5] = mx[5] * v.y; mx[6] = mx[6] * v.y; mx[7] = mx[7] * v.y;
350
- mx[8] = mx[8] * v.z; mx[9] = mx[9] * v.z; mx[10] = mx[10] * v.z; mx[11] = mx[11] * v.z;
351
- return this;
352
- };
353
-
354
- /**
355
- * Sets perspective projection matrix frustum values.
356
- * @public
357
- * @param {number} left -
358
- * @param {number} right -
359
- * @param {number} bottom -
360
- * @param {number} top -
361
- * @param {number} near -
362
- * @param {number} far -
363
- * @returns {og.Mat4} -
364
- */
365
- Mat4.prototype.setPerspective = function (left, right, bottom, top, near, far) {
366
- var h = right - left, i = top - bottom, j = far - near;
367
- this._m[0] = near * 2 / h;
368
- this._m[1] = 0;
369
- this._m[2] = 0;
370
- this._m[3] = 0;
371
- this._m[4] = 0;
372
- this._m[5] = near * 2 / i;
373
- this._m[6] = 0;
374
- this._m[7] = 0;
375
- this._m[8] = (right + left) / h;
376
- this._m[9] = (top + bottom) / i;
377
- this._m[10] = -(far + near) / j;
378
- this._m[11] = -1;
379
- this._m[12] = 0;
380
- this._m[13] = 0;
381
- this._m[14] = -(far * near * 2) / j;
382
- this._m[15] = 0;
383
- return this;
384
- };
385
-
386
- /**
387
- * Creates current orthographic projection matrix.
388
- * @public
389
- * @param {number} left -
390
- * @param {number} right -
391
- * @param {number} bottom -
392
- * @param {number} top -
393
- * @param {number} near -
394
- * @param {number} far -
395
- * @return {og.Mat4} -
396
- */
397
- Mat4.prototype.setOrtho = function (left, right, bottom, top, near, far) {
398
-
399
- var lr = 1.0 / (left - right),
400
- bt = 1.0 / (bottom - top),
401
- nf = 1.0 / (near - far),
402
- m = this._m;
403
-
404
- m[0] = -2.0 * lr;
405
- m[1] = 0;
406
- m[2] = 0;
407
- m[3] = 0;
408
- m[4] = 0;
409
- m[5] = -2.0 * bt;
410
- m[6] = 0;
411
- m[7] = 0;
412
- m[8] = 0;
413
- m[9] = 0;
414
- m[10] = 2.0 * nf;
415
- m[11] = 0;
416
- m[12] = (left + right) * lr;
417
- m[13] = (top + bottom) * bt;
418
- m[14] = (far + near) * nf;
419
- m[15] = 1.0;
420
- return this;
421
- };
422
-
423
- /**
424
- * Sets current rotation matrix by euler's angles.
425
- * @public
426
- * @param {number} ax - Rotation angle in radians arond X axis.
427
- * @param {number} ay - Rotation angle in radians arond Y axis.
428
- * @param {number} az - Rotation angle in radians arond Z axis.
429
- * @returns {og.Mat4} -
430
- */
431
- Mat4.prototype.eulerToMatrix = function (ax, ay, az) {
432
- var a = Math.cos(ax),
433
- b = Math.sin(ax),
434
- c = Math.cos(ay),
435
- d = Math.sin(ay),
436
- e = Math.cos(az),
437
- f = Math.sin(az);
438
-
439
- var ad = a * d,
440
- bd = b * d;
441
-
442
- var mat = this._m;
443
-
444
- mat[0] = c * e;
445
- mat[1] = -c * f;
446
- mat[2] = -d;
447
- mat[4] = -bd * e + a * f;
448
- mat[5] = bd * f + a * e;
449
- mat[6] = -b * c;
450
- mat[8] = ad * e + b * f;
451
- mat[9] = -ad * f + b * e;
452
- mat[10] = a * c;
453
- mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
454
- mat[15] = 1;
455
-
456
- return this;
457
- };
458
-
459
- export { Mat4 };
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
+ }