@openglobus/og 0.11.2 → 0.11.7

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