@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.
- package/package.json +18 -20
- package/src/og/Clock.js +11 -11
- package/src/og/Deferred.js +1 -1
- package/src/og/Events.js +9 -7
- package/src/og/Extent.js +117 -72
- package/src/og/Globe.js +35 -22
- package/src/og/ImageCanvas.js +24 -18
- package/src/og/Lock.js +2 -2
- package/src/og/LonLat.js +40 -37
- package/src/og/Popup.js +21 -15
- package/src/og/QueueArray.js +7 -3
- package/src/og/Rectangle.js +11 -6
- package/src/og/Stack.js +8 -5
- package/src/og/ajax.js +21 -33
- package/src/og/astro/astro.js +5 -5
- package/src/og/astro/earth.js +23 -17
- package/src/og/astro/jd.js +44 -39
- package/src/og/astro/orbit.js +20 -18
- package/src/og/astro/rotation.js +17 -8
- package/src/og/bv/Box.js +7 -3
- package/src/og/bv/Sphere.js +17 -9
- package/src/og/camera/Camera.js +137 -86
- package/src/og/camera/Frustum.js +30 -19
- package/src/og/camera/PlanetCamera.js +30 -26
- package/src/og/control/CompassButton.js +8 -2
- package/src/og/control/Control.js +13 -11
- package/src/og/control/DebugInfo.js +4 -1
- package/src/og/control/EarthCoordinates.js +62 -41
- package/src/og/control/EarthNavigation.js +20 -22
- package/src/og/control/GeoImageDragControl.js +1 -1
- package/src/og/control/KeyboardNavigation.js +12 -12
- package/src/og/control/LayerSwitcher.js +24 -23
- package/src/og/control/Lighting.js +1 -1
- package/src/og/control/MouseNavigation.js +1 -1
- package/src/og/control/ScaleControl.js +1 -1
- package/src/og/control/SegmentBoundVisualization.js +8 -9
- package/src/og/control/ShowFps.js +15 -10
- package/src/og/control/SimpleNavigation.js +8 -10
- package/src/og/control/Sun.js +25 -15
- package/src/og/control/ToggleWireframe.js +5 -5
- package/src/og/control/TouchNavigation.js +58 -45
- package/src/og/control/ZoomControl.js +41 -25
- package/src/og/control/index.js +4 -0
- package/src/og/ellipsoid/Ellipsoid.js +181 -85
- package/src/og/ellipsoid/wgs84.js +4 -4
- package/src/og/entity/BaseBillboard.js +97 -44
- package/src/og/entity/Billboard.js +15 -11
- package/src/og/entity/BillboardHandler.js +314 -64
- package/src/og/entity/Entity.js +106 -74
- package/src/og/entity/EntityCollection.js +72 -49
- package/src/og/entity/GeoObject.js +228 -0
- package/src/og/entity/GeoObjectHandler.js +910 -0
- package/src/og/entity/Geometry.js +29 -26
- package/src/og/entity/GeometryHandler.js +598 -126
- package/src/og/entity/Label.js +74 -40
- package/src/og/entity/LabelHandler.js +47 -246
- package/src/og/entity/LabelWorker.js +213 -0
- package/src/og/entity/Object3d.js +504 -0
- package/src/og/entity/PointCloud.js +81 -33
- package/src/og/entity/PointCloudHandler.js +9 -9
- package/src/og/entity/Polyline.js +39 -39
- package/src/og/entity/Ray.js +61 -28
- package/src/og/entity/ShapeHandler.js +1 -1
- package/src/og/entity/Strip.js +77 -48
- package/src/og/entity/StripHandler.js +27 -27
- package/src/og/entity/index.js +8 -16
- package/src/og/input/KeyboardHandler.js +107 -104
- package/src/og/input/MouseHandler.js +81 -78
- package/src/og/input/TouchHandler.js +55 -51
- package/src/og/layer/BaseGeoImage.js +61 -30
- package/src/og/layer/CanvasTiles.js +26 -24
- package/src/og/layer/GeoImage.js +10 -10
- package/src/og/layer/GeoTexture2d.js +1 -1
- package/src/og/layer/GeoVideo.js +3 -3
- package/src/og/layer/KML.js +66 -40
- package/src/og/layer/Layer.js +27 -17
- package/src/og/layer/Material.js +93 -61
- package/src/og/layer/Vector.js +118 -72
- package/src/og/layer/WMS.js +36 -19
- package/src/og/layer/XYZ.js +55 -48
- package/src/og/light/LightSource.js +47 -40
- package/src/og/math/Line2.js +24 -24
- package/src/og/math/Line3.js +103 -102
- package/src/og/math/Mat3.js +134 -121
- package/src/og/math/Mat4.js +603 -459
- package/src/og/math/Plane.js +21 -20
- package/src/og/math/Quat.js +980 -927
- package/src/og/math/Ray.js +195 -187
- package/src/og/math/Vec2.js +127 -117
- package/src/og/math/Vec3.js +206 -176
- package/src/og/math/Vec4.js +49 -53
- package/src/og/math/coder.js +18 -18
- package/src/og/math.js +12 -12
- package/src/og/mercator.js +11 -11
- package/src/og/proj/EPSG3857.js +4 -4
- package/src/og/proj/EPSG4326.js +4 -4
- package/src/og/proj/Proj.js +31 -31
- package/src/og/quadTree/EntityCollectionNode.js +310 -300
- package/src/og/quadTree/Node.js +1008 -993
- package/src/og/renderer/Renderer.js +768 -747
- package/src/og/renderer/RendererEvents.js +9 -6
- package/src/og/scene/Axes.js +1 -1
- package/src/og/scene/BaseNode.js +8 -9
- package/src/og/scene/Planet.js +115 -87
- package/src/og/scene/RenderNode.js +29 -22
- package/src/og/scene/SkyBox.js +1 -1
- package/src/og/segment/Segment.js +1886 -1878
- package/src/og/segment/SegmentLonLat.js +298 -268
- package/src/og/segment/segmentHelper.js +11 -11
- package/src/og/shaders/bloom.js +1 -1
- package/src/og/shaders/blur.js +2 -2
- package/src/og/shaders/depth.js +1 -1
- package/src/og/shaders/geoObject.js +211 -0
- package/src/og/shaders/label.js +1 -1
- package/src/og/shaders/lumFilter.js +1 -1
- package/src/og/shaders/pointCloud.js +42 -42
- package/src/og/shaders/screenFrame.js +1 -1
- package/src/og/shaders/shape.js +15 -21
- package/src/og/shaders/skybox.js +37 -37
- package/src/og/shaders/toneMapping.js +1 -1
- package/src/og/shapes/BaseShape.js +129 -57
- package/src/og/shapes/Icosphere.js +30 -15
- package/src/og/shapes/Sphere.js +13 -16
- package/src/og/terrain/BilTerrain.js +2 -1
- package/src/og/terrain/EmptyTerrain.js +2 -2
- package/src/og/terrain/Geoid.js +2 -2
- package/src/og/terrain/GlobusTerrain.js +10 -10
- package/src/og/terrain/MapboxTerrain.js +1 -1
- package/src/og/utils/GeoImageCreator.js +9 -9
- package/src/og/utils/Loader.js +6 -6
- package/src/og/utils/NormalMapCreator.js +13 -13
- package/src/og/utils/TerrainWorker.js +1 -1
- package/src/og/utils/TextureAtlas.js +20 -22
- package/src/og/utils/VectorTileCreator.js +5 -5
- package/src/og/utils/earcut.js +1 -1
- package/src/og/utils/shared.js +15 -15
- package/src/og/webgl/Framebuffer.js +101 -53
- package/src/og/webgl/Handler.js +125 -85
- package/src/og/webgl/Multisample.js +55 -27
- package/src/og/webgl/Program.js +80 -35
- package/src/og/webgl/ProgramController.js +27 -23
- package/src/og/webgl/callbacks.js +8 -8
- package/types/Clock.d.ts +6 -2
- package/types/Deferred.d.ts +1 -1
- package/types/Events.d.ts +8 -4
- package/types/Extent.d.ts +37 -33
- package/types/Globe.d.ts +15 -13
- package/types/ImageCanvas.d.ts +5 -3
- package/types/LonLat.d.ts +24 -24
- package/types/Popup.d.ts +4 -0
- package/types/QueueArray.d.ts +6 -2
- package/types/Rectangle.d.ts +10 -4
- package/types/Stack.d.ts +4 -0
- package/types/ajax.d.ts +1 -1
- package/types/astro/earth.d.ts +3 -2
- package/types/bv/Box.d.ts +10 -5
- package/types/bv/Sphere.d.ts +13 -7
- package/types/camera/Camera.d.ts +90 -81
- package/types/camera/Frustum.d.ts +26 -22
- package/types/camera/PlanetCamera.d.ts +49 -53
- package/types/control/CompassButton.d.ts +4 -4
- package/types/control/Control.d.ts +7 -4
- package/types/control/DebugInfo.d.ts +3 -4
- package/types/control/EarthCoordinates.d.ts +6 -6
- package/types/control/EarthNavigation.d.ts +42 -0
- package/types/control/KeyboardNavigation.d.ts +3 -4
- package/types/control/LayerSwitcher.d.ts +3 -5
- package/types/control/Lighting.d.ts +3 -3
- package/types/control/MouseNavigation.d.ts +47 -0
- package/types/control/ScaleControl.d.ts +3 -3
- package/types/control/ShowFps.d.ts +3 -4
- package/types/control/SimpleNavigation.d.ts +3 -6
- package/types/control/Sun.d.ts +8 -10
- package/types/control/ToggleWireframe.d.ts +3 -3
- package/types/control/TouchNavigation.d.ts +48 -0
- package/types/control/ZoomControl.d.ts +3 -4
- package/types/control/index.d.ts +3 -1
- package/types/ellipsoid/Ellipsoid.d.ts +47 -43
- package/types/ellipsoid/wgs84.d.ts +3 -2
- package/types/entity/BaseBillboard.d.ts +41 -34
- package/types/entity/Billboard.d.ts +7 -7
- package/types/entity/BillboardHandler.d.ts +4 -0
- package/types/entity/Entity.d.ts +101 -83
- package/types/entity/EntityCollection.d.ts +57 -43
- package/types/entity/GeoObject.d.ts +111 -0
- package/types/entity/GeoObjectHandler.d.ts +77 -0
- package/types/entity/Geometry.d.ts +9 -7
- package/types/entity/GeometryHandler.d.ts +2 -2
- package/types/entity/Label.d.ts +24 -29
- package/types/entity/LabelHandler.d.ts +9 -2
- package/types/entity/LabelWorker.d.ts +9 -0
- package/types/entity/PointCloud.d.ts +8 -8
- package/types/entity/PointCloudHandler.d.ts +3 -3
- package/types/entity/Polyline.d.ts +58 -55
- package/types/entity/Ray.d.ts +19 -18
- package/types/entity/Strip.d.ts +8 -7
- package/types/entity/StripHandler.d.ts +3 -3
- package/types/entity/index.d.ts +7 -7
- package/types/input/KeyboardHandler.d.ts +10 -0
- package/types/input/MouseHandler.d.ts +5 -0
- package/types/input/TouchHandler.d.ts +5 -0
- package/types/layer/BaseGeoImage.d.ts +23 -35
- package/types/layer/CanvasTiles.d.ts +15 -22
- package/types/layer/GeoImage.d.ts +5 -18
- package/types/layer/GeoVideo.d.ts +5 -30
- package/types/layer/KML.d.ts +20 -15
- package/types/layer/Layer.d.ts +326 -0
- package/types/layer/Material.d.ts +45 -0
- package/types/layer/Vector.d.ts +208 -0
- package/types/layer/WMS.d.ts +4 -7
- package/types/layer/XYZ.d.ts +19 -25
- package/types/light/LightSource.d.ts +54 -53
- package/types/math/Line2.d.ts +11 -0
- package/types/math/Line3.d.ts +10 -0
- package/types/math/Mat3.d.ts +30 -18
- package/types/math/Mat4.d.ts +71 -52
- package/types/math/Plane.d.ts +5 -4
- package/types/math/Quat.d.ts +379 -0
- package/types/math/Ray.d.ts +82 -0
- package/types/math/Vec2.d.ts +102 -101
- package/types/math/Vec3.d.ts +143 -142
- package/types/math/Vec4.d.ts +40 -39
- package/types/math/coder.d.ts +12 -11
- package/types/math.d.ts +8 -8
- package/types/mercator.d.ts +3 -3
- package/types/proj/EPSG3857.d.ts +3 -2
- package/types/proj/EPSG4326.d.ts +3 -2
- package/types/proj/Proj.d.ts +42 -0
- package/types/quadTree/EntityCollectionNode.d.ts +34 -0
- package/types/quadTree/Node.d.ts +61 -0
- package/types/renderer/Renderer.d.ts +300 -0
- package/types/renderer/RendererEvents.d.ts +10 -7
- package/types/scene/BaseNode.d.ts +9 -9
- package/types/scene/Planet.d.ts +131 -126
- package/types/scene/RenderNode.d.ts +22 -23
- package/types/segment/Segment.d.ts +279 -0
- package/types/segment/SegmentLonLat.d.ts +16 -0
- package/types/shaders/geoObject.d.ts +3 -0
- package/types/shapes/BaseShape.d.ts +43 -40
- package/types/shapes/Sphere.d.ts +7 -7
- package/types/terrain/BilTerrain.d.ts +0 -1
- package/types/terrain/EmptyTerrain.d.ts +4 -4
- package/types/terrain/GlobusTerrain.d.ts +17 -54
- package/types/terrain/MapboxTerrain.d.ts +0 -1
- package/types/utils/GeoImageCreator.d.ts +3 -2
- package/types/utils/TextureAtlas.d.ts +8 -8
- package/types/utils/shared.d.ts +25 -24
- package/types/webgl/Framebuffer.d.ts +5 -5
- package/types/webgl/Handler.d.ts +68 -43
- package/types/webgl/Multisample.d.ts +5 -5
- package/types/webgl/Program.d.ts +8 -2
- package/types/webgl/ProgramController.d.ts +18 -13
- package/src/og/inherits.js +0 -8
- package/src/og/utils/polylabel.js +0 -176
- package/types/inherits.d.ts +0 -4
package/src/og/math/Quat.js
CHANGED
|
@@ -1,927 +1,980 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import * as math from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { Vec3 } from
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.
|
|
10
|
-
* @constructor
|
|
11
|
-
* @param {Number} [x=0.0] The X component.
|
|
12
|
-
* @param {Number} [y=0.0] The Y component.
|
|
13
|
-
* @param {Number} [z=0.0] The Z component.
|
|
14
|
-
* @param {Number} [w=0.0] The W component.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* The
|
|
20
|
-
* @
|
|
21
|
-
* @
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*
|
|
110
|
-
|
|
111
|
-
Quat.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
Quat.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
Quat
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
*
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
*
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
*
|
|
510
|
-
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
*
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
*
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
this.
|
|
606
|
-
this.
|
|
607
|
-
this.
|
|
608
|
-
this.
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
*
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
Quat.
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
Quat.
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
*
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
*
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
*
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import * as math from "../math.js";
|
|
4
|
+
import { Mat3 } from "./Mat3.js";
|
|
5
|
+
import { Mat4 } from "./Mat4.js";
|
|
6
|
+
import { Vec3 } from "./Vec3.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.
|
|
10
|
+
* @constructor
|
|
11
|
+
* @param {Number} [x=0.0] The X component.
|
|
12
|
+
* @param {Number} [y=0.0] The Y component.
|
|
13
|
+
* @param {Number} [z=0.0] The Z component.
|
|
14
|
+
* @param {Number} [w=0.0] The W component.
|
|
15
|
+
*/
|
|
16
|
+
export class Quat {
|
|
17
|
+
/**
|
|
18
|
+
* @param {Number} [x=0.0] The X component.
|
|
19
|
+
* @param {Number} [y=0.0] The Y component.
|
|
20
|
+
* @param {Number} [z=0.0] The Z component.
|
|
21
|
+
* @param {Number} [w=0.0] The W component.
|
|
22
|
+
*/
|
|
23
|
+
constructor(x, y, z, w) {
|
|
24
|
+
/**
|
|
25
|
+
* The X component.
|
|
26
|
+
* @public
|
|
27
|
+
* @type {Number}
|
|
28
|
+
* @default 0.0
|
|
29
|
+
*/
|
|
30
|
+
this.x = x || 0.0;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The Y component.
|
|
34
|
+
* @public
|
|
35
|
+
* @type {Number}
|
|
36
|
+
* @default 0.0
|
|
37
|
+
*/
|
|
38
|
+
this.y = y || 0.0;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The Z component.
|
|
42
|
+
* @public
|
|
43
|
+
* @type {Number}
|
|
44
|
+
* @default 0.0
|
|
45
|
+
*/
|
|
46
|
+
this.z = z || 0.0;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The W component.
|
|
50
|
+
* @public
|
|
51
|
+
* @type {Number}
|
|
52
|
+
* @default 0.0
|
|
53
|
+
*/
|
|
54
|
+
this.w = w || 0.0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Identity Quat.
|
|
59
|
+
* @const
|
|
60
|
+
* @type {Quat}
|
|
61
|
+
*/
|
|
62
|
+
static get IDENTITY() {
|
|
63
|
+
return new Quat(0.0, 0.0, 0.0, 1.0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Returns a Quat represents rotation around X axis.
|
|
68
|
+
* @static
|
|
69
|
+
* @param {number} a - The angle in radians to rotate around the axis.
|
|
70
|
+
* @returns {Quat} -
|
|
71
|
+
*/
|
|
72
|
+
static xRotation(a) {
|
|
73
|
+
a *= 0.5;
|
|
74
|
+
return new Quat(Math.sin(a), 0.0, 0.0, Math.cos(a));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns a Quat represents rotation around Y axis.
|
|
79
|
+
* @static
|
|
80
|
+
* @param {number} a - The angle in radians to rotate around the axis.
|
|
81
|
+
* @returns {Quat} -
|
|
82
|
+
*/
|
|
83
|
+
static yRotation(a) {
|
|
84
|
+
a *= 0.5;
|
|
85
|
+
return new Quat(0.0, Math.sin(a), 0.0, Math.cos(a));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Returns a Quat represents rotation around Z axis.
|
|
90
|
+
* @static
|
|
91
|
+
* @param {number} a - The angle in radians to rotate around the axis.
|
|
92
|
+
* @returns {Quat} -
|
|
93
|
+
*/
|
|
94
|
+
static zRotation(a) {
|
|
95
|
+
a *= 0.5;
|
|
96
|
+
return new Quat(0.0, 0.0, Math.sin(a), Math.cos(a));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Computes a Quat representing a rotation around an axis.
|
|
101
|
+
* @static
|
|
102
|
+
* @param {Vec3} axis - The axis of rotation.
|
|
103
|
+
* @param {number} [angle=0.0] The angle in radians to rotate around the axis.
|
|
104
|
+
* @returns {Quat} -
|
|
105
|
+
*/
|
|
106
|
+
static axisAngleToQuat(axis, angle) {
|
|
107
|
+
angle = angle || 0.0;
|
|
108
|
+
var v = axis.normal();
|
|
109
|
+
var half_angle = angle * 0.5;
|
|
110
|
+
var sin_a = Math.sin(half_angle);
|
|
111
|
+
return new Quat(v.x * sin_a, v.y * sin_a, v.z * sin_a, Math.cos(half_angle));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Computes a rotation from the given heading and up vector.
|
|
116
|
+
* @static
|
|
117
|
+
* @param {Vec3} forward - Heading target coordinates.
|
|
118
|
+
* @param {Vec3} up - Up vector.
|
|
119
|
+
* @returns {Quat} -
|
|
120
|
+
*/
|
|
121
|
+
static getLookRotation(forward, up) {
|
|
122
|
+
var f = forward.normal().negate();
|
|
123
|
+
var s = up.cross(f).normalize();
|
|
124
|
+
var u = f.cross(s);
|
|
125
|
+
|
|
126
|
+
var z = 1.0 + s.x + u.y + f.z;
|
|
127
|
+
|
|
128
|
+
if (z > 0.000001) {
|
|
129
|
+
let fd = 1.0 / (2.0 * Math.sqrt(z));
|
|
130
|
+
return new Quat((f.y - u.z) * fd, (s.z - f.x) * fd, (u.x - s.y) * fd, 0.25 / fd);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (s.x > u.y && s.x > f.z) {
|
|
134
|
+
let fd = 1.0 / (2.0 * Math.sqrt(1.0 + s.x - u.y - f.z));
|
|
135
|
+
return new Quat(0.25 / fd, (u.x + s.y) * fd, (s.z + f.x) * fd, (f.y - u.z) * fd);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (u.y > f.z) {
|
|
139
|
+
let fd = 1.0 / (2.0 * Math.sqrt(1.0 + u.y - s.x - f.z));
|
|
140
|
+
return new Quat((u.x + s.y) * fd, 0.25 / fd, (f.y + u.z) * fd, (s.z - f.x) * fd);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let fd = 1.0 / (2.0 * Math.sqrt(1.0 + f.z - s.x - u.y));
|
|
144
|
+
return new Quat((s.z + f.x) * fd, (f.y + u.z) * fd, 0.25 / fd, (u.x - s.y) * fd);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Computes a Quat from from source point heading to the destination point.
|
|
149
|
+
* @static
|
|
150
|
+
* @param {Vec3} sourcePoint - Source coordinate.
|
|
151
|
+
* @param {Vec3} destPoint - Destination coordinate.
|
|
152
|
+
* @returns {Quat} -
|
|
153
|
+
*/
|
|
154
|
+
static getLookAtSourceDest(sourcePoint, destPoint) {
|
|
155
|
+
var forwardVector = destPoint.subA(sourcePoint).normalize();
|
|
156
|
+
var dot = Vec3.FORWARD.dot(forwardVector);
|
|
157
|
+
if (Math.abs(dot - -1.0) < 0.000001) {
|
|
158
|
+
return Quat.axisAngleToQuat(Vec3.UP, Math.PI);
|
|
159
|
+
}
|
|
160
|
+
if (Math.abs(dot - 1.0) < 0.000001) {
|
|
161
|
+
return new Quat(0.0, 0.0, 0.0, 1.0);
|
|
162
|
+
}
|
|
163
|
+
var rotAngle = Math.acos(dot);
|
|
164
|
+
var rotAxis = Vec3.FORWARD.cross(forwardVector).normalize();
|
|
165
|
+
return Quat.axisAngleToQuat(rotAxis, rotAngle);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Compute rotation between two vectors.
|
|
170
|
+
* @static
|
|
171
|
+
* @param {Vec3} u - First vector.
|
|
172
|
+
* @param {Vec3} v - Second vector.
|
|
173
|
+
* @returns {Quat} -
|
|
174
|
+
*/
|
|
175
|
+
static getRotationBetweenVectors(u, v) {
|
|
176
|
+
var w = u.cross(v);
|
|
177
|
+
var q = new Quat(w.x, w.y, w.z, 1.0 + u.dot(v));
|
|
178
|
+
return q.normalize();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Compute rotation between two vectors.
|
|
183
|
+
* @static
|
|
184
|
+
* @param {Vec3} u - First vector.
|
|
185
|
+
* @param {Vec3} v - Second vector.
|
|
186
|
+
* @param {Quat} res
|
|
187
|
+
* @returns {Quat} -
|
|
188
|
+
*/
|
|
189
|
+
static getRotationBetweenVectorsRes(u, v, res) {
|
|
190
|
+
var w = u.cross(v);
|
|
191
|
+
res.set(w.x, w.y, w.z, 1.0 + u.dot(v));
|
|
192
|
+
return res.normalize();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Compute rotation between two vectors with around vector up
|
|
197
|
+
* for exactly opposite vectors. If vectors exaclty in the same
|
|
198
|
+
* direction than returns identity Quat.
|
|
199
|
+
* @static
|
|
200
|
+
* @param {Vec3} source - First vector.
|
|
201
|
+
* @param {Vec3} dest - Second vector.
|
|
202
|
+
* @param {Vec3} up - Up vector.
|
|
203
|
+
* @returns {Quat} -
|
|
204
|
+
*/
|
|
205
|
+
static getRotationBetweenVectorsUp(source, dest, up) {
|
|
206
|
+
var dot = source.dot(dest);
|
|
207
|
+
if (Math.abs(dot + 1.0) < 0.000001) {
|
|
208
|
+
// vector source and dest point exactly in the opposite direction,
|
|
209
|
+
// so it is a 180 degrees turn around the up-axis
|
|
210
|
+
return Quat.axisAngleToQuat(up, Math.PI);
|
|
211
|
+
}
|
|
212
|
+
if (Math.abs(dot - 1.0) < 0.000001) {
|
|
213
|
+
// vector source and dest point exactly in the same direction
|
|
214
|
+
// so we return the identity Quat
|
|
215
|
+
return new Quat(0, 0, 0, 1);
|
|
216
|
+
}
|
|
217
|
+
var rotAngle = Math.acos(dot);
|
|
218
|
+
var rotAxis = source.cross(dest).normalize();
|
|
219
|
+
return Quat.axisAngleToQuat(rotAxis, rotAngle);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Returns true if the components are zero.
|
|
224
|
+
* @public
|
|
225
|
+
* @param {Quat} q - Quat to subtract.
|
|
226
|
+
* @returns {Quat} -
|
|
227
|
+
*/
|
|
228
|
+
isZero() {
|
|
229
|
+
return this.x === 0.0 && this.y === 0.0 && this.z === 0.0 && this.w === 0.0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Clear Quat. Sets zeroes.
|
|
234
|
+
* @public
|
|
235
|
+
* @returns {Quat} -
|
|
236
|
+
*/
|
|
237
|
+
clear() {
|
|
238
|
+
this.x = this.y = this.z = this.w = 0;
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Sets Quat values.
|
|
244
|
+
* @public
|
|
245
|
+
* @param {Number} [x=0.0] The X component.
|
|
246
|
+
* @param {Number} [y=0.0] The Y component.
|
|
247
|
+
* @param {Number} [z=0.0] The Z component.
|
|
248
|
+
* @param {Number} [w=0.0] The W component.
|
|
249
|
+
* @returns {Quat} -
|
|
250
|
+
*/
|
|
251
|
+
set(x, y, z, w) {
|
|
252
|
+
this.x = x;
|
|
253
|
+
this.y = y;
|
|
254
|
+
this.z = z;
|
|
255
|
+
this.w = w;
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Copy Quat values.
|
|
261
|
+
* @public
|
|
262
|
+
* @param {Quat} q - Copy Quat.
|
|
263
|
+
* @returns {Quat} -
|
|
264
|
+
*/
|
|
265
|
+
copy(q) {
|
|
266
|
+
this.x = q.x;
|
|
267
|
+
this.y = q.y;
|
|
268
|
+
this.z = q.z;
|
|
269
|
+
this.w = q.w;
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Set current Quat instance to identity Quat.
|
|
275
|
+
* @public
|
|
276
|
+
* @returns {Quat} -
|
|
277
|
+
*/
|
|
278
|
+
setIdentity() {
|
|
279
|
+
this.x = 0.0;
|
|
280
|
+
this.y = 0.0;
|
|
281
|
+
this.z = 0.0;
|
|
282
|
+
this.w = 1.0;
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Duplicates a Quat instance.
|
|
288
|
+
* @public
|
|
289
|
+
* @returns {Quat} -
|
|
290
|
+
*/
|
|
291
|
+
clone() {
|
|
292
|
+
return new Quat(this.x, this.y, this.z, this.w);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Computes the componentwise sum of two Quats.
|
|
297
|
+
* @public
|
|
298
|
+
* @param {Quat} q - Quat to add.
|
|
299
|
+
* @returns {Quat} -
|
|
300
|
+
*/
|
|
301
|
+
add(q) {
|
|
302
|
+
return new Quat(this.x + q.x, this.y + q.y, this.z + q.z, this.w + q.w);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Computes the componentwise difference of two Quats.
|
|
307
|
+
* @public
|
|
308
|
+
* @param {Quat} q - Quat to subtract.
|
|
309
|
+
* @returns {Quat} -
|
|
310
|
+
*/
|
|
311
|
+
sub(q) {
|
|
312
|
+
return new Quat(this.x - q.x, this.y - q.y, this.z - q.z, this.w - q.w);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Multiplies the provided Quat componentwise by the provided scalar.
|
|
317
|
+
* @public
|
|
318
|
+
* @param {Number} scale - The scalar to multiply with.
|
|
319
|
+
* @returns {Quat} -
|
|
320
|
+
*/
|
|
321
|
+
scaleTo(scale) {
|
|
322
|
+
return new Quat(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Multiplies the provided Quat componentwise.
|
|
327
|
+
* @public
|
|
328
|
+
* @param {Number} scale - The scalar to multiply with.
|
|
329
|
+
* @returns {Quat} -
|
|
330
|
+
*/
|
|
331
|
+
scale(scale) {
|
|
332
|
+
this.x *= scale;
|
|
333
|
+
this.y *= scale;
|
|
334
|
+
this.z *= scale;
|
|
335
|
+
this.w *= scale;
|
|
336
|
+
return this;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Converts Quat values to array.
|
|
341
|
+
* @public
|
|
342
|
+
* @returns {Array.<number>} - (exactly 4 entries)
|
|
343
|
+
*/
|
|
344
|
+
toVec() {
|
|
345
|
+
return [this.x, this.y, this.z, this.w];
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Sets current quaternion by spherical coordinates.
|
|
350
|
+
* @public
|
|
351
|
+
* @param {number} lat - Latitude.
|
|
352
|
+
* @param {number} lon - Longitude.
|
|
353
|
+
* @param {number} angle - Angle in radians.
|
|
354
|
+
* @returns {Quat} -
|
|
355
|
+
*/
|
|
356
|
+
setFromSphericalCoords(lat, lon, angle) {
|
|
357
|
+
var sin_a = Math.sin(angle / 2);
|
|
358
|
+
var cos_a = Math.cos(angle / 2);
|
|
359
|
+
var sin_lat = Math.sin(lat);
|
|
360
|
+
var cos_lat = Math.cos(lat);
|
|
361
|
+
var sin_long = Math.sin(lon);
|
|
362
|
+
var cos_long = Math.cos(lon);
|
|
363
|
+
this.x = sin_a * cos_lat * sin_long;
|
|
364
|
+
this.y = sin_a * sin_lat;
|
|
365
|
+
this.z = sin_a * sin_lat * cos_long;
|
|
366
|
+
this.w = cos_a;
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Sets rotation with the given heading and up vectors.
|
|
372
|
+
* @static
|
|
373
|
+
* @param {Vec3} forward - Heading target coordinates.
|
|
374
|
+
* @param {Vec3} up - Up vector.
|
|
375
|
+
* @returns {Quat} -
|
|
376
|
+
*/
|
|
377
|
+
setLookRotation(forward, up) {
|
|
378
|
+
var f = forward.normal().negate();
|
|
379
|
+
var s = up.cross(f).normalize();
|
|
380
|
+
var u = f.cross(s);
|
|
381
|
+
|
|
382
|
+
var z = 1.0 + s.x + u.y + f.z;
|
|
383
|
+
|
|
384
|
+
if (z > 0.000001) {
|
|
385
|
+
let fd = 1.0 / (2.0 * Math.sqrt(z));
|
|
386
|
+
this.x = (f.y - u.z) * fd;
|
|
387
|
+
this.y = (s.z - f.x) * fd;
|
|
388
|
+
this.z = (u.x - s.y) * fd;
|
|
389
|
+
this.w = 0.25 / fd;
|
|
390
|
+
} else if (s.x > u.y && s.x > f.z) {
|
|
391
|
+
let fd = 1.0 / (2.0 * Math.sqrt(1.0 + s.x - u.y - f.z));
|
|
392
|
+
this.x = 0.25 / fd;
|
|
393
|
+
this.y = (u.x + s.y) * fd;
|
|
394
|
+
this.z = (s.z + f.x) * fd;
|
|
395
|
+
this.w = (f.y - u.z) * fd;
|
|
396
|
+
} else if (u.y > f.z) {
|
|
397
|
+
let fd = 1.0 / (2.0 * Math.sqrt(1.0 + u.y - s.x - f.z));
|
|
398
|
+
this.x = (u.x + s.y) * fd;
|
|
399
|
+
this.y = 0.25 / fd;
|
|
400
|
+
this.z = (f.y + u.z) * fd;
|
|
401
|
+
this.w = (s.z - f.x) * fd;
|
|
402
|
+
} else {
|
|
403
|
+
let fd = 1.0 / (2.0 * Math.sqrt(1.0 + f.z - s.x - u.y));
|
|
404
|
+
this.x = (s.z + f.x) * fd;
|
|
405
|
+
this.y = (f.y + u.z) * fd;
|
|
406
|
+
this.z = 0.25 / fd;
|
|
407
|
+
this.w = (u.x - s.y) * fd;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return this;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Gets spherical coordinates.
|
|
415
|
+
* @public
|
|
416
|
+
* @returns {Object} Returns object with latitude, longitude and alpha.
|
|
417
|
+
*/
|
|
418
|
+
toSphericalCoords() {
|
|
419
|
+
var cos_a = this.w;
|
|
420
|
+
var sin_a = Math.sqrt(1.0 - cos_a * cos_a);
|
|
421
|
+
// var angle = Math.acos(cos_a) * 2;
|
|
422
|
+
if (Math.abs(sin_a) < 0.0005) {
|
|
423
|
+
sin_a = 1;
|
|
424
|
+
}
|
|
425
|
+
var tx = this.x / sin_a;
|
|
426
|
+
var ty = this.y / sin_a;
|
|
427
|
+
var tz = this.z / sin_a;
|
|
428
|
+
|
|
429
|
+
var lon,
|
|
430
|
+
lat = -Math.asin(ty);
|
|
431
|
+
if (tx * tx + tz * tz < 0.0005) {
|
|
432
|
+
lon = 0;
|
|
433
|
+
} else {
|
|
434
|
+
lon = Math.atan2(tx, tz);
|
|
435
|
+
}
|
|
436
|
+
if (lon < 0) {
|
|
437
|
+
lon += 360.0;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return { lat: lat, lon: lon, alpha: Math.acos(cos_a) };
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Sets current Quat representing a rotation around an axis.
|
|
445
|
+
* @public
|
|
446
|
+
* @param {Vec3} axis - The axis of rotation.
|
|
447
|
+
* @param {number} angle The angle in radians to rotate around the axis.
|
|
448
|
+
* @returns {Quat} -
|
|
449
|
+
*/
|
|
450
|
+
setFromAxisAngle(axis, angle) {
|
|
451
|
+
var v = axis.normal();
|
|
452
|
+
var half_angle = angle * 0.5;
|
|
453
|
+
var sin_a = Math.sin(half_angle);
|
|
454
|
+
this.set(v.x * sin_a, v.y * sin_a, v.z * sin_a, Math.cos(half_angle));
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Returns axis and angle of the current Quat.
|
|
460
|
+
* @public
|
|
461
|
+
* @returns {Object} -
|
|
462
|
+
*/
|
|
463
|
+
getAxisAngle() {
|
|
464
|
+
let x = this.x,
|
|
465
|
+
y = this.y,
|
|
466
|
+
z = this.z,
|
|
467
|
+
w = this.w;
|
|
468
|
+
var vl = Math.sqrt(x * x + y * y + z * z);
|
|
469
|
+
var axis, angle;
|
|
470
|
+
if (vl > 0.0000001) {
|
|
471
|
+
var ivl = 1.0 / vl;
|
|
472
|
+
axis = new Vec3(x * ivl, y * ivl, z * ivl);
|
|
473
|
+
if (w < 0) {
|
|
474
|
+
angle = 2.0 * Math.atan2(-vl, -w); // -PI,0
|
|
475
|
+
} else {
|
|
476
|
+
angle = 2.0 * Math.atan2(vl, w); // 0,PI
|
|
477
|
+
}
|
|
478
|
+
} else {
|
|
479
|
+
axis = new Vec3(0, 0, 0);
|
|
480
|
+
angle = 0;
|
|
481
|
+
}
|
|
482
|
+
return { axis: axis, angle: angle };
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Sets current Quat by Euler's angles.
|
|
487
|
+
* @public
|
|
488
|
+
* @param {number} pitch - Pitch angle in degrees.
|
|
489
|
+
* @param {number} yaw - Yaw angle in degrees.
|
|
490
|
+
* @param {number} roll - Roll angle in degrees.
|
|
491
|
+
* @returns {Quat} -
|
|
492
|
+
*/
|
|
493
|
+
setFromEulerAngles(pitch, yaw, roll) {
|
|
494
|
+
var ex = pitch * math.RADIANS_HALF,
|
|
495
|
+
ey = yaw * math.RADIANS_HALF,
|
|
496
|
+
ez = roll * math.RADIANS_HALF;
|
|
497
|
+
|
|
498
|
+
var cr = Math.cos(ex),
|
|
499
|
+
cp = Math.cos(ey),
|
|
500
|
+
cy = Math.cos(ez);
|
|
501
|
+
|
|
502
|
+
var sr = Math.sin(ex),
|
|
503
|
+
sp = Math.sin(ey),
|
|
504
|
+
sy = Math.sin(ez);
|
|
505
|
+
|
|
506
|
+
var cpcy = cp * cy,
|
|
507
|
+
spsy = sp * sy;
|
|
508
|
+
|
|
509
|
+
this.w = cr * cpcy + sr * spsy;
|
|
510
|
+
this.x = sr * cpcy - cr * spsy;
|
|
511
|
+
this.y = cr * sp * cy + sr * cp * sy;
|
|
512
|
+
this.z = cr * cp * sy - sr * sp * cy;
|
|
513
|
+
|
|
514
|
+
return this.normalize();
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Returns Euler's angles of the current Quat.
|
|
519
|
+
* @public
|
|
520
|
+
* @returns {Object} -
|
|
521
|
+
*/
|
|
522
|
+
getEulerAngles() {
|
|
523
|
+
let x = this.x,
|
|
524
|
+
y = this.y,
|
|
525
|
+
z = this.z,
|
|
526
|
+
w = this.w;
|
|
527
|
+
|
|
528
|
+
let sqy = y * y;
|
|
529
|
+
|
|
530
|
+
let roll = Math.atan2(2.0 * (w * x + y * z), 1.0 - 2.0 * (x * x + sqy));
|
|
531
|
+
|
|
532
|
+
let a = w * y - z * x;
|
|
533
|
+
|
|
534
|
+
if (a < -1.0) {
|
|
535
|
+
a = -1.0;
|
|
536
|
+
} else if (a > 1.0) {
|
|
537
|
+
a = 1.0;
|
|
538
|
+
}
|
|
539
|
+
let pitch = Math.asin(2.0 * a);
|
|
540
|
+
|
|
541
|
+
let yaw = Math.atan2(2.0 * (w * z + x * y), 1.0 - 2.0 * (sqy + z * z));
|
|
542
|
+
|
|
543
|
+
return { roll, pitch, yaw };
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Computes a Quat from the provided 4x4 matrix instance.
|
|
548
|
+
* @public
|
|
549
|
+
* @param {Mat4} m - The rotation matrix.
|
|
550
|
+
* @returns {Quat} -
|
|
551
|
+
*/
|
|
552
|
+
setFromMatrix4(m) {
|
|
553
|
+
var tr,
|
|
554
|
+
s,
|
|
555
|
+
q = [];
|
|
556
|
+
var i, j, k;
|
|
557
|
+
m = m._m;
|
|
558
|
+
|
|
559
|
+
var nxt = [1, 2, 0];
|
|
560
|
+
|
|
561
|
+
tr = m[0] + m[5] + m[10];
|
|
562
|
+
|
|
563
|
+
if (tr > 0.0) {
|
|
564
|
+
s = Math.sqrt(tr + 1.0);
|
|
565
|
+
this.w = s / 2.0;
|
|
566
|
+
s = 0.5 / s;
|
|
567
|
+
this.x = (m[6] - m[9]) * s;
|
|
568
|
+
this.y = (m[8] - m[2]) * s;
|
|
569
|
+
this.z = (m[1] - m[4]) * s;
|
|
570
|
+
} else {
|
|
571
|
+
i = 0;
|
|
572
|
+
if (m[5] > m[0]) i = 1;
|
|
573
|
+
if (m[10] > m[i * 5]) i = 2;
|
|
574
|
+
j = nxt[i];
|
|
575
|
+
k = nxt[j];
|
|
576
|
+
|
|
577
|
+
s = Math.sqrt(m[i * 5] - (m[j * 5] + m[k * 5]) + 1.0);
|
|
578
|
+
|
|
579
|
+
q[i] = s * 0.5;
|
|
580
|
+
|
|
581
|
+
if (s !== 0.0) s = 0.5 / s;
|
|
582
|
+
|
|
583
|
+
q[3] = (m[j * 4 + k] - m[k * 4 + j]) * s;
|
|
584
|
+
q[j] = (m[i * 4 + j] + m[j * 4 + i]) * s;
|
|
585
|
+
q[k] = (m[i * 4 + k] + m[k * 4 + i]) * s;
|
|
586
|
+
|
|
587
|
+
this.x = q[0];
|
|
588
|
+
this.y = q[1];
|
|
589
|
+
this.z = q[2];
|
|
590
|
+
this.w = q[3];
|
|
591
|
+
}
|
|
592
|
+
return this;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Converts current Quat to the rotation 4x4 matrix.
|
|
597
|
+
* @public
|
|
598
|
+
* @returns {Mat4} -
|
|
599
|
+
*/
|
|
600
|
+
getMat4(out) {
|
|
601
|
+
var xs = this.x + this.x;
|
|
602
|
+
var ys = this.y + this.y;
|
|
603
|
+
var zs = this.z + this.z;
|
|
604
|
+
var wx = this.w * xs;
|
|
605
|
+
var wy = this.w * ys;
|
|
606
|
+
var wz = this.w * zs;
|
|
607
|
+
var xx = this.x * xs;
|
|
608
|
+
var xy = this.x * ys;
|
|
609
|
+
var xz = this.x * zs;
|
|
610
|
+
var yy = this.y * ys;
|
|
611
|
+
var yz = this.y * zs;
|
|
612
|
+
var zz = this.z * zs;
|
|
613
|
+
var m = out || new Mat4();
|
|
614
|
+
return m.set([
|
|
615
|
+
1 - (yy + zz),
|
|
616
|
+
xy - wz,
|
|
617
|
+
xz + wy,
|
|
618
|
+
0,
|
|
619
|
+
xy + wz,
|
|
620
|
+
1 - (xx + zz),
|
|
621
|
+
yz - wx,
|
|
622
|
+
0,
|
|
623
|
+
xz - wy,
|
|
624
|
+
yz + wx,
|
|
625
|
+
1 - (xx + yy),
|
|
626
|
+
0,
|
|
627
|
+
0,
|
|
628
|
+
0,
|
|
629
|
+
0,
|
|
630
|
+
1
|
|
631
|
+
]);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Converts current Quat to the rotation 3x3 matrix.
|
|
636
|
+
* @public
|
|
637
|
+
* @returns {Mat3} -
|
|
638
|
+
* @todo NOT TESTED
|
|
639
|
+
*/
|
|
640
|
+
getMat3() {
|
|
641
|
+
var m = new Mat3();
|
|
642
|
+
var mx = m._m;
|
|
643
|
+
var c = this.x,
|
|
644
|
+
d = this.y,
|
|
645
|
+
e = this.z,
|
|
646
|
+
g = this.w,
|
|
647
|
+
f = c + c,
|
|
648
|
+
h = d + d,
|
|
649
|
+
i = e + e,
|
|
650
|
+
j = c * f,
|
|
651
|
+
k = c * h;
|
|
652
|
+
|
|
653
|
+
c = c * i;
|
|
654
|
+
|
|
655
|
+
var l = d * h;
|
|
656
|
+
|
|
657
|
+
d = d * i;
|
|
658
|
+
e = e * i;
|
|
659
|
+
f = g * f;
|
|
660
|
+
h = g * h;
|
|
661
|
+
g = g * i;
|
|
662
|
+
|
|
663
|
+
mx[0] = 1 - (l + e);
|
|
664
|
+
mx[1] = k - g;
|
|
665
|
+
mx[2] = c + h;
|
|
666
|
+
mx[3] = k + g;
|
|
667
|
+
mx[4] = 1 - (j + e);
|
|
668
|
+
mx[5] = d - f;
|
|
669
|
+
mx[6] = c - h;
|
|
670
|
+
mx[7] = d + f;
|
|
671
|
+
mx[8] = 1 - (j + l);
|
|
672
|
+
|
|
673
|
+
return m;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Returns quatrenion and vector production.
|
|
678
|
+
* @public
|
|
679
|
+
* @param {Vec3} v - 3d Vector.
|
|
680
|
+
* @returns {Vec3} -
|
|
681
|
+
*/
|
|
682
|
+
mulVec3(v) {
|
|
683
|
+
// t = 2 * cross(q.xyz, v)
|
|
684
|
+
// v' = v + q.w * t + cross(q.xyz, t)
|
|
685
|
+
|
|
686
|
+
var d = v.x,
|
|
687
|
+
e = v.y,
|
|
688
|
+
g = v.z;
|
|
689
|
+
|
|
690
|
+
var b = this.x,
|
|
691
|
+
f = this.y,
|
|
692
|
+
h = this.z,
|
|
693
|
+
a = this.w;
|
|
694
|
+
|
|
695
|
+
var i = a * d + f * g - h * e,
|
|
696
|
+
j = a * e + h * d - b * g,
|
|
697
|
+
k = a * g + b * e - f * d;
|
|
698
|
+
|
|
699
|
+
d = -b * d - f * e - h * g;
|
|
700
|
+
|
|
701
|
+
return new Vec3(
|
|
702
|
+
i * a + d * -b + j * -h - k * -f,
|
|
703
|
+
j * a + d * -f + k * -b - i * -h,
|
|
704
|
+
k * a + d * -h + i * -f - j * -b
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Computes the product of two Quats.
|
|
710
|
+
* @public
|
|
711
|
+
* @param {Quat} q - Quat to multiply.
|
|
712
|
+
* @returns {Quat} -
|
|
713
|
+
*/
|
|
714
|
+
mul(q) {
|
|
715
|
+
var d = this.x,
|
|
716
|
+
e = this.y,
|
|
717
|
+
g = this.z,
|
|
718
|
+
a = this.w;
|
|
719
|
+
var f = q.x,
|
|
720
|
+
h = q.y,
|
|
721
|
+
i = q.z,
|
|
722
|
+
b = q.w;
|
|
723
|
+
return new Quat(
|
|
724
|
+
d * b + a * f + e * i - g * h,
|
|
725
|
+
e * b + a * h + g * f - d * i,
|
|
726
|
+
g * b + a * i + d * h - e * f,
|
|
727
|
+
a * b - d * f - e * h - g * i
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Computes the product of two Quats.
|
|
733
|
+
* @public
|
|
734
|
+
* @param {Quat} q - Quat to multiply.
|
|
735
|
+
* @returns {Quat} -
|
|
736
|
+
*/
|
|
737
|
+
mulA(q) {
|
|
738
|
+
var d = this.x,
|
|
739
|
+
e = this.y,
|
|
740
|
+
g = this.z,
|
|
741
|
+
a = this.w;
|
|
742
|
+
var f = q.x,
|
|
743
|
+
h = q.y,
|
|
744
|
+
i = q.z,
|
|
745
|
+
b = q.w;
|
|
746
|
+
this.x = d * b + a * f + e * i - g * h;
|
|
747
|
+
this.y = e * b + a * h + g * f - d * i;
|
|
748
|
+
this.z = g * b + a * i + d * h - e * f;
|
|
749
|
+
this.w = a * b - d * f - e * h - g * i;
|
|
750
|
+
return this;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Gets the conjugate of the Quat.
|
|
755
|
+
* @public
|
|
756
|
+
* @returns {Quat} -
|
|
757
|
+
*/
|
|
758
|
+
conjugate() {
|
|
759
|
+
return new Quat(-this.x, -this.y, -this.z, this.w);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* Computes the inverse of the Quat.
|
|
764
|
+
* @public
|
|
765
|
+
* @returns {Quat} -
|
|
766
|
+
*/
|
|
767
|
+
inverse() {
|
|
768
|
+
var n = 1 / this.magnitude2();
|
|
769
|
+
return new Quat(-this.x * n, -this.y * n, -this.z * n, this.w * n);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Computes a magnitude of the Quat.
|
|
774
|
+
* @public
|
|
775
|
+
* @returns {number} -
|
|
776
|
+
*/
|
|
777
|
+
magnitude() {
|
|
778
|
+
var b = this.x,
|
|
779
|
+
c = this.y,
|
|
780
|
+
d = this.z,
|
|
781
|
+
a = this.w;
|
|
782
|
+
return Math.sqrt(b * b + c * c + d * d + a * a);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Computes a squared magnitude of the Quat.
|
|
787
|
+
* @public
|
|
788
|
+
* @returns {number} -
|
|
789
|
+
*/
|
|
790
|
+
magnitude2() {
|
|
791
|
+
var b = this.x,
|
|
792
|
+
c = this.y,
|
|
793
|
+
d = this.z,
|
|
794
|
+
a = this.w;
|
|
795
|
+
return b * b + c * c + d * d + a * a;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Computes the dot (scalar) product of two Quats.
|
|
800
|
+
* @public
|
|
801
|
+
* @param {Quat} q - Second quatrnion.
|
|
802
|
+
* @returns {number} -
|
|
803
|
+
*/
|
|
804
|
+
dot(q) {
|
|
805
|
+
return this.x * q.x + this.y * q.y + this.z * q.z;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Current Quat normalization.
|
|
810
|
+
* @public
|
|
811
|
+
* @returns {Quat} -
|
|
812
|
+
*/
|
|
813
|
+
normalize() {
|
|
814
|
+
var c = this.x,
|
|
815
|
+
d = this.y,
|
|
816
|
+
e = this.z,
|
|
817
|
+
g = this.w,
|
|
818
|
+
f = Math.sqrt(c * c + d * d + e * e + g * g);
|
|
819
|
+
if (f === 0.0) {
|
|
820
|
+
this.x = 0;
|
|
821
|
+
this.y = 0;
|
|
822
|
+
this.z = 0;
|
|
823
|
+
this.w = 0;
|
|
824
|
+
return this;
|
|
825
|
+
}
|
|
826
|
+
f = 1 / f;
|
|
827
|
+
this.x = c * f;
|
|
828
|
+
this.y = d * f;
|
|
829
|
+
this.z = e * f;
|
|
830
|
+
this.w = g * f;
|
|
831
|
+
return this;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Compares two Quats.
|
|
836
|
+
* @public
|
|
837
|
+
* @param {Quat} q - Second quatrnion.
|
|
838
|
+
* @returns {Boolean} -
|
|
839
|
+
*/
|
|
840
|
+
isEqual(q) {
|
|
841
|
+
var matching = this.dot(q);
|
|
842
|
+
if (Math.abs(matching - 1.0) < 0.001) {
|
|
843
|
+
return true;
|
|
844
|
+
}
|
|
845
|
+
return false;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* Performs a spherical linear interpolation between two Quats.
|
|
850
|
+
* @public
|
|
851
|
+
* @param {Quat} b - The end rotation Quat.
|
|
852
|
+
* @param {number} t - interpolation amount between the two Quats.
|
|
853
|
+
* @returns {Quat} -
|
|
854
|
+
*/
|
|
855
|
+
slerp(b, t) {
|
|
856
|
+
var ax = this.x,
|
|
857
|
+
ay = this.y,
|
|
858
|
+
az = this.z,
|
|
859
|
+
aw = this.w,
|
|
860
|
+
bx = b.x,
|
|
861
|
+
by = b.y,
|
|
862
|
+
bz = b.z,
|
|
863
|
+
bw = b.w;
|
|
864
|
+
|
|
865
|
+
var omega, cosom, sinom, scale0, scale1;
|
|
866
|
+
|
|
867
|
+
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
|
868
|
+
|
|
869
|
+
if (cosom < 0.0) {
|
|
870
|
+
cosom = -cosom;
|
|
871
|
+
bx = -bx;
|
|
872
|
+
by = -by;
|
|
873
|
+
bz = -bz;
|
|
874
|
+
bw = -bw;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
if (1.0 - cosom > 0.000001) {
|
|
878
|
+
omega = Math.acos(cosom);
|
|
879
|
+
sinom = Math.sin(omega);
|
|
880
|
+
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
|
881
|
+
scale1 = Math.sin(t * omega) / sinom;
|
|
882
|
+
} else {
|
|
883
|
+
scale0 = 1.0 - t;
|
|
884
|
+
scale1 = t;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
return new Quat(
|
|
888
|
+
scale0 * ax + scale1 * bx,
|
|
889
|
+
scale0 * ay + scale1 * by,
|
|
890
|
+
scale0 * az + scale1 * bz,
|
|
891
|
+
scale0 * aw + scale1 * bw
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Returns a roll angle in radians.
|
|
897
|
+
* @public
|
|
898
|
+
* @param {Boolean} [reprojectAxis] -
|
|
899
|
+
* @returns {Number} -
|
|
900
|
+
*/
|
|
901
|
+
getRoll(reprojectAxis) {
|
|
902
|
+
var x = this.x,
|
|
903
|
+
y = this.y,
|
|
904
|
+
z = this.z,
|
|
905
|
+
w = this.w;
|
|
906
|
+
if (reprojectAxis) {
|
|
907
|
+
var fTy = 2.0 * y;
|
|
908
|
+
var fTz = 2.0 * z;
|
|
909
|
+
var fTwz = fTz * w;
|
|
910
|
+
var fTxy = fTy * x;
|
|
911
|
+
var fTyy = fTy * y;
|
|
912
|
+
var fTzz = fTz * z;
|
|
913
|
+
return Math.atan2(fTxy + fTwz, 1.0 - (fTyy + fTzz));
|
|
914
|
+
} else {
|
|
915
|
+
return Math.atan2(2 * (x * y + w * z), w * w + x * x - y * y - z * z);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* Returns a pitch angle in radians.
|
|
921
|
+
* @public
|
|
922
|
+
* @param {Boolean} [reprojectAxis] -
|
|
923
|
+
* @returns {number} -
|
|
924
|
+
*/
|
|
925
|
+
getPitch(reprojectAxis) {
|
|
926
|
+
var x = this.x,
|
|
927
|
+
y = this.y,
|
|
928
|
+
z = this.z,
|
|
929
|
+
w = this.w;
|
|
930
|
+
if (reprojectAxis) {
|
|
931
|
+
var fTx = 2.0 * x;
|
|
932
|
+
var fTz = 2.0 * z;
|
|
933
|
+
var fTwx = fTx * w;
|
|
934
|
+
var fTxx = fTx * x;
|
|
935
|
+
var fTyz = fTz * y;
|
|
936
|
+
var fTzz = fTz * z;
|
|
937
|
+
return Math.atan2(fTyz + fTwx, 1.0 - (fTxx + fTzz));
|
|
938
|
+
} else {
|
|
939
|
+
return Math.atan2(2 * (y * z + w * x), w * w - x * x - y * y + z * z);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Returns a yaw angle in radians.
|
|
945
|
+
* @public
|
|
946
|
+
* @param {Boolean} [reprojectAxis] -
|
|
947
|
+
* @returns {number} -
|
|
948
|
+
*/
|
|
949
|
+
getYaw(reprojectAxis) {
|
|
950
|
+
var x = this.x,
|
|
951
|
+
y = this.y,
|
|
952
|
+
z = this.z,
|
|
953
|
+
w = this.w;
|
|
954
|
+
if (reprojectAxis) {
|
|
955
|
+
var fTx = 2.0 * x;
|
|
956
|
+
var fTy = 2.0 * y;
|
|
957
|
+
var fTz = 2.0 * z;
|
|
958
|
+
var fTwy = fTy * w;
|
|
959
|
+
var fTxx = fTx * x;
|
|
960
|
+
var fTxz = fTz * x;
|
|
961
|
+
var fTyy = fTy * y;
|
|
962
|
+
return Math.atan2(fTxz + fTwy, 1.0 - (fTxx + fTyy));
|
|
963
|
+
} else {
|
|
964
|
+
return Math.asin(-2 * (x * z - w * y));
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Creates Quat instance.
|
|
971
|
+
* @function
|
|
972
|
+
* @param {Number} [x=0.0] The X component.
|
|
973
|
+
* @param {Number} [y=0.0] The Y component.
|
|
974
|
+
* @param {Number} [z=0.0] The Z component.
|
|
975
|
+
* @param {Number} [w=0.0] The W component.
|
|
976
|
+
* @returns {Quat} -
|
|
977
|
+
*/
|
|
978
|
+
export function quat(x, y, z, w) {
|
|
979
|
+
return new Quat(x, y, z, w);
|
|
980
|
+
}
|