@openglobus/og 0.11.5 → 0.12.0

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 (267) hide show
  1. package/css/og.css +5 -2
  2. package/package.json +12 -14
  3. package/src/og/Clock.js +6 -10
  4. package/src/og/Events.js +5 -7
  5. package/src/og/Extent.js +73 -32
  6. package/src/og/Globe.js +25 -10
  7. package/src/og/ImageCanvas.js +18 -15
  8. package/src/og/LonLat.js +13 -10
  9. package/src/og/Popup.js +19 -17
  10. package/src/og/QueueArray.js +3 -4
  11. package/src/og/Rectangle.js +4 -6
  12. package/src/og/Stack.js +2 -4
  13. package/src/og/ajax.js +20 -14
  14. package/src/og/astro/earth.js +21 -15
  15. package/src/og/bv/Box.js +2 -3
  16. package/src/og/bv/Sphere.js +10 -7
  17. package/src/og/camera/Camera.js +70 -79
  18. package/src/og/camera/Frustum.js +19 -12
  19. package/src/og/camera/PlanetCamera.js +33 -34
  20. package/src/og/control/CompassButton.js +1 -2
  21. package/src/og/control/Control.js +7 -9
  22. package/src/og/control/DebugInfo.js +2 -3
  23. package/src/og/control/EarthNavigation.js +26 -17
  24. package/src/og/control/KeyboardNavigation.js +9 -9
  25. package/src/og/control/LayerSwitcher.js +21 -20
  26. package/src/og/control/Lighting.js +74 -64
  27. package/src/og/control/MouseNavigation.js +30 -29
  28. package/src/og/control/MouseWheelZoomControl.js +257 -0
  29. package/src/og/control/SegmentBoundVisualization.js +5 -6
  30. package/src/og/control/ShowFps.js +12 -7
  31. package/src/og/control/SimpleNavigation.js +5 -7
  32. package/src/og/control/Sun.js +24 -14
  33. package/src/og/control/ToggleWireframe.js +3 -3
  34. package/src/og/control/TouchNavigation.js +43 -32
  35. package/src/og/control/ZoomControl.js +40 -24
  36. package/src/og/control/index.js +2 -0
  37. package/src/og/control/visibleExtent/Segment.js +1862 -0
  38. package/src/og/control/visibleExtent/VisibleExtent.js +80 -0
  39. package/src/og/control/visibleExtent/drawnode.js +751 -0
  40. package/src/og/ellipsoid/Ellipsoid.js +149 -57
  41. package/src/og/ellipsoid/wgs84.js +3 -3
  42. package/src/og/entity/BaseBillboard.js +72 -30
  43. package/src/og/entity/Billboard.js +9 -5
  44. package/src/og/entity/BillboardHandler.js +315 -62
  45. package/src/og/entity/Entity.js +742 -704
  46. package/src/og/entity/EntityCollection.js +47 -24
  47. package/src/og/entity/GeoObject.js +228 -0
  48. package/src/og/entity/GeoObjectHandler.js +895 -0
  49. package/src/og/entity/GeometryHandler.js +595 -123
  50. package/src/og/entity/Label.js +62 -30
  51. package/src/og/entity/LabelHandler.js +42 -243
  52. package/src/og/entity/LabelWorker.js +218 -0
  53. package/src/og/entity/Object3d.js +504 -0
  54. package/src/og/entity/PointCloud.js +76 -28
  55. package/src/og/entity/PointCloudHandler.js +5 -5
  56. package/src/og/entity/Ray.js +49 -16
  57. package/src/og/entity/Strip.js +72 -43
  58. package/src/og/entity/StripHandler.js +23 -23
  59. package/src/og/layer/BaseGeoImage.js +50 -19
  60. package/src/og/layer/CanvasTiles.js +16 -17
  61. package/src/og/layer/GeoImage.js +8 -16
  62. package/src/og/layer/GeoTexture2d.js +2 -10
  63. package/src/og/layer/GeoVideo.js +2 -10
  64. package/src/og/layer/KML.js +55 -33
  65. package/src/og/layer/Layer.js +24 -33
  66. package/src/og/layer/Material.js +1 -1
  67. package/src/og/layer/Vector.js +94 -48
  68. package/src/og/layer/WMS.js +33 -18
  69. package/src/og/layer/XYZ.js +24 -26
  70. package/src/og/light/LightSource.js +19 -12
  71. package/src/og/math/Mat3.js +24 -12
  72. package/src/og/math/Mat4.js +603 -603
  73. package/src/og/math/Plane.js +19 -18
  74. package/src/og/math/Ray.js +17 -12
  75. package/src/og/math/Vec2.js +24 -14
  76. package/src/og/math/Vec3.js +78 -32
  77. package/src/og/math/coder.js +7 -7
  78. package/src/og/proj/EPSG3857.js +3 -3
  79. package/src/og/proj/EPSG4326.js +3 -3
  80. package/src/og/proj/Proj.js +2 -4
  81. package/src/og/quadTree/Node.js +50 -95
  82. package/src/og/quadTree/quadTree.js +1 -1
  83. package/src/og/renderer/Renderer.js +106 -126
  84. package/src/og/renderer/RendererEvents.js +45 -23
  85. package/src/og/scene/BaseNode.js +2 -3
  86. package/src/og/scene/Planet.js +139 -191
  87. package/src/og/scene/RenderNode.js +15 -8
  88. package/src/og/segment/Segment.js +93 -268
  89. package/src/og/segment/Slice.js +45 -0
  90. package/src/og/shaders/drawnode.js +174 -360
  91. package/src/og/shaders/geoObject.js +211 -0
  92. package/src/og/shaders/pointCloud.js +41 -41
  93. package/src/og/shaders/shape.js +12 -18
  94. package/src/og/shaders/skybox.js +36 -36
  95. package/src/og/shaders/toneMapping.js +1 -0
  96. package/src/og/shapes/BaseShape.js +108 -36
  97. package/src/og/shapes/Icosphere.js +25 -10
  98. package/src/og/shapes/Sphere.js +8 -11
  99. package/src/og/terrain/EmptyTerrain.js +3 -2
  100. package/src/og/terrain/GlobusTerrain.js +2 -0
  101. package/src/og/utils/FontAtlas.js +6 -2
  102. package/src/og/utils/GeoImageCreator.js +5 -1
  103. package/src/og/utils/Loader.js +1 -1
  104. package/src/og/utils/PlainSegmentWorker.js +0 -13
  105. package/src/og/utils/TextureAtlas.js +18 -20
  106. package/src/og/utils/VectorTileCreator.js +1 -3
  107. package/src/og/utils/shared.js +2 -2
  108. package/src/og/webgl/Handler.js +219 -162
  109. package/src/og/webgl/Multisample.js +44 -16
  110. package/src/og/webgl/Program.js +78 -33
  111. package/src/og/webgl/callbacks.js +3 -3
  112. package/types/Clock.d.ts +0 -94
  113. package/types/Deferred.d.ts +0 -6
  114. package/types/Events.d.ts +0 -77
  115. package/types/Extent.d.ts +0 -166
  116. package/types/Globe.d.ts +0 -82
  117. package/types/ImageCanvas.d.ts +0 -123
  118. package/types/Lock.d.ts +0 -12
  119. package/types/LonLat.d.ts +0 -108
  120. package/types/Popup.d.ts +0 -42
  121. package/types/QueueArray.d.ts +0 -19
  122. package/types/Rectangle.d.ts +0 -80
  123. package/types/Stack.d.ts +0 -19
  124. package/types/ajax.d.ts +0 -24
  125. package/types/arial.d.ts +0 -48
  126. package/types/astro/astro.d.ts +0 -38
  127. package/types/astro/earth.d.ts +0 -7
  128. package/types/astro/jd.d.ts +0 -254
  129. package/types/bv/Box.d.ts +0 -30
  130. package/types/bv/Sphere.d.ts +0 -38
  131. package/types/bv/index.d.ts +0 -3
  132. package/types/camera/Camera.d.ts +0 -312
  133. package/types/camera/Frustum.d.ts +0 -133
  134. package/types/camera/PlanetCamera.d.ts +0 -218
  135. package/types/camera/index.d.ts +0 -3
  136. package/types/cons.d.ts +0 -40
  137. package/types/control/CompassButton.d.ts +0 -17
  138. package/types/control/Control.d.ts +0 -104
  139. package/types/control/DebugInfo.d.ts +0 -15
  140. package/types/control/EarthCoordinates.d.ts +0 -47
  141. package/types/control/EarthNavigation.d.ts +0 -42
  142. package/types/control/GeoImageDragControl.d.ts +0 -6
  143. package/types/control/KeyboardNavigation.d.ts +0 -21
  144. package/types/control/LayerSwitcher.d.ts +0 -21
  145. package/types/control/Lighting.d.ts +0 -16
  146. package/types/control/MouseNavigation.d.ts +0 -47
  147. package/types/control/ScaleControl.d.ts +0 -22
  148. package/types/control/ShowFps.d.ts +0 -11
  149. package/types/control/SimpleNavigation.d.ts +0 -25
  150. package/types/control/Sun.d.ts +0 -50
  151. package/types/control/ToggleWireframe.d.ts +0 -12
  152. package/types/control/TouchNavigation.d.ts +0 -48
  153. package/types/control/ZoomControl.d.ts +0 -27
  154. package/types/control/index.d.ts +0 -17
  155. package/types/ellipsoid/Ellipsoid.d.ts +0 -146
  156. package/types/ellipsoid/index.d.ts +0 -3
  157. package/types/ellipsoid/wgs84.d.ts +0 -6
  158. package/types/entity/BaseBillboard.d.ts +0 -208
  159. package/types/entity/Billboard.d.ts +0 -94
  160. package/types/entity/BillboardHandler.d.ts +0 -78
  161. package/types/entity/Entity.d.ts +0 -333
  162. package/types/entity/EntityCollection.d.ts +0 -311
  163. package/types/entity/Geometry.d.ts +0 -74
  164. package/types/entity/GeometryHandler.d.ts +0 -76
  165. package/types/entity/Label.d.ts +0 -189
  166. package/types/entity/LabelHandler.d.ts +0 -29
  167. package/types/entity/PointCloud.d.ts +0 -174
  168. package/types/entity/PointCloudHandler.d.ts +0 -38
  169. package/types/entity/Polyline.d.ts +0 -306
  170. package/types/entity/PolylineHandler.d.ts +0 -18
  171. package/types/entity/Ray.d.ts +0 -124
  172. package/types/entity/RayHandler.d.ts +0 -67
  173. package/types/entity/ShapeHandler.d.ts +0 -22
  174. package/types/entity/Strip.d.ts +0 -119
  175. package/types/entity/StripHandler.d.ts +0 -38
  176. package/types/entity/index.d.ts +0 -8
  177. package/types/index.core.d.ts +0 -65
  178. package/types/index.d.ts +0 -45
  179. package/types/index.webgl.d.ts +0 -7
  180. package/types/input/KeyboardHandler.d.ts +0 -10
  181. package/types/input/MouseHandler.d.ts +0 -5
  182. package/types/input/TouchHandler.d.ts +0 -5
  183. package/types/input/input.d.ts +0 -34
  184. package/types/layer/BaseGeoImage.d.ts +0 -94
  185. package/types/layer/CanvasTiles.d.ts +0 -68
  186. package/types/layer/GeoImage.d.ts +0 -52
  187. package/types/layer/GeoTexture2d.d.ts +0 -8
  188. package/types/layer/GeoVideo.d.ts +0 -55
  189. package/types/layer/KML.d.ts +0 -63
  190. package/types/layer/Layer.d.ts +0 -326
  191. package/types/layer/Material.d.ts +0 -45
  192. package/types/layer/Vector.d.ts +0 -208
  193. package/types/layer/WMS.d.ts +0 -63
  194. package/types/layer/XYZ.d.ts +0 -120
  195. package/types/layer/index.d.ts +0 -10
  196. package/types/light/LightSource.d.ts +0 -178
  197. package/types/math/Line2.d.ts +0 -11
  198. package/types/math/Line3.d.ts +0 -10
  199. package/types/math/Mat3.d.ts +0 -65
  200. package/types/math/Mat4.d.ts +0 -176
  201. package/types/math/Plane.d.ts +0 -18
  202. package/types/math/Quat.d.ts +0 -379
  203. package/types/math/Ray.d.ts +0 -82
  204. package/types/math/Vec2.d.ts +0 -309
  205. package/types/math/Vec3.d.ts +0 -460
  206. package/types/math/Vec4.d.ts +0 -162
  207. package/types/math/coder.d.ts +0 -43
  208. package/types/math/index.d.ts +0 -11
  209. package/types/math.d.ts +0 -261
  210. package/types/mercator.d.ts +0 -92
  211. package/types/proj/EPSG3857.d.ts +0 -6
  212. package/types/proj/EPSG4326.d.ts +0 -6
  213. package/types/proj/Proj.d.ts +0 -42
  214. package/types/quadTree/EntityCollectionNode.d.ts +0 -34
  215. package/types/quadTree/Node.d.ts +0 -61
  216. package/types/quadTree/quadTree.d.ts +0 -40
  217. package/types/renderer/Renderer.d.ts +0 -298
  218. package/types/renderer/RendererEvents.d.ts +0 -233
  219. package/types/res/images.d.ts +0 -3
  220. package/types/scene/Axes.d.ts +0 -11
  221. package/types/scene/BaseNode.d.ts +0 -60
  222. package/types/scene/Planet.d.ts +0 -577
  223. package/types/scene/RenderNode.d.ts +0 -142
  224. package/types/scene/SkyBox.d.ts +0 -10
  225. package/types/scene/index.d.ts +0 -4
  226. package/types/segment/Segment.d.ts +0 -279
  227. package/types/segment/SegmentLonLat.d.ts +0 -16
  228. package/types/segment/segmentHelper.d.ts +0 -13
  229. package/types/shaders/billboard.d.ts +0 -3
  230. package/types/shaders/depth.d.ts +0 -2
  231. package/types/shaders/drawnode.d.ts +0 -7
  232. package/types/shaders/label.d.ts +0 -4
  233. package/types/shaders/pointCloud.d.ts +0 -2
  234. package/types/shaders/polyline.d.ts +0 -3
  235. package/types/shaders/ray.d.ts +0 -2
  236. package/types/shaders/screenFrame.d.ts +0 -2
  237. package/types/shaders/shape.d.ts +0 -4
  238. package/types/shaders/skybox.d.ts +0 -2
  239. package/types/shaders/toneMapping.d.ts +0 -2
  240. package/types/shapes/BaseShape.d.ts +0 -250
  241. package/types/shapes/Sphere.d.ts +0 -41
  242. package/types/terrain/BilTerrain.d.ts +0 -7
  243. package/types/terrain/EmptyTerrain.d.ts +0 -72
  244. package/types/terrain/Geoid.d.ts +0 -26
  245. package/types/terrain/GlobusTerrain.d.ts +0 -116
  246. package/types/terrain/MapboxTerrain.d.ts +0 -7
  247. package/types/terrain/index.d.ts +0 -5
  248. package/types/utils/FontAtlas.d.ts +0 -14
  249. package/types/utils/GeoImageCreator.d.ts +0 -30
  250. package/types/utils/ImagesCacheManager.d.ts +0 -10
  251. package/types/utils/Loader.d.ts +0 -25
  252. package/types/utils/NormalMapCreator.d.ts +0 -39
  253. package/types/utils/PlainSegmentWorker.d.ts +0 -10
  254. package/types/utils/TerrainWorker.d.ts +0 -9
  255. package/types/utils/TextureAtlas.d.ts +0 -111
  256. package/types/utils/VectorTileCreator.d.ts +0 -16
  257. package/types/utils/colorTable.d.ts +0 -143
  258. package/types/utils/earcut.d.ts +0 -6
  259. package/types/utils/shared.d.ts +0 -231
  260. package/types/webgl/Framebuffer.d.ts +0 -135
  261. package/types/webgl/Handler.d.ts +0 -388
  262. package/types/webgl/Multisample.d.ts +0 -89
  263. package/types/webgl/Program.d.ts +0 -155
  264. package/types/webgl/ProgramController.d.ts +0 -89
  265. package/types/webgl/callbacks.d.ts +0 -1
  266. package/types/webgl/index.d.ts +0 -6
  267. package/types/webgl/types.d.ts +0 -2
@@ -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
+ }