deeptwins-cesium-engine 0.1.2 → 0.1.4
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/Build/Workers/chunk-2HWLF3FT.js +837 -0
- package/Build/Workers/chunk-2KXMJ5XS.js +3792 -0
- package/Build/Workers/chunk-2NPCLB3H.js +56 -0
- package/Build/Workers/chunk-2ZHQTIBH.js +1483 -0
- package/Build/Workers/chunk-3GLYOW63.js +352 -0
- package/Build/Workers/chunk-3L22KMPU.js +219 -0
- package/Build/Workers/chunk-3Q6V2B2I.js +73 -0
- package/Build/Workers/chunk-3QOKKRIG.js +387 -0
- package/Build/Workers/chunk-44YZFGRH.js +1800 -0
- package/Build/Workers/chunk-45VV4SBO.js +2342 -0
- package/Build/Workers/chunk-4EJ4AA2S.js +368 -0
- package/Build/Workers/chunk-4IJFHUL6.js +414 -0
- package/Build/Workers/chunk-4K3V5CGW.js +454 -0
- package/Build/Workers/chunk-4M4QL6KJ.js +305 -0
- package/Build/Workers/chunk-4YNRIEQ6.js +288 -0
- package/Build/Workers/chunk-56CVDPH5.js +352 -0
- package/Build/Workers/chunk-5CTAAPXH.js +1483 -0
- package/Build/Workers/chunk-5ISZ6NJD.js +102 -0
- package/Build/Workers/chunk-5SDHYIOS.js +56 -0
- package/Build/Workers/chunk-66TGUMCU.js +2719 -0
- package/Build/Workers/chunk-6EJMTDQJ.js +163 -0
- package/Build/Workers/chunk-6VWXYSMH.js +959 -0
- package/Build/Workers/chunk-6VZ7VB2Q.js +241 -0
- package/Build/Workers/chunk-7AMRE57Q.js +301 -0
- package/Build/Workers/chunk-7DH6C33H.js +398 -0
- package/Build/Workers/chunk-7VUS3FVE.js +38 -0
- package/Build/Workers/chunk-7Y3ZA6H3.js +198 -0
- package/Build/Workers/chunk-A6BMHZNA.js +38 -0
- package/Build/Workers/chunk-A7XY2MN7.js +171 -0
- package/Build/Workers/chunk-AC7ND63S.js +57 -0
- package/Build/Workers/chunk-AHCZ757M.js +9230 -0
- package/Build/Workers/chunk-ANOA7E7F.js +56 -0
- package/Build/Workers/chunk-AYO5HHV6.js +789 -0
- package/Build/Workers/chunk-BE2N56VZ.js +1344 -0
- package/Build/Workers/chunk-BR3BPM64.js +9230 -0
- package/Build/Workers/chunk-BVMRWGOK.js +455 -0
- package/Build/Workers/chunk-BXEL2NX7.js +455 -0
- package/Build/Workers/chunk-C5BO2JCG.js +278 -0
- package/Build/Workers/chunk-CIRQNZVR.js +301 -0
- package/Build/Workers/chunk-CM67CQME.js +305 -0
- package/Build/Workers/chunk-D3QIW4DH.js +630 -0
- package/Build/Workers/chunk-E5W7QIGZ.js +511 -0
- package/Build/Workers/chunk-E6CYGUJI.js +1054 -0
- package/Build/Workers/chunk-EIZ23IOX.js +414 -0
- package/Build/Workers/chunk-EIZJUMQY.js +101 -0
- package/Build/Workers/chunk-EXTMZJXB.js +82 -0
- package/Build/Workers/chunk-EYOOSIBW.js +682 -0
- package/Build/Workers/chunk-F37WADVC.js +1054 -0
- package/Build/Workers/chunk-FIWPJFHX.js +101 -0
- package/Build/Workers/chunk-FM32TNGT.js +198 -0
- package/Build/Workers/chunk-FOMYIEIB.js +476 -0
- package/Build/Workers/chunk-FWYDLSVQ.js +97 -0
- package/Build/Workers/chunk-HGZR6CZF.js +1067 -0
- package/Build/Workers/chunk-HIXHDABG.js +288 -0
- package/Build/Workers/chunk-HMCCZZWE.js +97 -0
- package/Build/Workers/chunk-HW54WHGM.js +2719 -0
- package/Build/Workers/chunk-IHYAI7GF.js +973 -0
- package/Build/Workers/chunk-INLQ7LVK.js +837 -0
- package/Build/Workers/chunk-IQMESTCB.js +124 -0
- package/Build/Workers/chunk-J4PISUNT.js +2342 -0
- package/Build/Workers/chunk-JSWU557I.js +693 -0
- package/Build/Workers/chunk-KHONDSQ7.js +693 -0
- package/Build/Workers/chunk-KLUL2SOE.js +352 -0
- package/Build/Workers/chunk-KMBLKQCC.js +1992 -0
- package/Build/Workers/chunk-KOTWWQN7.js +171 -0
- package/Build/Workers/chunk-KWV6ZTF4.js +163 -0
- package/Build/Workers/chunk-LSEFPQHG.js +476 -0
- package/Build/Workers/chunk-M66X4O24.js +44 -0
- package/Build/Workers/chunk-M6IXKBC7.js +1992 -0
- package/Build/Workers/chunk-MFUC3D5C.js +162 -0
- package/Build/Workers/chunk-MRMNELAH.js +82 -0
- package/Build/Workers/chunk-N3NUA5H2.js +3792 -0
- package/Build/Workers/chunk-NFB2NXJN.js +138 -0
- package/Build/Workers/chunk-NQAXBK4K.js +789 -0
- package/Build/Workers/chunk-NUGQWV6S.js +352 -0
- package/Build/Workers/chunk-O7S7WL7K.js +278 -0
- package/Build/Workers/chunk-ODZYB26X.js +1287 -0
- package/Build/Workers/chunk-OEHJY463.js +3201 -0
- package/Build/Workers/chunk-OMMRNMXF.js +44 -0
- package/Build/Workers/chunk-OZ3CQDO3.js +138 -0
- package/Build/Workers/chunk-PNXBG64I.js +219 -0
- package/Build/Workers/chunk-PYR35GK4.js +973 -0
- package/Build/Workers/chunk-Q4CXGW74.js +57 -0
- package/Build/Workers/chunk-QGISLKCW.js +147 -0
- package/Build/Workers/chunk-QQHVOJW6.js +497 -0
- package/Build/Workers/chunk-QWCMMRJW.js +58 -0
- package/Build/Workers/chunk-RDEZCHF4.js +398 -0
- package/Build/Workers/chunk-SJTE7FVN.js +778 -0
- package/Build/Workers/chunk-SM5T67LR.js +162 -0
- package/Build/Workers/chunk-T27NNXEU.js +58 -0
- package/Build/Workers/chunk-T4J5BWUO.js +511 -0
- package/Build/Workers/chunk-T6JS4BRN.js +140 -0
- package/Build/Workers/chunk-UH6DUQBW.js +140 -0
- package/Build/Workers/chunk-UJAH6XKF.js +73 -0
- package/Build/Workers/chunk-UKSTJ2PH.js +454 -0
- package/Build/Workers/chunk-UQCDCCZ7.js +368 -0
- package/Build/Workers/chunk-UXIFNEA3.js +1287 -0
- package/Build/Workers/chunk-UXJ6J5L7.js +56 -0
- package/Build/Workers/chunk-V4VUAZXI.js +1800 -0
- package/Build/Workers/chunk-VQH2YXO2.js +497 -0
- package/Build/Workers/chunk-VXKCLSE4.js +241 -0
- package/Build/Workers/chunk-W3U6YBEI.js +280 -0
- package/Build/Workers/chunk-W75ZVFKP.js +778 -0
- package/Build/Workers/chunk-WCDFJYFB.js +1344 -0
- package/Build/Workers/chunk-WME5M6W3.js +630 -0
- package/Build/Workers/chunk-XDQBQB64.js +1067 -0
- package/Build/Workers/chunk-Y6HOIWE5.js +959 -0
- package/Build/Workers/chunk-YEMC2ZOR.js +147 -0
- package/Build/Workers/chunk-YWNF3TPE.js +682 -0
- package/Build/Workers/chunk-Z55VGWJP.js +280 -0
- package/Build/Workers/chunk-Z5YWP24C.js +124 -0
- package/Build/Workers/chunk-ZHXCWUJB.js +387 -0
- package/Build/Workers/chunk-ZIMPUF2I.js +102 -0
- package/Build/Workers/chunk-ZKDWYQKC.js +3201 -0
- package/Build/Workers/combineGeometry.js +24 -22
- package/Build/Workers/createBoxGeometry.js +18 -16
- package/Build/Workers/createBoxOutlineGeometry.js +23 -25
- package/Build/Workers/createCircleGeometry.js +29 -27
- package/Build/Workers/createCircleOutlineGeometry.js +22 -20
- package/Build/Workers/createCoplanarPolygonGeometry.js +43 -43
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +37 -35
- package/Build/Workers/createCorridorGeometry.js +46 -49
- package/Build/Workers/createCorridorOutlineGeometry.js +40 -43
- package/Build/Workers/createCylinderGeometry.js +20 -18
- package/Build/Workers/createCylinderOutlineGeometry.js +27 -25
- package/Build/Workers/createEllipseGeometry.js +28 -25
- package/Build/Workers/createEllipseOutlineGeometry.js +21 -18
- package/Build/Workers/createEllipsoidGeometry.js +19 -17
- package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -16
- package/Build/Workers/createFrustumGeometry.js +18 -16
- package/Build/Workers/createFrustumOutlineGeometry.js +21 -21
- package/Build/Workers/createGeometry.js +31 -26
- package/Build/Workers/createGroundPolylineGeometry.js +188 -135
- package/Build/Workers/createPlaneGeometry.js +22 -21
- package/Build/Workers/createPlaneOutlineGeometry.js +15 -13
- package/Build/Workers/createPolygonGeometry.js +51 -52
- package/Build/Workers/createPolygonOutlineGeometry.js +43 -44
- package/Build/Workers/createPolylineGeometry.js +37 -40
- package/Build/Workers/createPolylineVolumeGeometry.js +41 -44
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +36 -39
- package/Build/Workers/createRectangleGeometry.js +47 -53
- package/Build/Workers/createRectangleOutlineGeometry.js +32 -33
- package/Build/Workers/createSimplePolylineGeometry.js +33 -34
- package/Build/Workers/createSphereGeometry.js +20 -20
- package/Build/Workers/createSphereOutlineGeometry.js +19 -19
- package/Build/Workers/createTaskProcessorWorker.js +3 -3
- package/Build/Workers/createVectorTileClampedPolylines.js +16 -14
- package/Build/Workers/createVectorTileGeometries.js +24 -22
- package/Build/Workers/createVectorTilePoints.js +15 -13
- package/Build/Workers/createVectorTilePolygons.js +24 -21
- package/Build/Workers/createVectorTilePolylines.js +16 -14
- package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +25 -25
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +29 -27
- package/Build/Workers/createVerticesFromHeightmap.js +42 -63
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +26 -280
- package/Build/Workers/createWallGeometry.js +35 -36
- package/Build/Workers/createWallOutlineGeometry.js +33 -34
- package/Build/Workers/decodeDraco.js +10 -11
- package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
- package/Build/Workers/decodeI3S.js +16 -20
- package/Build/Workers/gaussianSplatSorter.js +4 -4
- package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
- package/Build/Workers/incrementallyBuildTerrainPicker.js +20 -12
- package/Build/Workers/transcodeKTX2.js +42 -14
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +24 -21
- package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +25 -25
- package/Source/Shaders/BillboardCollectionFS.js +85 -81
- package/Source/Shaders/BillboardCollectionVS.js +60 -118
- package/Source/Shaders/Builtin/Constants/passCesium3DTile.js +1 -1
- package/Source/Shaders/Builtin/Constants/passCesium3DTileClassification.js +1 -1
- package/Source/Shaders/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.js +1 -1
- package/Source/Shaders/Builtin/Constants/passCesium3DTileEdges.js +12 -0
- package/Source/Shaders/Builtin/Constants/passCesium3DTileEdgesDirect.js +11 -0
- package/Source/Shaders/Builtin/Constants/passGaussianSplats.js +11 -0
- package/Source/Shaders/Builtin/Constants/passOpaque.js +1 -1
- package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
- package/Source/Shaders/Builtin/Constants/passTranslucent.js +1 -1
- package/Source/Shaders/Builtin/Constants/passVoxels.js +1 -1
- package/Source/Shaders/Builtin/CzmBuiltins.js +12 -0
- package/Source/Shaders/Builtin/Functions/columbusViewMorph.js +8 -1
- package/Source/Shaders/Builtin/Functions/computeTextureTransform.js +25 -0
- package/Source/Shaders/Builtin/Functions/decodeRGB8.js +24 -0
- package/Source/Shaders/Builtin/Functions/modelToWindowCoordinates.js +2 -1
- package/Source/Shaders/Builtin/Functions/unpackTexture.js +37 -0
- package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js +0 -1
- package/Source/Shaders/EllipsoidVS.js +4 -4
- package/Source/Shaders/FXAA3_11.js +2 -0
- package/Source/Shaders/GlobeFS.js +22 -0
- package/Source/Shaders/GlobeVS.js +3 -2
- package/Source/Shaders/Model/MaterialStageFS.js +50 -20
- package/Source/Shaders/Model/MetadataStageFS.js +2 -1
- package/Source/Shaders/Model/MetadataStageVS.js +2 -1
- package/Source/Shaders/Model/ModelFS.js +32 -2
- package/Source/Shaders/Model/ModelVS.js +15 -1
- package/Source/Shaders/Model/PointCloudStylingStageVS.js +2 -1
- package/Source/Shaders/Model/PrimitiveOutlineStageFS.js +0 -1
- package/Source/Shaders/PointPrimitiveCollectionVS.js +8 -39
- package/Source/Shaders/PolygonSignedDistanceFS.js +64 -33
- package/Source/Shaders/PolylineCommon.js +1 -1
- package/Source/Shaders/ShadowVolumeAppearanceFS.js +7 -15
- package/Source/Shaders/SkyAtmosphereVS.js +2 -1
- package/Source/Shaders/Voxels/IntersectBox.js +20 -33
- package/Source/Shaders/Voxels/IntersectCylinder.js +28 -32
- package/Source/Shaders/Voxels/IntersectDepth.js +10 -6
- package/Source/Shaders/Voxels/IntersectEllipsoid.js +12 -20
- package/Source/Shaders/Voxels/IntersectLongitude.js +21 -9
- package/Source/Shaders/Voxels/Intersection.js +3 -5
- package/Source/Shaders/Voxels/IntersectionUtils.js +2 -1
- package/Source/Shaders/Voxels/Megatexture.js +15 -83
- package/Source/Shaders/Voxels/Octree.js +53 -61
- package/Source/Shaders/Voxels/VoxelFS.js +67 -52
- package/Source/Shaders/Voxels/VoxelUtils.js +0 -19
- package/index.js +346 -261
- package/package.json +1 -1
- package/Source/Shaders/Voxels/IntersectClippingPlanes.js +0 -80
- package/Source/Shaders/Voxels/convertUvToBox.js +0 -46
- package/Source/Shaders/Voxels/convertUvToCylinder.js +0 -101
- package/Source/Shaders/Voxels/convertUvToEllipsoid.js +0 -141
|
@@ -0,0 +1,3201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Cesium - https://github.com/CesiumGS/cesium
|
|
4
|
+
* Version 0.1.3
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2011-2022 Cesium Contributors
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*
|
|
20
|
+
* Columbus View (Pat. Pend.)
|
|
21
|
+
*
|
|
22
|
+
* Portions licensed separately.
|
|
23
|
+
* See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
RuntimeError_default
|
|
28
|
+
} from "./chunk-QWCMMRJW.js";
|
|
29
|
+
import {
|
|
30
|
+
Cartesian3_default,
|
|
31
|
+
Frozen_default,
|
|
32
|
+
Matrix3_default
|
|
33
|
+
} from "./chunk-45VV4SBO.js";
|
|
34
|
+
import {
|
|
35
|
+
Math_default
|
|
36
|
+
} from "./chunk-QQHVOJW6.js";
|
|
37
|
+
import {
|
|
38
|
+
Check_default,
|
|
39
|
+
DeveloperError_default
|
|
40
|
+
} from "./chunk-6EJMTDQJ.js";
|
|
41
|
+
import {
|
|
42
|
+
defined_default
|
|
43
|
+
} from "./chunk-EXTMZJXB.js";
|
|
44
|
+
|
|
45
|
+
// packages/engine/Source/Core/Cartesian4.js
|
|
46
|
+
var Cartesian4 = class _Cartesian4 {
|
|
47
|
+
/**
|
|
48
|
+
* @param {number} [x=0.0] The X component.
|
|
49
|
+
* @param {number} [y=0.0] The Y component.
|
|
50
|
+
* @param {number} [z=0.0] The Z component.
|
|
51
|
+
* @param {number} [w=0.0] The W component.
|
|
52
|
+
*/
|
|
53
|
+
constructor(x, y, z, w) {
|
|
54
|
+
this.x = x ?? 0;
|
|
55
|
+
this.y = y ?? 0;
|
|
56
|
+
this.z = z ?? 0;
|
|
57
|
+
this.w = w ?? 0;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a Cartesian4 instance from x, y, z and w coordinates.
|
|
61
|
+
*
|
|
62
|
+
* @param {number} x The x coordinate.
|
|
63
|
+
* @param {number} y The y coordinate.
|
|
64
|
+
* @param {number} z The z coordinate.
|
|
65
|
+
* @param {number} w The w coordinate.
|
|
66
|
+
* @param {Cartesian4} [result] The object onto which to store the result.
|
|
67
|
+
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
|
|
68
|
+
*/
|
|
69
|
+
static fromElements(x, y, z, w, result) {
|
|
70
|
+
if (!defined_default(result)) {
|
|
71
|
+
return new _Cartesian4(x, y, z, w);
|
|
72
|
+
}
|
|
73
|
+
result.x = x;
|
|
74
|
+
result.y = y;
|
|
75
|
+
result.z = z;
|
|
76
|
+
result.w = w;
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates a Cartesian4 instance from a {@link Color}. <code>red</code>, <code>green</code>, <code>blue</code>,
|
|
81
|
+
* and <code>alpha</code> map to <code>x</code>, <code>y</code>, <code>z</code>, and <code>w</code>, respectively.
|
|
82
|
+
*
|
|
83
|
+
* @param {Color} color The source color.
|
|
84
|
+
* @param {Cartesian4} [result] The object onto which to store the result.
|
|
85
|
+
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
|
|
86
|
+
*/
|
|
87
|
+
static fromColor(color, result) {
|
|
88
|
+
Check_default.typeOf.object("color", color);
|
|
89
|
+
if (!defined_default(result)) {
|
|
90
|
+
return new _Cartesian4(color.red, color.green, color.blue, color.alpha);
|
|
91
|
+
}
|
|
92
|
+
result.x = color.red;
|
|
93
|
+
result.y = color.green;
|
|
94
|
+
result.z = color.blue;
|
|
95
|
+
result.w = color.alpha;
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Duplicates a Cartesian4 instance.
|
|
100
|
+
*
|
|
101
|
+
* @param {Cartesian4} cartesian The Cartesian to duplicate.
|
|
102
|
+
* @param {Cartesian4} [result] The object onto which to store the result.
|
|
103
|
+
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided. (Returns undefined if cartesian is undefined)
|
|
104
|
+
*/
|
|
105
|
+
static clone(cartesian, result) {
|
|
106
|
+
if (!defined_default(cartesian)) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
if (!defined_default(result)) {
|
|
110
|
+
return new _Cartesian4(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
|
|
111
|
+
}
|
|
112
|
+
result.x = cartesian.x;
|
|
113
|
+
result.y = cartesian.y;
|
|
114
|
+
result.z = cartesian.z;
|
|
115
|
+
result.w = cartesian.w;
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Stores the provided instance into the provided array.
|
|
120
|
+
*
|
|
121
|
+
* @param {Cartesian4} value The value to pack.
|
|
122
|
+
* @param {number[]} array The array to pack into.
|
|
123
|
+
* @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
|
|
124
|
+
*
|
|
125
|
+
* @returns {number[]} The array that was packed into
|
|
126
|
+
*/
|
|
127
|
+
static pack(value, array, startingIndex) {
|
|
128
|
+
Check_default.typeOf.object("value", value);
|
|
129
|
+
Check_default.defined("array", array);
|
|
130
|
+
startingIndex = startingIndex ?? 0;
|
|
131
|
+
array[startingIndex++] = value.x;
|
|
132
|
+
array[startingIndex++] = value.y;
|
|
133
|
+
array[startingIndex++] = value.z;
|
|
134
|
+
array[startingIndex] = value.w;
|
|
135
|
+
return array;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Retrieves an instance from a packed array.
|
|
139
|
+
*
|
|
140
|
+
* @param {number[]} array The packed array.
|
|
141
|
+
* @param {number} [startingIndex=0] The starting index of the element to be unpacked.
|
|
142
|
+
* @param {Cartesian4} [result] The object into which to store the result.
|
|
143
|
+
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
|
|
144
|
+
*/
|
|
145
|
+
static unpack(array, startingIndex, result) {
|
|
146
|
+
Check_default.defined("array", array);
|
|
147
|
+
startingIndex = startingIndex ?? 0;
|
|
148
|
+
if (!defined_default(result)) {
|
|
149
|
+
result = new _Cartesian4();
|
|
150
|
+
}
|
|
151
|
+
result.x = array[startingIndex++];
|
|
152
|
+
result.y = array[startingIndex++];
|
|
153
|
+
result.z = array[startingIndex++];
|
|
154
|
+
result.w = array[startingIndex];
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Flattens an array of Cartesian4s into an array of components.
|
|
159
|
+
*
|
|
160
|
+
* @param {Cartesian4[]} array The array of cartesians to pack.
|
|
161
|
+
* @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 4 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 4) elements.
|
|
162
|
+
* @returns {number[]} The packed array.
|
|
163
|
+
*/
|
|
164
|
+
static packArray(array, result) {
|
|
165
|
+
Check_default.defined("array", array);
|
|
166
|
+
const length = array.length;
|
|
167
|
+
const resultLength = length * 4;
|
|
168
|
+
if (!defined_default(result)) {
|
|
169
|
+
result = new Array(resultLength);
|
|
170
|
+
} else if (!Array.isArray(result) && result.length !== resultLength) {
|
|
171
|
+
throw new DeveloperError_default(
|
|
172
|
+
"If result is a typed array, it must have exactly array.length * 4 elements"
|
|
173
|
+
);
|
|
174
|
+
} else if (result.length !== resultLength) {
|
|
175
|
+
result.length = resultLength;
|
|
176
|
+
}
|
|
177
|
+
for (let i = 0; i < length; ++i) {
|
|
178
|
+
_Cartesian4.pack(array[i], result, i * 4);
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Unpacks an array of cartesian components into an array of Cartesian4s.
|
|
184
|
+
*
|
|
185
|
+
* @param {number[]} array The array of components to unpack.
|
|
186
|
+
* @param {Cartesian4[]} [result] The array onto which to store the result.
|
|
187
|
+
* @returns {Cartesian4[]} The unpacked array.
|
|
188
|
+
*/
|
|
189
|
+
static unpackArray(array, result) {
|
|
190
|
+
Check_default.defined("array", array);
|
|
191
|
+
Check_default.typeOf.number.greaterThanOrEquals("array.length", array.length, 4);
|
|
192
|
+
if (array.length % 4 !== 0) {
|
|
193
|
+
throw new DeveloperError_default("array length must be a multiple of 4.");
|
|
194
|
+
}
|
|
195
|
+
const length = array.length;
|
|
196
|
+
if (!defined_default(result)) {
|
|
197
|
+
result = new Array(length / 4);
|
|
198
|
+
} else {
|
|
199
|
+
result.length = length / 4;
|
|
200
|
+
}
|
|
201
|
+
for (let i = 0; i < length; i += 4) {
|
|
202
|
+
const index = i / 4;
|
|
203
|
+
result[index] = _Cartesian4.unpack(array, i, result[index]);
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Computes the value of the maximum component for the supplied Cartesian.
|
|
209
|
+
*
|
|
210
|
+
* @param {Cartesian4} cartesian The cartesian to use.
|
|
211
|
+
* @returns {number} The value of the maximum component.
|
|
212
|
+
*/
|
|
213
|
+
static maximumComponent(cartesian) {
|
|
214
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
215
|
+
return Math.max(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Computes the value of the minimum component for the supplied Cartesian.
|
|
219
|
+
*
|
|
220
|
+
* @param {Cartesian4} cartesian The cartesian to use.
|
|
221
|
+
* @returns {number} The value of the minimum component.
|
|
222
|
+
*/
|
|
223
|
+
static minimumComponent(cartesian) {
|
|
224
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
225
|
+
return Math.min(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
|
|
229
|
+
*
|
|
230
|
+
* @param {Cartesian4} first A cartesian to compare.
|
|
231
|
+
* @param {Cartesian4} second A cartesian to compare.
|
|
232
|
+
* @param {Cartesian4} result The object into which to store the result.
|
|
233
|
+
* @returns {Cartesian4} A cartesian with the minimum components.
|
|
234
|
+
*/
|
|
235
|
+
static minimumByComponent(first, second, result) {
|
|
236
|
+
Check_default.typeOf.object("first", first);
|
|
237
|
+
Check_default.typeOf.object("second", second);
|
|
238
|
+
Check_default.typeOf.object("result", result);
|
|
239
|
+
result.x = Math.min(first.x, second.x);
|
|
240
|
+
result.y = Math.min(first.y, second.y);
|
|
241
|
+
result.z = Math.min(first.z, second.z);
|
|
242
|
+
result.w = Math.min(first.w, second.w);
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
|
|
247
|
+
*
|
|
248
|
+
* @param {Cartesian4} first A cartesian to compare.
|
|
249
|
+
* @param {Cartesian4} second A cartesian to compare.
|
|
250
|
+
* @param {Cartesian4} result The object into which to store the result.
|
|
251
|
+
* @returns {Cartesian4} A cartesian with the maximum components.
|
|
252
|
+
*/
|
|
253
|
+
static maximumByComponent(first, second, result) {
|
|
254
|
+
Check_default.typeOf.object("first", first);
|
|
255
|
+
Check_default.typeOf.object("second", second);
|
|
256
|
+
Check_default.typeOf.object("result", result);
|
|
257
|
+
result.x = Math.max(first.x, second.x);
|
|
258
|
+
result.y = Math.max(first.y, second.y);
|
|
259
|
+
result.z = Math.max(first.z, second.z);
|
|
260
|
+
result.w = Math.max(first.w, second.w);
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Constrain a value to lie between two values.
|
|
265
|
+
*
|
|
266
|
+
* @param {Cartesian4} value The value to clamp.
|
|
267
|
+
* @param {Cartesian4} min The minimum bound.
|
|
268
|
+
* @param {Cartesian4} max The maximum bound.
|
|
269
|
+
* @param {Cartesian4} result The object into which to store the result.
|
|
270
|
+
* @returns {Cartesian4} The clamped value such that min <= result <= max.
|
|
271
|
+
*/
|
|
272
|
+
static clamp(value, min, max, result) {
|
|
273
|
+
Check_default.typeOf.object("value", value);
|
|
274
|
+
Check_default.typeOf.object("min", min);
|
|
275
|
+
Check_default.typeOf.object("max", max);
|
|
276
|
+
Check_default.typeOf.object("result", result);
|
|
277
|
+
const x = Math_default.clamp(value.x, min.x, max.x);
|
|
278
|
+
const y = Math_default.clamp(value.y, min.y, max.y);
|
|
279
|
+
const z = Math_default.clamp(value.z, min.z, max.z);
|
|
280
|
+
const w = Math_default.clamp(value.w, min.w, max.w);
|
|
281
|
+
result.x = x;
|
|
282
|
+
result.y = y;
|
|
283
|
+
result.z = z;
|
|
284
|
+
result.w = w;
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Computes the provided Cartesian's squared magnitude.
|
|
289
|
+
*
|
|
290
|
+
* @param {Cartesian4} cartesian The Cartesian instance whose squared magnitude is to be computed.
|
|
291
|
+
* @returns {number} The squared magnitude.
|
|
292
|
+
*/
|
|
293
|
+
static magnitudeSquared(cartesian) {
|
|
294
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
295
|
+
return cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z + cartesian.w * cartesian.w;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Computes the Cartesian's magnitude (length).
|
|
299
|
+
*
|
|
300
|
+
* @param {Cartesian4} cartesian The Cartesian instance whose magnitude is to be computed.
|
|
301
|
+
* @returns {number} The magnitude.
|
|
302
|
+
*/
|
|
303
|
+
static magnitude(cartesian) {
|
|
304
|
+
return Math.sqrt(_Cartesian4.magnitudeSquared(cartesian));
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Computes the 4-space distance between two points.
|
|
308
|
+
*
|
|
309
|
+
* @param {Cartesian4} left The first point to compute the distance from.
|
|
310
|
+
* @param {Cartesian4} right The second point to compute the distance to.
|
|
311
|
+
* @returns {number} The distance between two points.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* // Returns 1.0
|
|
315
|
+
* const d = Cesium.Cartesian4.distance(
|
|
316
|
+
* new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
|
|
317
|
+
* new Cesium.Cartesian4(2.0, 0.0, 0.0, 0.0));
|
|
318
|
+
*/
|
|
319
|
+
static distance(left, right) {
|
|
320
|
+
Check_default.typeOf.object("left", left);
|
|
321
|
+
Check_default.typeOf.object("right", right);
|
|
322
|
+
_Cartesian4.subtract(left, right, distanceScratch);
|
|
323
|
+
return _Cartesian4.magnitude(distanceScratch);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Computes the squared distance between two points. Comparing squared distances
|
|
327
|
+
* using this function is more efficient than comparing distances using {@link Cartesian4#distance}.
|
|
328
|
+
*
|
|
329
|
+
* @param {Cartesian4} left The first point to compute the distance from.
|
|
330
|
+
* @param {Cartesian4} right The second point to compute the distance to.
|
|
331
|
+
* @returns {number} The distance between two points.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* // Returns 4.0, not 2.0
|
|
335
|
+
* const d = Cesium.Cartesian4.distance(
|
|
336
|
+
* new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
|
|
337
|
+
* new Cesium.Cartesian4(3.0, 0.0, 0.0, 0.0));
|
|
338
|
+
*/
|
|
339
|
+
static distanceSquared(left, right) {
|
|
340
|
+
Check_default.typeOf.object("left", left);
|
|
341
|
+
Check_default.typeOf.object("right", right);
|
|
342
|
+
_Cartesian4.subtract(left, right, distanceScratch);
|
|
343
|
+
return _Cartesian4.magnitudeSquared(distanceScratch);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Computes the normalized form of the supplied Cartesian.
|
|
347
|
+
*
|
|
348
|
+
* @param {Cartesian4} cartesian The Cartesian to be normalized.
|
|
349
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
350
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
351
|
+
*/
|
|
352
|
+
static normalize(cartesian, result) {
|
|
353
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
354
|
+
Check_default.typeOf.object("result", result);
|
|
355
|
+
const magnitude = _Cartesian4.magnitude(cartesian);
|
|
356
|
+
result.x = cartesian.x / magnitude;
|
|
357
|
+
result.y = cartesian.y / magnitude;
|
|
358
|
+
result.z = cartesian.z / magnitude;
|
|
359
|
+
result.w = cartesian.w / magnitude;
|
|
360
|
+
if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z) || isNaN(result.w)) {
|
|
361
|
+
throw new DeveloperError_default("normalized result is not a number");
|
|
362
|
+
}
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Computes the dot (scalar) product of two Cartesians.
|
|
367
|
+
*
|
|
368
|
+
* @param {Cartesian4} left The first Cartesian.
|
|
369
|
+
* @param {Cartesian4} right The second Cartesian.
|
|
370
|
+
* @returns {number} The dot product.
|
|
371
|
+
*/
|
|
372
|
+
static dot(left, right) {
|
|
373
|
+
Check_default.typeOf.object("left", left);
|
|
374
|
+
Check_default.typeOf.object("right", right);
|
|
375
|
+
return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Computes the componentwise product of two Cartesians.
|
|
379
|
+
*
|
|
380
|
+
* @param {Cartesian4} left The first Cartesian.
|
|
381
|
+
* @param {Cartesian4} right The second Cartesian.
|
|
382
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
383
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
384
|
+
*/
|
|
385
|
+
static multiplyComponents(left, right, result) {
|
|
386
|
+
Check_default.typeOf.object("left", left);
|
|
387
|
+
Check_default.typeOf.object("right", right);
|
|
388
|
+
Check_default.typeOf.object("result", result);
|
|
389
|
+
result.x = left.x * right.x;
|
|
390
|
+
result.y = left.y * right.y;
|
|
391
|
+
result.z = left.z * right.z;
|
|
392
|
+
result.w = left.w * right.w;
|
|
393
|
+
return result;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Computes the componentwise quotient of two Cartesians.
|
|
397
|
+
*
|
|
398
|
+
* @param {Cartesian4} left The first Cartesian.
|
|
399
|
+
* @param {Cartesian4} right The second Cartesian.
|
|
400
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
401
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
402
|
+
*/
|
|
403
|
+
static divideComponents(left, right, result) {
|
|
404
|
+
Check_default.typeOf.object("left", left);
|
|
405
|
+
Check_default.typeOf.object("right", right);
|
|
406
|
+
Check_default.typeOf.object("result", result);
|
|
407
|
+
result.x = left.x / right.x;
|
|
408
|
+
result.y = left.y / right.y;
|
|
409
|
+
result.z = left.z / right.z;
|
|
410
|
+
result.w = left.w / right.w;
|
|
411
|
+
return result;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Computes the componentwise sum of two Cartesians.
|
|
415
|
+
*
|
|
416
|
+
* @param {Cartesian4} left The first Cartesian.
|
|
417
|
+
* @param {Cartesian4} right The second Cartesian.
|
|
418
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
419
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
420
|
+
*/
|
|
421
|
+
static add(left, right, result) {
|
|
422
|
+
Check_default.typeOf.object("left", left);
|
|
423
|
+
Check_default.typeOf.object("right", right);
|
|
424
|
+
Check_default.typeOf.object("result", result);
|
|
425
|
+
result.x = left.x + right.x;
|
|
426
|
+
result.y = left.y + right.y;
|
|
427
|
+
result.z = left.z + right.z;
|
|
428
|
+
result.w = left.w + right.w;
|
|
429
|
+
return result;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Computes the componentwise difference of two Cartesians.
|
|
433
|
+
*
|
|
434
|
+
* @param {Cartesian4} left The first Cartesian.
|
|
435
|
+
* @param {Cartesian4} right The second Cartesian.
|
|
436
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
437
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
438
|
+
*/
|
|
439
|
+
static subtract(left, right, result) {
|
|
440
|
+
Check_default.typeOf.object("left", left);
|
|
441
|
+
Check_default.typeOf.object("right", right);
|
|
442
|
+
Check_default.typeOf.object("result", result);
|
|
443
|
+
result.x = left.x - right.x;
|
|
444
|
+
result.y = left.y - right.y;
|
|
445
|
+
result.z = left.z - right.z;
|
|
446
|
+
result.w = left.w - right.w;
|
|
447
|
+
return result;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Multiplies the provided Cartesian componentwise by the provided scalar.
|
|
451
|
+
*
|
|
452
|
+
* @param {Cartesian4} cartesian The Cartesian to be scaled.
|
|
453
|
+
* @param {number} scalar The scalar to multiply with.
|
|
454
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
455
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
456
|
+
*/
|
|
457
|
+
static multiplyByScalar(cartesian, scalar, result) {
|
|
458
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
459
|
+
Check_default.typeOf.number("scalar", scalar);
|
|
460
|
+
Check_default.typeOf.object("result", result);
|
|
461
|
+
result.x = cartesian.x * scalar;
|
|
462
|
+
result.y = cartesian.y * scalar;
|
|
463
|
+
result.z = cartesian.z * scalar;
|
|
464
|
+
result.w = cartesian.w * scalar;
|
|
465
|
+
return result;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Divides the provided Cartesian componentwise by the provided scalar.
|
|
469
|
+
*
|
|
470
|
+
* @param {Cartesian4} cartesian The Cartesian to be divided.
|
|
471
|
+
* @param {number} scalar The scalar to divide by.
|
|
472
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
473
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
474
|
+
*/
|
|
475
|
+
static divideByScalar(cartesian, scalar, result) {
|
|
476
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
477
|
+
Check_default.typeOf.number("scalar", scalar);
|
|
478
|
+
Check_default.typeOf.object("result", result);
|
|
479
|
+
result.x = cartesian.x / scalar;
|
|
480
|
+
result.y = cartesian.y / scalar;
|
|
481
|
+
result.z = cartesian.z / scalar;
|
|
482
|
+
result.w = cartesian.w / scalar;
|
|
483
|
+
return result;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Negates the provided Cartesian.
|
|
487
|
+
*
|
|
488
|
+
* @param {Cartesian4} cartesian The Cartesian to be negated.
|
|
489
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
490
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
491
|
+
*/
|
|
492
|
+
static negate(cartesian, result) {
|
|
493
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
494
|
+
Check_default.typeOf.object("result", result);
|
|
495
|
+
result.x = -cartesian.x;
|
|
496
|
+
result.y = -cartesian.y;
|
|
497
|
+
result.z = -cartesian.z;
|
|
498
|
+
result.w = -cartesian.w;
|
|
499
|
+
return result;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Computes the absolute value of the provided Cartesian.
|
|
503
|
+
*
|
|
504
|
+
* @param {Cartesian4} cartesian The Cartesian whose absolute value is to be computed.
|
|
505
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
506
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
507
|
+
*/
|
|
508
|
+
static abs(cartesian, result) {
|
|
509
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
510
|
+
Check_default.typeOf.object("result", result);
|
|
511
|
+
result.x = Math.abs(cartesian.x);
|
|
512
|
+
result.y = Math.abs(cartesian.y);
|
|
513
|
+
result.z = Math.abs(cartesian.z);
|
|
514
|
+
result.w = Math.abs(cartesian.w);
|
|
515
|
+
return result;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Computes the linear interpolation or extrapolation at t using the provided cartesians.
|
|
519
|
+
*
|
|
520
|
+
* @param {Cartesian4} start The value corresponding to t at 0.0.
|
|
521
|
+
* @param {Cartesian4}end The value corresponding to t at 1.0.
|
|
522
|
+
* @param {number} t The point along t at which to interpolate.
|
|
523
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
524
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
525
|
+
*/
|
|
526
|
+
static lerp(start, end, t, result) {
|
|
527
|
+
Check_default.typeOf.object("start", start);
|
|
528
|
+
Check_default.typeOf.object("end", end);
|
|
529
|
+
Check_default.typeOf.number("t", t);
|
|
530
|
+
Check_default.typeOf.object("result", result);
|
|
531
|
+
_Cartesian4.multiplyByScalar(end, t, lerpScratch);
|
|
532
|
+
result = _Cartesian4.multiplyByScalar(start, 1 - t, result);
|
|
533
|
+
return _Cartesian4.add(lerpScratch, result, result);
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Returns the axis that is most orthogonal to the provided Cartesian.
|
|
537
|
+
*
|
|
538
|
+
* @param {Cartesian4} cartesian The Cartesian on which to find the most orthogonal axis.
|
|
539
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
540
|
+
* @returns {Cartesian4} The most orthogonal axis.
|
|
541
|
+
*/
|
|
542
|
+
static mostOrthogonalAxis(cartesian, result) {
|
|
543
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
544
|
+
Check_default.typeOf.object("result", result);
|
|
545
|
+
const f = _Cartesian4.normalize(cartesian, mostOrthogonalAxisScratch);
|
|
546
|
+
_Cartesian4.abs(f, f);
|
|
547
|
+
if (f.x <= f.y) {
|
|
548
|
+
if (f.x <= f.z) {
|
|
549
|
+
if (f.x <= f.w) {
|
|
550
|
+
result = _Cartesian4.clone(_Cartesian4.UNIT_X, result);
|
|
551
|
+
} else {
|
|
552
|
+
result = _Cartesian4.clone(_Cartesian4.UNIT_W, result);
|
|
553
|
+
}
|
|
554
|
+
} else if (f.z <= f.w) {
|
|
555
|
+
result = _Cartesian4.clone(_Cartesian4.UNIT_Z, result);
|
|
556
|
+
} else {
|
|
557
|
+
result = _Cartesian4.clone(_Cartesian4.UNIT_W, result);
|
|
558
|
+
}
|
|
559
|
+
} else if (f.y <= f.z) {
|
|
560
|
+
if (f.y <= f.w) {
|
|
561
|
+
result = _Cartesian4.clone(_Cartesian4.UNIT_Y, result);
|
|
562
|
+
} else {
|
|
563
|
+
result = _Cartesian4.clone(_Cartesian4.UNIT_W, result);
|
|
564
|
+
}
|
|
565
|
+
} else if (f.z <= f.w) {
|
|
566
|
+
result = _Cartesian4.clone(_Cartesian4.UNIT_Z, result);
|
|
567
|
+
} else {
|
|
568
|
+
result = _Cartesian4.clone(_Cartesian4.UNIT_W, result);
|
|
569
|
+
}
|
|
570
|
+
return result;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Compares the provided Cartesians componentwise and returns
|
|
574
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
575
|
+
*
|
|
576
|
+
* @param {Cartesian4} [left] The first Cartesian.
|
|
577
|
+
* @param {Cartesian4} [right] The second Cartesian.
|
|
578
|
+
* @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
|
|
579
|
+
*/
|
|
580
|
+
static equals(left, right) {
|
|
581
|
+
return left === right || defined_default(left) && defined_default(right) && left.x === right.x && left.y === right.y && left.z === right.z && left.w === right.w;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* @param {Cartesian4} cartesian
|
|
585
|
+
* @param {number[]} array
|
|
586
|
+
* @param {number} offset
|
|
587
|
+
* @ignore
|
|
588
|
+
*/
|
|
589
|
+
static equalsArray(cartesian, array, offset) {
|
|
590
|
+
return cartesian.x === array[offset] && cartesian.y === array[offset + 1] && cartesian.z === array[offset + 2] && cartesian.w === array[offset + 3];
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Compares the provided Cartesians componentwise and returns
|
|
594
|
+
* <code>true</code> if they pass an absolute or relative tolerance test,
|
|
595
|
+
* <code>false</code> otherwise.
|
|
596
|
+
*
|
|
597
|
+
* @param {Cartesian4} [left] The first Cartesian.
|
|
598
|
+
* @param {Cartesian4} [right] The second Cartesian.
|
|
599
|
+
* @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
|
|
600
|
+
* @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
|
|
601
|
+
* @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
|
|
602
|
+
*/
|
|
603
|
+
static equalsEpsilon(left, right, relativeEpsilon, absoluteEpsilon) {
|
|
604
|
+
return left === right || defined_default(left) && defined_default(right) && Math_default.equalsEpsilon(
|
|
605
|
+
left.x,
|
|
606
|
+
right.x,
|
|
607
|
+
relativeEpsilon,
|
|
608
|
+
absoluteEpsilon
|
|
609
|
+
) && Math_default.equalsEpsilon(
|
|
610
|
+
left.y,
|
|
611
|
+
right.y,
|
|
612
|
+
relativeEpsilon,
|
|
613
|
+
absoluteEpsilon
|
|
614
|
+
) && Math_default.equalsEpsilon(
|
|
615
|
+
left.z,
|
|
616
|
+
right.z,
|
|
617
|
+
relativeEpsilon,
|
|
618
|
+
absoluteEpsilon
|
|
619
|
+
) && Math_default.equalsEpsilon(
|
|
620
|
+
left.w,
|
|
621
|
+
right.w,
|
|
622
|
+
relativeEpsilon,
|
|
623
|
+
absoluteEpsilon
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Duplicates this Cartesian4 instance.
|
|
628
|
+
*
|
|
629
|
+
* @param {Cartesian4} [result] The object onto which to store the result.
|
|
630
|
+
* @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
|
|
631
|
+
*/
|
|
632
|
+
clone(result) {
|
|
633
|
+
return _Cartesian4.clone(this, result);
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Compares this Cartesian against the provided Cartesian componentwise and returns
|
|
637
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
638
|
+
*
|
|
639
|
+
* @param {Cartesian4} [right] The right hand side Cartesian.
|
|
640
|
+
* @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
641
|
+
*/
|
|
642
|
+
equals(right) {
|
|
643
|
+
return _Cartesian4.equals(this, right);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Compares this Cartesian against the provided Cartesian componentwise and returns
|
|
647
|
+
* <code>true</code> if they pass an absolute or relative tolerance test,
|
|
648
|
+
* <code>false</code> otherwise.
|
|
649
|
+
*
|
|
650
|
+
* @param {Cartesian4} [right] The right hand side Cartesian.
|
|
651
|
+
* @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
|
|
652
|
+
* @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
|
|
653
|
+
* @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
|
|
654
|
+
*/
|
|
655
|
+
equalsEpsilon(right, relativeEpsilon, absoluteEpsilon) {
|
|
656
|
+
return _Cartesian4.equalsEpsilon(
|
|
657
|
+
this,
|
|
658
|
+
right,
|
|
659
|
+
relativeEpsilon,
|
|
660
|
+
absoluteEpsilon
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Creates a string representing this Cartesian in the format '(x, y, z, w)'.
|
|
665
|
+
*
|
|
666
|
+
* @returns {string} A string representing the provided Cartesian in the format '(x, y, z, w)'.
|
|
667
|
+
*/
|
|
668
|
+
toString() {
|
|
669
|
+
return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Packs an arbitrary floating point value to 4 values representable using uint8.
|
|
673
|
+
*
|
|
674
|
+
* @param {number} value A floating point number.
|
|
675
|
+
* @param {Cartesian4} [result] The Cartesian4 that will contain the packed float.
|
|
676
|
+
* @returns {Cartesian4} A Cartesian4 representing the float packed to values in x, y, z, and w.
|
|
677
|
+
*/
|
|
678
|
+
static packFloat(value, result) {
|
|
679
|
+
Check_default.typeOf.number("value", value);
|
|
680
|
+
if (!defined_default(result)) {
|
|
681
|
+
result = new _Cartesian4();
|
|
682
|
+
}
|
|
683
|
+
scratchF32Array[0] = value;
|
|
684
|
+
if (littleEndian) {
|
|
685
|
+
result.x = scratchU8Array[0];
|
|
686
|
+
result.y = scratchU8Array[1];
|
|
687
|
+
result.z = scratchU8Array[2];
|
|
688
|
+
result.w = scratchU8Array[3];
|
|
689
|
+
} else {
|
|
690
|
+
result.x = scratchU8Array[3];
|
|
691
|
+
result.y = scratchU8Array[2];
|
|
692
|
+
result.z = scratchU8Array[1];
|
|
693
|
+
result.w = scratchU8Array[0];
|
|
694
|
+
}
|
|
695
|
+
return result;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Unpacks a float packed using Cartesian4.packFloat.
|
|
699
|
+
*
|
|
700
|
+
* @param {Cartesian4} packedFloat A Cartesian4 containing a float packed to 4 values representable using uint8.
|
|
701
|
+
* @returns {number} The unpacked float.
|
|
702
|
+
* @private
|
|
703
|
+
*/
|
|
704
|
+
static unpackFloat(packedFloat) {
|
|
705
|
+
Check_default.typeOf.object("packedFloat", packedFloat);
|
|
706
|
+
if (littleEndian) {
|
|
707
|
+
scratchU8Array[0] = packedFloat.x;
|
|
708
|
+
scratchU8Array[1] = packedFloat.y;
|
|
709
|
+
scratchU8Array[2] = packedFloat.z;
|
|
710
|
+
scratchU8Array[3] = packedFloat.w;
|
|
711
|
+
} else {
|
|
712
|
+
scratchU8Array[0] = packedFloat.w;
|
|
713
|
+
scratchU8Array[1] = packedFloat.z;
|
|
714
|
+
scratchU8Array[2] = packedFloat.y;
|
|
715
|
+
scratchU8Array[3] = packedFloat.x;
|
|
716
|
+
}
|
|
717
|
+
return scratchF32Array[0];
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
Cartesian4.packedLength = 4;
|
|
721
|
+
Cartesian4.fromArray = Cartesian4.unpack;
|
|
722
|
+
var distanceScratch = new Cartesian4();
|
|
723
|
+
var lerpScratch = new Cartesian4();
|
|
724
|
+
var mostOrthogonalAxisScratch = new Cartesian4();
|
|
725
|
+
Cartesian4.ZERO = Object.freeze(new Cartesian4(0, 0, 0, 0));
|
|
726
|
+
Cartesian4.ONE = Object.freeze(new Cartesian4(1, 1, 1, 1));
|
|
727
|
+
Cartesian4.UNIT_X = Object.freeze(new Cartesian4(1, 0, 0, 0));
|
|
728
|
+
Cartesian4.UNIT_Y = Object.freeze(new Cartesian4(0, 1, 0, 0));
|
|
729
|
+
Cartesian4.UNIT_Z = Object.freeze(new Cartesian4(0, 0, 1, 0));
|
|
730
|
+
Cartesian4.UNIT_W = Object.freeze(new Cartesian4(0, 0, 0, 1));
|
|
731
|
+
var scratchF32Array = new Float32Array(1);
|
|
732
|
+
var scratchU8Array = new Uint8Array(scratchF32Array.buffer);
|
|
733
|
+
var testU32 = new Uint32Array([287454020]);
|
|
734
|
+
var testU8 = new Uint8Array(testU32.buffer);
|
|
735
|
+
var littleEndian = testU8[0] === 68;
|
|
736
|
+
var Cartesian4_default = Cartesian4;
|
|
737
|
+
|
|
738
|
+
// packages/engine/Source/Core/Matrix4.js
|
|
739
|
+
var Matrix4 = class _Matrix4 {
|
|
740
|
+
/**
|
|
741
|
+
* @param {number} [column0Row0=0.0] The value for column 0, row 0.
|
|
742
|
+
* @param {number} [column1Row0=0.0] The value for column 1, row 0.
|
|
743
|
+
* @param {number} [column2Row0=0.0] The value for column 2, row 0.
|
|
744
|
+
* @param {number} [column3Row0=0.0] The value for column 3, row 0.
|
|
745
|
+
* @param {number} [column0Row1=0.0] The value for column 0, row 1.
|
|
746
|
+
* @param {number} [column1Row1=0.0] The value for column 1, row 1.
|
|
747
|
+
* @param {number} [column2Row1=0.0] The value for column 2, row 1.
|
|
748
|
+
* @param {number} [column3Row1=0.0] The value for column 3, row 1.
|
|
749
|
+
* @param {number} [column0Row2=0.0] The value for column 0, row 2.
|
|
750
|
+
* @param {number} [column1Row2=0.0] The value for column 1, row 2.
|
|
751
|
+
* @param {number} [column2Row2=0.0] The value for column 2, row 2.
|
|
752
|
+
* @param {number} [column3Row2=0.0] The value for column 3, row 2.
|
|
753
|
+
* @param {number} [column0Row3=0.0] The value for column 0, row 3.
|
|
754
|
+
* @param {number} [column1Row3=0.0] The value for column 1, row 3.
|
|
755
|
+
* @param {number} [column2Row3=0.0] The value for column 2, row 3.
|
|
756
|
+
* @param {number} [column3Row3=0.0] The value for column 3, row 3.
|
|
757
|
+
*/
|
|
758
|
+
constructor(column0Row0, column1Row0, column2Row0, column3Row0, column0Row1, column1Row1, column2Row1, column3Row1, column0Row2, column1Row2, column2Row2, column3Row2, column0Row3, column1Row3, column2Row3, column3Row3) {
|
|
759
|
+
this[0] = column0Row0 ?? 0;
|
|
760
|
+
this[1] = column0Row1 ?? 0;
|
|
761
|
+
this[2] = column0Row2 ?? 0;
|
|
762
|
+
this[3] = column0Row3 ?? 0;
|
|
763
|
+
this[4] = column1Row0 ?? 0;
|
|
764
|
+
this[5] = column1Row1 ?? 0;
|
|
765
|
+
this[6] = column1Row2 ?? 0;
|
|
766
|
+
this[7] = column1Row3 ?? 0;
|
|
767
|
+
this[8] = column2Row0 ?? 0;
|
|
768
|
+
this[9] = column2Row1 ?? 0;
|
|
769
|
+
this[10] = column2Row2 ?? 0;
|
|
770
|
+
this[11] = column2Row3 ?? 0;
|
|
771
|
+
this[12] = column3Row0 ?? 0;
|
|
772
|
+
this[13] = column3Row1 ?? 0;
|
|
773
|
+
this[14] = column3Row2 ?? 0;
|
|
774
|
+
this[15] = column3Row3 ?? 0;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Stores the provided instance into the provided array.
|
|
778
|
+
*
|
|
779
|
+
* @param {Matrix4} value The value to pack.
|
|
780
|
+
* @param {number[]} array The array to pack into.
|
|
781
|
+
* @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
|
|
782
|
+
*
|
|
783
|
+
* @returns {number[]} The array that was packed into
|
|
784
|
+
*/
|
|
785
|
+
static pack(value, array, startingIndex) {
|
|
786
|
+
Check_default.typeOf.object("value", value);
|
|
787
|
+
Check_default.defined("array", array);
|
|
788
|
+
startingIndex = startingIndex ?? 0;
|
|
789
|
+
array[startingIndex++] = value[0];
|
|
790
|
+
array[startingIndex++] = value[1];
|
|
791
|
+
array[startingIndex++] = value[2];
|
|
792
|
+
array[startingIndex++] = value[3];
|
|
793
|
+
array[startingIndex++] = value[4];
|
|
794
|
+
array[startingIndex++] = value[5];
|
|
795
|
+
array[startingIndex++] = value[6];
|
|
796
|
+
array[startingIndex++] = value[7];
|
|
797
|
+
array[startingIndex++] = value[8];
|
|
798
|
+
array[startingIndex++] = value[9];
|
|
799
|
+
array[startingIndex++] = value[10];
|
|
800
|
+
array[startingIndex++] = value[11];
|
|
801
|
+
array[startingIndex++] = value[12];
|
|
802
|
+
array[startingIndex++] = value[13];
|
|
803
|
+
array[startingIndex++] = value[14];
|
|
804
|
+
array[startingIndex] = value[15];
|
|
805
|
+
return array;
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Retrieves an instance from a packed array.
|
|
809
|
+
*
|
|
810
|
+
* @param {number[]} array The packed array.
|
|
811
|
+
* @param {number} [startingIndex=0] The starting index of the element to be unpacked.
|
|
812
|
+
* @param {Matrix4} [result] The object into which to store the result.
|
|
813
|
+
* @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
|
|
814
|
+
*/
|
|
815
|
+
static unpack(array, startingIndex, result) {
|
|
816
|
+
Check_default.defined("array", array);
|
|
817
|
+
startingIndex = startingIndex ?? 0;
|
|
818
|
+
if (!defined_default(result)) {
|
|
819
|
+
result = new _Matrix4();
|
|
820
|
+
}
|
|
821
|
+
result[0] = array[startingIndex++];
|
|
822
|
+
result[1] = array[startingIndex++];
|
|
823
|
+
result[2] = array[startingIndex++];
|
|
824
|
+
result[3] = array[startingIndex++];
|
|
825
|
+
result[4] = array[startingIndex++];
|
|
826
|
+
result[5] = array[startingIndex++];
|
|
827
|
+
result[6] = array[startingIndex++];
|
|
828
|
+
result[7] = array[startingIndex++];
|
|
829
|
+
result[8] = array[startingIndex++];
|
|
830
|
+
result[9] = array[startingIndex++];
|
|
831
|
+
result[10] = array[startingIndex++];
|
|
832
|
+
result[11] = array[startingIndex++];
|
|
833
|
+
result[12] = array[startingIndex++];
|
|
834
|
+
result[13] = array[startingIndex++];
|
|
835
|
+
result[14] = array[startingIndex++];
|
|
836
|
+
result[15] = array[startingIndex];
|
|
837
|
+
return result;
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Flattens an array of Matrix4s into an array of components. The components
|
|
841
|
+
* are stored in column-major order.
|
|
842
|
+
*
|
|
843
|
+
* @param {Matrix4[]} array The array of matrices to pack.
|
|
844
|
+
* @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 16 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 16) elements.
|
|
845
|
+
* @returns {number[]} The packed array.
|
|
846
|
+
*/
|
|
847
|
+
static packArray(array, result) {
|
|
848
|
+
Check_default.defined("array", array);
|
|
849
|
+
const length = array.length;
|
|
850
|
+
const resultLength = length * 16;
|
|
851
|
+
if (!defined_default(result)) {
|
|
852
|
+
result = new Array(resultLength);
|
|
853
|
+
} else if (!Array.isArray(result) && result.length !== resultLength) {
|
|
854
|
+
throw new DeveloperError_default(
|
|
855
|
+
"If result is a typed array, it must have exactly array.length * 16 elements"
|
|
856
|
+
);
|
|
857
|
+
} else if (result.length !== resultLength) {
|
|
858
|
+
result.length = resultLength;
|
|
859
|
+
}
|
|
860
|
+
for (let i = 0; i < length; ++i) {
|
|
861
|
+
_Matrix4.pack(array[i], result, i * 16);
|
|
862
|
+
}
|
|
863
|
+
return result;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Unpacks an array of column-major matrix components into an array of Matrix4s.
|
|
867
|
+
*
|
|
868
|
+
* @param {number[]} array The array of components to unpack.
|
|
869
|
+
* @param {Matrix4[]} [result] The array onto which to store the result.
|
|
870
|
+
* @returns {Matrix4[]} The unpacked array.
|
|
871
|
+
*/
|
|
872
|
+
static unpackArray(array, result) {
|
|
873
|
+
Check_default.defined("array", array);
|
|
874
|
+
Check_default.typeOf.number.greaterThanOrEquals("array.length", array.length, 16);
|
|
875
|
+
if (array.length % 16 !== 0) {
|
|
876
|
+
throw new DeveloperError_default("array length must be a multiple of 16.");
|
|
877
|
+
}
|
|
878
|
+
const length = array.length;
|
|
879
|
+
if (!defined_default(result)) {
|
|
880
|
+
result = new Array(length / 16);
|
|
881
|
+
} else {
|
|
882
|
+
result.length = length / 16;
|
|
883
|
+
}
|
|
884
|
+
for (let i = 0; i < length; i += 16) {
|
|
885
|
+
const index = i / 16;
|
|
886
|
+
result[index] = _Matrix4.unpack(array, i, result[index]);
|
|
887
|
+
}
|
|
888
|
+
return result;
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Duplicates a Matrix4 instance.
|
|
892
|
+
*
|
|
893
|
+
* @param {Matrix4} matrix The matrix to duplicate.
|
|
894
|
+
* @param {Matrix4} [result] The object onto which to store the result.
|
|
895
|
+
* @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided. (Returns undefined if matrix is undefined)
|
|
896
|
+
*/
|
|
897
|
+
static clone(matrix, result) {
|
|
898
|
+
if (!defined_default(matrix)) {
|
|
899
|
+
return void 0;
|
|
900
|
+
}
|
|
901
|
+
if (!defined_default(result)) {
|
|
902
|
+
return new _Matrix4(
|
|
903
|
+
matrix[0],
|
|
904
|
+
matrix[4],
|
|
905
|
+
matrix[8],
|
|
906
|
+
matrix[12],
|
|
907
|
+
matrix[1],
|
|
908
|
+
matrix[5],
|
|
909
|
+
matrix[9],
|
|
910
|
+
matrix[13],
|
|
911
|
+
matrix[2],
|
|
912
|
+
matrix[6],
|
|
913
|
+
matrix[10],
|
|
914
|
+
matrix[14],
|
|
915
|
+
matrix[3],
|
|
916
|
+
matrix[7],
|
|
917
|
+
matrix[11],
|
|
918
|
+
matrix[15]
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
result[0] = matrix[0];
|
|
922
|
+
result[1] = matrix[1];
|
|
923
|
+
result[2] = matrix[2];
|
|
924
|
+
result[3] = matrix[3];
|
|
925
|
+
result[4] = matrix[4];
|
|
926
|
+
result[5] = matrix[5];
|
|
927
|
+
result[6] = matrix[6];
|
|
928
|
+
result[7] = matrix[7];
|
|
929
|
+
result[8] = matrix[8];
|
|
930
|
+
result[9] = matrix[9];
|
|
931
|
+
result[10] = matrix[10];
|
|
932
|
+
result[11] = matrix[11];
|
|
933
|
+
result[12] = matrix[12];
|
|
934
|
+
result[13] = matrix[13];
|
|
935
|
+
result[14] = matrix[14];
|
|
936
|
+
result[15] = matrix[15];
|
|
937
|
+
return result;
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Computes a Matrix4 instance from a column-major order array.
|
|
941
|
+
*
|
|
942
|
+
* @param {number[]} values The column-major order array.
|
|
943
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
944
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
945
|
+
*/
|
|
946
|
+
static fromColumnMajorArray(values, result) {
|
|
947
|
+
Check_default.defined("values", values);
|
|
948
|
+
return _Matrix4.clone(values, result);
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Computes a Matrix4 instance from a row-major order array.
|
|
952
|
+
* The resulting matrix will be in column-major order.
|
|
953
|
+
*
|
|
954
|
+
* @param {number[]} values The row-major order array.
|
|
955
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
956
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
957
|
+
*/
|
|
958
|
+
static fromRowMajorArray(values, result) {
|
|
959
|
+
Check_default.defined("values", values);
|
|
960
|
+
if (!defined_default(result)) {
|
|
961
|
+
return new _Matrix4(
|
|
962
|
+
values[0],
|
|
963
|
+
values[1],
|
|
964
|
+
values[2],
|
|
965
|
+
values[3],
|
|
966
|
+
values[4],
|
|
967
|
+
values[5],
|
|
968
|
+
values[6],
|
|
969
|
+
values[7],
|
|
970
|
+
values[8],
|
|
971
|
+
values[9],
|
|
972
|
+
values[10],
|
|
973
|
+
values[11],
|
|
974
|
+
values[12],
|
|
975
|
+
values[13],
|
|
976
|
+
values[14],
|
|
977
|
+
values[15]
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
result[0] = values[0];
|
|
981
|
+
result[1] = values[4];
|
|
982
|
+
result[2] = values[8];
|
|
983
|
+
result[3] = values[12];
|
|
984
|
+
result[4] = values[1];
|
|
985
|
+
result[5] = values[5];
|
|
986
|
+
result[6] = values[9];
|
|
987
|
+
result[7] = values[13];
|
|
988
|
+
result[8] = values[2];
|
|
989
|
+
result[9] = values[6];
|
|
990
|
+
result[10] = values[10];
|
|
991
|
+
result[11] = values[14];
|
|
992
|
+
result[12] = values[3];
|
|
993
|
+
result[13] = values[7];
|
|
994
|
+
result[14] = values[11];
|
|
995
|
+
result[15] = values[15];
|
|
996
|
+
return result;
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Computes a Matrix4 instance from a Matrix3 representing the rotation
|
|
1000
|
+
* and a Cartesian3 representing the translation.
|
|
1001
|
+
*
|
|
1002
|
+
* @param {Matrix3} rotation The upper left portion of the matrix representing the rotation.
|
|
1003
|
+
* @param {Cartesian3} [translation=Cartesian3.ZERO] The upper right portion of the matrix representing the translation.
|
|
1004
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
1005
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
1006
|
+
*/
|
|
1007
|
+
static fromRotationTranslation(rotation, translation, result) {
|
|
1008
|
+
Check_default.typeOf.object("rotation", rotation);
|
|
1009
|
+
translation = translation ?? Cartesian3_default.ZERO;
|
|
1010
|
+
if (!defined_default(result)) {
|
|
1011
|
+
return new _Matrix4(
|
|
1012
|
+
rotation[0],
|
|
1013
|
+
rotation[3],
|
|
1014
|
+
rotation[6],
|
|
1015
|
+
translation.x,
|
|
1016
|
+
rotation[1],
|
|
1017
|
+
rotation[4],
|
|
1018
|
+
rotation[7],
|
|
1019
|
+
translation.y,
|
|
1020
|
+
rotation[2],
|
|
1021
|
+
rotation[5],
|
|
1022
|
+
rotation[8],
|
|
1023
|
+
translation.z,
|
|
1024
|
+
0,
|
|
1025
|
+
0,
|
|
1026
|
+
0,
|
|
1027
|
+
1
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
result[0] = rotation[0];
|
|
1031
|
+
result[1] = rotation[1];
|
|
1032
|
+
result[2] = rotation[2];
|
|
1033
|
+
result[3] = 0;
|
|
1034
|
+
result[4] = rotation[3];
|
|
1035
|
+
result[5] = rotation[4];
|
|
1036
|
+
result[6] = rotation[5];
|
|
1037
|
+
result[7] = 0;
|
|
1038
|
+
result[8] = rotation[6];
|
|
1039
|
+
result[9] = rotation[7];
|
|
1040
|
+
result[10] = rotation[8];
|
|
1041
|
+
result[11] = 0;
|
|
1042
|
+
result[12] = translation.x;
|
|
1043
|
+
result[13] = translation.y;
|
|
1044
|
+
result[14] = translation.z;
|
|
1045
|
+
result[15] = 1;
|
|
1046
|
+
return result;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Computes a Matrix4 instance from a translation, rotation, and scale (TRS)
|
|
1050
|
+
* representation with the rotation represented as a quaternion.
|
|
1051
|
+
*
|
|
1052
|
+
* @param {Cartesian3} translation The translation transformation.
|
|
1053
|
+
* @param {Quaternion} rotation The rotation transformation.
|
|
1054
|
+
* @param {Cartesian3} scale The non-uniform scale transformation.
|
|
1055
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
1056
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
1057
|
+
*
|
|
1058
|
+
* @example
|
|
1059
|
+
* const result = Cesium.Matrix4.fromTranslationQuaternionRotationScale(
|
|
1060
|
+
* new Cesium.Cartesian3(1.0, 2.0, 3.0), // translation
|
|
1061
|
+
* Cesium.Quaternion.IDENTITY, // rotation
|
|
1062
|
+
* new Cesium.Cartesian3(7.0, 8.0, 9.0), // scale
|
|
1063
|
+
* result);
|
|
1064
|
+
*/
|
|
1065
|
+
static fromTranslationQuaternionRotationScale(translation, rotation, scale, result) {
|
|
1066
|
+
Check_default.typeOf.object("translation", translation);
|
|
1067
|
+
Check_default.typeOf.object("rotation", rotation);
|
|
1068
|
+
Check_default.typeOf.object("scale", scale);
|
|
1069
|
+
if (!defined_default(result)) {
|
|
1070
|
+
result = new _Matrix4();
|
|
1071
|
+
}
|
|
1072
|
+
const scaleX = scale.x;
|
|
1073
|
+
const scaleY = scale.y;
|
|
1074
|
+
const scaleZ = scale.z;
|
|
1075
|
+
const x2 = rotation.x * rotation.x;
|
|
1076
|
+
const xy = rotation.x * rotation.y;
|
|
1077
|
+
const xz = rotation.x * rotation.z;
|
|
1078
|
+
const xw = rotation.x * rotation.w;
|
|
1079
|
+
const y2 = rotation.y * rotation.y;
|
|
1080
|
+
const yz = rotation.y * rotation.z;
|
|
1081
|
+
const yw = rotation.y * rotation.w;
|
|
1082
|
+
const z2 = rotation.z * rotation.z;
|
|
1083
|
+
const zw = rotation.z * rotation.w;
|
|
1084
|
+
const w2 = rotation.w * rotation.w;
|
|
1085
|
+
const m00 = x2 - y2 - z2 + w2;
|
|
1086
|
+
const m01 = 2 * (xy - zw);
|
|
1087
|
+
const m02 = 2 * (xz + yw);
|
|
1088
|
+
const m10 = 2 * (xy + zw);
|
|
1089
|
+
const m11 = -x2 + y2 - z2 + w2;
|
|
1090
|
+
const m12 = 2 * (yz - xw);
|
|
1091
|
+
const m20 = 2 * (xz - yw);
|
|
1092
|
+
const m21 = 2 * (yz + xw);
|
|
1093
|
+
const m22 = -x2 - y2 + z2 + w2;
|
|
1094
|
+
result[0] = m00 * scaleX;
|
|
1095
|
+
result[1] = m10 * scaleX;
|
|
1096
|
+
result[2] = m20 * scaleX;
|
|
1097
|
+
result[3] = 0;
|
|
1098
|
+
result[4] = m01 * scaleY;
|
|
1099
|
+
result[5] = m11 * scaleY;
|
|
1100
|
+
result[6] = m21 * scaleY;
|
|
1101
|
+
result[7] = 0;
|
|
1102
|
+
result[8] = m02 * scaleZ;
|
|
1103
|
+
result[9] = m12 * scaleZ;
|
|
1104
|
+
result[10] = m22 * scaleZ;
|
|
1105
|
+
result[11] = 0;
|
|
1106
|
+
result[12] = translation.x;
|
|
1107
|
+
result[13] = translation.y;
|
|
1108
|
+
result[14] = translation.z;
|
|
1109
|
+
result[15] = 1;
|
|
1110
|
+
return result;
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Creates a Matrix4 instance from a {@link TranslationRotationScale} instance.
|
|
1114
|
+
*
|
|
1115
|
+
* @param {TranslationRotationScale} translationRotationScale The instance.
|
|
1116
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
1117
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
1118
|
+
*/
|
|
1119
|
+
static fromTranslationRotationScale(translationRotationScale, result) {
|
|
1120
|
+
Check_default.typeOf.object("translationRotationScale", translationRotationScale);
|
|
1121
|
+
return _Matrix4.fromTranslationQuaternionRotationScale(
|
|
1122
|
+
translationRotationScale.translation,
|
|
1123
|
+
translationRotationScale.rotation,
|
|
1124
|
+
translationRotationScale.scale,
|
|
1125
|
+
result
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Creates a Matrix4 instance from a Cartesian3 representing the translation.
|
|
1130
|
+
*
|
|
1131
|
+
* @param {Cartesian3} translation The upper right portion of the matrix representing the translation.
|
|
1132
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
1133
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
1134
|
+
*
|
|
1135
|
+
* @see Matrix4.multiplyByTranslation
|
|
1136
|
+
*/
|
|
1137
|
+
static fromTranslation(translation, result) {
|
|
1138
|
+
Check_default.typeOf.object("translation", translation);
|
|
1139
|
+
return _Matrix4.fromRotationTranslation(
|
|
1140
|
+
Matrix3_default.IDENTITY,
|
|
1141
|
+
translation,
|
|
1142
|
+
result
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Computes a Matrix4 instance representing a non-uniform scale.
|
|
1147
|
+
*
|
|
1148
|
+
* @param {Cartesian3} scale The x, y, and z scale factors.
|
|
1149
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
1150
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
1151
|
+
*
|
|
1152
|
+
* @example
|
|
1153
|
+
* // Creates
|
|
1154
|
+
* // [7.0, 0.0, 0.0, 0.0]
|
|
1155
|
+
* // [0.0, 8.0, 0.0, 0.0]
|
|
1156
|
+
* // [0.0, 0.0, 9.0, 0.0]
|
|
1157
|
+
* // [0.0, 0.0, 0.0, 1.0]
|
|
1158
|
+
* const m = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));
|
|
1159
|
+
*/
|
|
1160
|
+
static fromScale(scale, result) {
|
|
1161
|
+
Check_default.typeOf.object("scale", scale);
|
|
1162
|
+
if (!defined_default(result)) {
|
|
1163
|
+
return new _Matrix4(
|
|
1164
|
+
scale.x,
|
|
1165
|
+
0,
|
|
1166
|
+
0,
|
|
1167
|
+
0,
|
|
1168
|
+
0,
|
|
1169
|
+
scale.y,
|
|
1170
|
+
0,
|
|
1171
|
+
0,
|
|
1172
|
+
0,
|
|
1173
|
+
0,
|
|
1174
|
+
scale.z,
|
|
1175
|
+
0,
|
|
1176
|
+
0,
|
|
1177
|
+
0,
|
|
1178
|
+
0,
|
|
1179
|
+
1
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
result[0] = scale.x;
|
|
1183
|
+
result[1] = 0;
|
|
1184
|
+
result[2] = 0;
|
|
1185
|
+
result[3] = 0;
|
|
1186
|
+
result[4] = 0;
|
|
1187
|
+
result[5] = scale.y;
|
|
1188
|
+
result[6] = 0;
|
|
1189
|
+
result[7] = 0;
|
|
1190
|
+
result[8] = 0;
|
|
1191
|
+
result[9] = 0;
|
|
1192
|
+
result[10] = scale.z;
|
|
1193
|
+
result[11] = 0;
|
|
1194
|
+
result[12] = 0;
|
|
1195
|
+
result[13] = 0;
|
|
1196
|
+
result[14] = 0;
|
|
1197
|
+
result[15] = 1;
|
|
1198
|
+
return result;
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Computes a Matrix4 instance representing a uniform scale.
|
|
1202
|
+
*
|
|
1203
|
+
* @param {number} scale The uniform scale factor.
|
|
1204
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
1205
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
1206
|
+
*
|
|
1207
|
+
* @example
|
|
1208
|
+
* // Creates
|
|
1209
|
+
* // [2.0, 0.0, 0.0, 0.0]
|
|
1210
|
+
* // [0.0, 2.0, 0.0, 0.0]
|
|
1211
|
+
* // [0.0, 0.0, 2.0, 0.0]
|
|
1212
|
+
* // [0.0, 0.0, 0.0, 1.0]
|
|
1213
|
+
* const m = Cesium.Matrix4.fromUniformScale(2.0);
|
|
1214
|
+
*/
|
|
1215
|
+
static fromUniformScale(scale, result) {
|
|
1216
|
+
Check_default.typeOf.number("scale", scale);
|
|
1217
|
+
if (!defined_default(result)) {
|
|
1218
|
+
return new _Matrix4(
|
|
1219
|
+
scale,
|
|
1220
|
+
0,
|
|
1221
|
+
0,
|
|
1222
|
+
0,
|
|
1223
|
+
0,
|
|
1224
|
+
scale,
|
|
1225
|
+
0,
|
|
1226
|
+
0,
|
|
1227
|
+
0,
|
|
1228
|
+
0,
|
|
1229
|
+
scale,
|
|
1230
|
+
0,
|
|
1231
|
+
0,
|
|
1232
|
+
0,
|
|
1233
|
+
0,
|
|
1234
|
+
1
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
result[0] = scale;
|
|
1238
|
+
result[1] = 0;
|
|
1239
|
+
result[2] = 0;
|
|
1240
|
+
result[3] = 0;
|
|
1241
|
+
result[4] = 0;
|
|
1242
|
+
result[5] = scale;
|
|
1243
|
+
result[6] = 0;
|
|
1244
|
+
result[7] = 0;
|
|
1245
|
+
result[8] = 0;
|
|
1246
|
+
result[9] = 0;
|
|
1247
|
+
result[10] = scale;
|
|
1248
|
+
result[11] = 0;
|
|
1249
|
+
result[12] = 0;
|
|
1250
|
+
result[13] = 0;
|
|
1251
|
+
result[14] = 0;
|
|
1252
|
+
result[15] = 1;
|
|
1253
|
+
return result;
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Creates a rotation matrix.
|
|
1257
|
+
*
|
|
1258
|
+
* @param {Matrix3} rotation The rotation matrix.
|
|
1259
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
1260
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
1261
|
+
*/
|
|
1262
|
+
static fromRotation(rotation, result) {
|
|
1263
|
+
Check_default.typeOf.object("rotation", rotation);
|
|
1264
|
+
if (!defined_default(result)) {
|
|
1265
|
+
result = new _Matrix4();
|
|
1266
|
+
}
|
|
1267
|
+
result[0] = rotation[0];
|
|
1268
|
+
result[1] = rotation[1];
|
|
1269
|
+
result[2] = rotation[2];
|
|
1270
|
+
result[3] = 0;
|
|
1271
|
+
result[4] = rotation[3];
|
|
1272
|
+
result[5] = rotation[4];
|
|
1273
|
+
result[6] = rotation[5];
|
|
1274
|
+
result[7] = 0;
|
|
1275
|
+
result[8] = rotation[6];
|
|
1276
|
+
result[9] = rotation[7];
|
|
1277
|
+
result[10] = rotation[8];
|
|
1278
|
+
result[11] = 0;
|
|
1279
|
+
result[12] = 0;
|
|
1280
|
+
result[13] = 0;
|
|
1281
|
+
result[14] = 0;
|
|
1282
|
+
result[15] = 1;
|
|
1283
|
+
return result;
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Computes a Matrix4 instance from a Camera.
|
|
1287
|
+
*
|
|
1288
|
+
* @param {Camera} camera The camera to use.
|
|
1289
|
+
* @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
|
|
1290
|
+
* @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
|
|
1291
|
+
*/
|
|
1292
|
+
static fromCamera(camera, result) {
|
|
1293
|
+
Check_default.typeOf.object("camera", camera);
|
|
1294
|
+
const position = camera.position;
|
|
1295
|
+
const direction = camera.direction;
|
|
1296
|
+
const up = camera.up;
|
|
1297
|
+
Check_default.typeOf.object("camera.position", position);
|
|
1298
|
+
Check_default.typeOf.object("camera.direction", direction);
|
|
1299
|
+
Check_default.typeOf.object("camera.up", up);
|
|
1300
|
+
Cartesian3_default.normalize(direction, fromCameraF);
|
|
1301
|
+
Cartesian3_default.normalize(
|
|
1302
|
+
Cartesian3_default.cross(fromCameraF, up, fromCameraR),
|
|
1303
|
+
fromCameraR
|
|
1304
|
+
);
|
|
1305
|
+
Cartesian3_default.normalize(
|
|
1306
|
+
Cartesian3_default.cross(fromCameraR, fromCameraF, fromCameraU),
|
|
1307
|
+
fromCameraU
|
|
1308
|
+
);
|
|
1309
|
+
const sX = fromCameraR.x;
|
|
1310
|
+
const sY = fromCameraR.y;
|
|
1311
|
+
const sZ = fromCameraR.z;
|
|
1312
|
+
const fX = fromCameraF.x;
|
|
1313
|
+
const fY = fromCameraF.y;
|
|
1314
|
+
const fZ = fromCameraF.z;
|
|
1315
|
+
const uX = fromCameraU.x;
|
|
1316
|
+
const uY = fromCameraU.y;
|
|
1317
|
+
const uZ = fromCameraU.z;
|
|
1318
|
+
const positionX = position.x;
|
|
1319
|
+
const positionY = position.y;
|
|
1320
|
+
const positionZ = position.z;
|
|
1321
|
+
const t0 = sX * -positionX + sY * -positionY + sZ * -positionZ;
|
|
1322
|
+
const t1 = uX * -positionX + uY * -positionY + uZ * -positionZ;
|
|
1323
|
+
const t2 = fX * positionX + fY * positionY + fZ * positionZ;
|
|
1324
|
+
if (!defined_default(result)) {
|
|
1325
|
+
return new _Matrix4(
|
|
1326
|
+
sX,
|
|
1327
|
+
sY,
|
|
1328
|
+
sZ,
|
|
1329
|
+
t0,
|
|
1330
|
+
uX,
|
|
1331
|
+
uY,
|
|
1332
|
+
uZ,
|
|
1333
|
+
t1,
|
|
1334
|
+
-fX,
|
|
1335
|
+
-fY,
|
|
1336
|
+
-fZ,
|
|
1337
|
+
t2,
|
|
1338
|
+
0,
|
|
1339
|
+
0,
|
|
1340
|
+
0,
|
|
1341
|
+
1
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
result[0] = sX;
|
|
1345
|
+
result[1] = uX;
|
|
1346
|
+
result[2] = -fX;
|
|
1347
|
+
result[3] = 0;
|
|
1348
|
+
result[4] = sY;
|
|
1349
|
+
result[5] = uY;
|
|
1350
|
+
result[6] = -fY;
|
|
1351
|
+
result[7] = 0;
|
|
1352
|
+
result[8] = sZ;
|
|
1353
|
+
result[9] = uZ;
|
|
1354
|
+
result[10] = -fZ;
|
|
1355
|
+
result[11] = 0;
|
|
1356
|
+
result[12] = t0;
|
|
1357
|
+
result[13] = t1;
|
|
1358
|
+
result[14] = t2;
|
|
1359
|
+
result[15] = 1;
|
|
1360
|
+
return result;
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Computes a Matrix4 instance representing a perspective transformation matrix.
|
|
1364
|
+
*
|
|
1365
|
+
* @param {number} fovY The field of view along the Y axis in radians.
|
|
1366
|
+
* @param {number} aspectRatio The aspect ratio.
|
|
1367
|
+
* @param {number} near The distance to the near plane in meters.
|
|
1368
|
+
* @param {number} far The distance to the far plane in meters.
|
|
1369
|
+
* @param {Matrix4} result The object in which the result will be stored.
|
|
1370
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1371
|
+
*
|
|
1372
|
+
* @exception {DeveloperError} fovY must be in (0, PI].
|
|
1373
|
+
* @exception {DeveloperError} aspectRatio must be greater than zero.
|
|
1374
|
+
* @exception {DeveloperError} near must be greater than zero.
|
|
1375
|
+
* @exception {DeveloperError} far must be greater than zero.
|
|
1376
|
+
*/
|
|
1377
|
+
static computePerspectiveFieldOfView(fovY, aspectRatio, near, far, result) {
|
|
1378
|
+
Check_default.typeOf.number.greaterThan("fovY", fovY, 0);
|
|
1379
|
+
Check_default.typeOf.number.lessThan("fovY", fovY, Math.PI);
|
|
1380
|
+
Check_default.typeOf.number.greaterThan("near", near, 0);
|
|
1381
|
+
Check_default.typeOf.number.greaterThan("far", far, 0);
|
|
1382
|
+
Check_default.typeOf.object("result", result);
|
|
1383
|
+
const bottom = Math.tan(fovY * 0.5);
|
|
1384
|
+
const column1Row1 = 1 / bottom;
|
|
1385
|
+
const column0Row0 = column1Row1 / aspectRatio;
|
|
1386
|
+
const column2Row2 = (far + near) / (near - far);
|
|
1387
|
+
const column3Row2 = 2 * far * near / (near - far);
|
|
1388
|
+
result[0] = column0Row0;
|
|
1389
|
+
result[1] = 0;
|
|
1390
|
+
result[2] = 0;
|
|
1391
|
+
result[3] = 0;
|
|
1392
|
+
result[4] = 0;
|
|
1393
|
+
result[5] = column1Row1;
|
|
1394
|
+
result[6] = 0;
|
|
1395
|
+
result[7] = 0;
|
|
1396
|
+
result[8] = 0;
|
|
1397
|
+
result[9] = 0;
|
|
1398
|
+
result[10] = column2Row2;
|
|
1399
|
+
result[11] = -1;
|
|
1400
|
+
result[12] = 0;
|
|
1401
|
+
result[13] = 0;
|
|
1402
|
+
result[14] = column3Row2;
|
|
1403
|
+
result[15] = 0;
|
|
1404
|
+
return result;
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Computes a Matrix4 instance representing an orthographic transformation matrix.
|
|
1408
|
+
*
|
|
1409
|
+
* @param {number} left The number of meters to the left of the camera that will be in view.
|
|
1410
|
+
* @param {number} right The number of meters to the right of the camera that will be in view.
|
|
1411
|
+
* @param {number} bottom The number of meters below of the camera that will be in view.
|
|
1412
|
+
* @param {number} top The number of meters above of the camera that will be in view.
|
|
1413
|
+
* @param {number} near The distance to the near plane in meters.
|
|
1414
|
+
* @param {number} far The distance to the far plane in meters.
|
|
1415
|
+
* @param {Matrix4} result The object in which the result will be stored.
|
|
1416
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1417
|
+
*/
|
|
1418
|
+
static computeOrthographicOffCenter(left, right, bottom, top, near, far, result) {
|
|
1419
|
+
Check_default.typeOf.number("left", left);
|
|
1420
|
+
Check_default.typeOf.number("right", right);
|
|
1421
|
+
Check_default.typeOf.number("bottom", bottom);
|
|
1422
|
+
Check_default.typeOf.number("top", top);
|
|
1423
|
+
Check_default.typeOf.number("near", near);
|
|
1424
|
+
Check_default.typeOf.number("far", far);
|
|
1425
|
+
Check_default.typeOf.object("result", result);
|
|
1426
|
+
let a = 1 / (right - left);
|
|
1427
|
+
let b = 1 / (top - bottom);
|
|
1428
|
+
let c = 1 / (far - near);
|
|
1429
|
+
const tx = -(right + left) * a;
|
|
1430
|
+
const ty = -(top + bottom) * b;
|
|
1431
|
+
const tz = -(far + near) * c;
|
|
1432
|
+
a *= 2;
|
|
1433
|
+
b *= 2;
|
|
1434
|
+
c *= -2;
|
|
1435
|
+
result[0] = a;
|
|
1436
|
+
result[1] = 0;
|
|
1437
|
+
result[2] = 0;
|
|
1438
|
+
result[3] = 0;
|
|
1439
|
+
result[4] = 0;
|
|
1440
|
+
result[5] = b;
|
|
1441
|
+
result[6] = 0;
|
|
1442
|
+
result[7] = 0;
|
|
1443
|
+
result[8] = 0;
|
|
1444
|
+
result[9] = 0;
|
|
1445
|
+
result[10] = c;
|
|
1446
|
+
result[11] = 0;
|
|
1447
|
+
result[12] = tx;
|
|
1448
|
+
result[13] = ty;
|
|
1449
|
+
result[14] = tz;
|
|
1450
|
+
result[15] = 1;
|
|
1451
|
+
return result;
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Computes a Matrix4 instance representing an off center perspective transformation.
|
|
1455
|
+
*
|
|
1456
|
+
* @param {number} left The number of meters to the left of the camera that will be in view.
|
|
1457
|
+
* @param {number} right The number of meters to the right of the camera that will be in view.
|
|
1458
|
+
* @param {number} bottom The number of meters below the camera that will be in view.
|
|
1459
|
+
* @param {number} top The number of meters above the camera that will be in view.
|
|
1460
|
+
* @param {number} near The distance to the near plane in meters.
|
|
1461
|
+
* @param {number} far The distance to the far plane in meters.
|
|
1462
|
+
* @param {Matrix4} result The object in which the result will be stored.
|
|
1463
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1464
|
+
*/
|
|
1465
|
+
static computePerspectiveOffCenter(left, right, bottom, top, near, far, result) {
|
|
1466
|
+
Check_default.typeOf.number("left", left);
|
|
1467
|
+
Check_default.typeOf.number("right", right);
|
|
1468
|
+
Check_default.typeOf.number("bottom", bottom);
|
|
1469
|
+
Check_default.typeOf.number("top", top);
|
|
1470
|
+
Check_default.typeOf.number("near", near);
|
|
1471
|
+
Check_default.typeOf.number("far", far);
|
|
1472
|
+
Check_default.typeOf.object("result", result);
|
|
1473
|
+
const column0Row0 = 2 * near / (right - left);
|
|
1474
|
+
const column1Row1 = 2 * near / (top - bottom);
|
|
1475
|
+
const column2Row0 = (right + left) / (right - left);
|
|
1476
|
+
const column2Row1 = (top + bottom) / (top - bottom);
|
|
1477
|
+
const column2Row2 = -(far + near) / (far - near);
|
|
1478
|
+
const column2Row3 = -1;
|
|
1479
|
+
const column3Row2 = -2 * far * near / (far - near);
|
|
1480
|
+
result[0] = column0Row0;
|
|
1481
|
+
result[1] = 0;
|
|
1482
|
+
result[2] = 0;
|
|
1483
|
+
result[3] = 0;
|
|
1484
|
+
result[4] = 0;
|
|
1485
|
+
result[5] = column1Row1;
|
|
1486
|
+
result[6] = 0;
|
|
1487
|
+
result[7] = 0;
|
|
1488
|
+
result[8] = column2Row0;
|
|
1489
|
+
result[9] = column2Row1;
|
|
1490
|
+
result[10] = column2Row2;
|
|
1491
|
+
result[11] = column2Row3;
|
|
1492
|
+
result[12] = 0;
|
|
1493
|
+
result[13] = 0;
|
|
1494
|
+
result[14] = column3Row2;
|
|
1495
|
+
result[15] = 0;
|
|
1496
|
+
return result;
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Computes a Matrix4 instance representing an infinite off center perspective transformation.
|
|
1500
|
+
*
|
|
1501
|
+
* @param {number} left The number of meters to the left of the camera that will be in view.
|
|
1502
|
+
* @param {number} right The number of meters to the right of the camera that will be in view.
|
|
1503
|
+
* @param {number} bottom The number of meters below of the camera that will be in view.
|
|
1504
|
+
* @param {number} top The number of meters above of the camera that will be in view.
|
|
1505
|
+
* @param {number} near The distance to the near plane in meters.
|
|
1506
|
+
* @param {Matrix4} result The object in which the result will be stored.
|
|
1507
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1508
|
+
*/
|
|
1509
|
+
static computeInfinitePerspectiveOffCenter(left, right, bottom, top, near, result) {
|
|
1510
|
+
Check_default.typeOf.number("left", left);
|
|
1511
|
+
Check_default.typeOf.number("right", right);
|
|
1512
|
+
Check_default.typeOf.number("bottom", bottom);
|
|
1513
|
+
Check_default.typeOf.number("top", top);
|
|
1514
|
+
Check_default.typeOf.number("near", near);
|
|
1515
|
+
Check_default.typeOf.object("result", result);
|
|
1516
|
+
const column0Row0 = 2 * near / (right - left);
|
|
1517
|
+
const column1Row1 = 2 * near / (top - bottom);
|
|
1518
|
+
const column2Row0 = (right + left) / (right - left);
|
|
1519
|
+
const column2Row1 = (top + bottom) / (top - bottom);
|
|
1520
|
+
const column2Row2 = -1;
|
|
1521
|
+
const column2Row3 = -1;
|
|
1522
|
+
const column3Row2 = -2 * near;
|
|
1523
|
+
result[0] = column0Row0;
|
|
1524
|
+
result[1] = 0;
|
|
1525
|
+
result[2] = 0;
|
|
1526
|
+
result[3] = 0;
|
|
1527
|
+
result[4] = 0;
|
|
1528
|
+
result[5] = column1Row1;
|
|
1529
|
+
result[6] = 0;
|
|
1530
|
+
result[7] = 0;
|
|
1531
|
+
result[8] = column2Row0;
|
|
1532
|
+
result[9] = column2Row1;
|
|
1533
|
+
result[10] = column2Row2;
|
|
1534
|
+
result[11] = column2Row3;
|
|
1535
|
+
result[12] = 0;
|
|
1536
|
+
result[13] = 0;
|
|
1537
|
+
result[14] = column3Row2;
|
|
1538
|
+
result[15] = 0;
|
|
1539
|
+
return result;
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Computes a Matrix4 instance that transforms from normalized device coordinates to window coordinates.
|
|
1543
|
+
*
|
|
1544
|
+
* @param {Viewport} [viewport = { x : 0.0, y : 0.0, width : 0.0, height : 0.0 }] The viewport's corners as shown in Example 1.
|
|
1545
|
+
* @param {number} [nearDepthRange=0.0] The near plane distance in window coordinates.
|
|
1546
|
+
* @param {number} [farDepthRange=1.0] The far plane distance in window coordinates.
|
|
1547
|
+
* @param {Matrix4} [result] The object in which the result will be stored.
|
|
1548
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1549
|
+
*
|
|
1550
|
+
* @example
|
|
1551
|
+
* // Create viewport transformation using an explicit viewport and depth range.
|
|
1552
|
+
* const m = Cesium.Matrix4.computeViewportTransformation({
|
|
1553
|
+
* x : 0.0,
|
|
1554
|
+
* y : 0.0,
|
|
1555
|
+
* width : 1024.0,
|
|
1556
|
+
* height : 768.0
|
|
1557
|
+
* }, 0.0, 1.0, new Cesium.Matrix4());
|
|
1558
|
+
*/
|
|
1559
|
+
static computeViewportTransformation(viewport, nearDepthRange, farDepthRange, result) {
|
|
1560
|
+
if (!defined_default(result)) {
|
|
1561
|
+
result = new _Matrix4();
|
|
1562
|
+
}
|
|
1563
|
+
viewport = viewport ?? Frozen_default.EMPTY_OBJECT;
|
|
1564
|
+
const x = viewport.x ?? 0;
|
|
1565
|
+
const y = viewport.y ?? 0;
|
|
1566
|
+
const width = viewport.width ?? 0;
|
|
1567
|
+
const height = viewport.height ?? 0;
|
|
1568
|
+
nearDepthRange = nearDepthRange ?? 0;
|
|
1569
|
+
farDepthRange = farDepthRange ?? 1;
|
|
1570
|
+
const halfWidth = width * 0.5;
|
|
1571
|
+
const halfHeight = height * 0.5;
|
|
1572
|
+
const halfDepth = (farDepthRange - nearDepthRange) * 0.5;
|
|
1573
|
+
const column0Row0 = halfWidth;
|
|
1574
|
+
const column1Row1 = halfHeight;
|
|
1575
|
+
const column2Row2 = halfDepth;
|
|
1576
|
+
const column3Row0 = x + halfWidth;
|
|
1577
|
+
const column3Row1 = y + halfHeight;
|
|
1578
|
+
const column3Row2 = nearDepthRange + halfDepth;
|
|
1579
|
+
const column3Row3 = 1;
|
|
1580
|
+
result[0] = column0Row0;
|
|
1581
|
+
result[1] = 0;
|
|
1582
|
+
result[2] = 0;
|
|
1583
|
+
result[3] = 0;
|
|
1584
|
+
result[4] = 0;
|
|
1585
|
+
result[5] = column1Row1;
|
|
1586
|
+
result[6] = 0;
|
|
1587
|
+
result[7] = 0;
|
|
1588
|
+
result[8] = 0;
|
|
1589
|
+
result[9] = 0;
|
|
1590
|
+
result[10] = column2Row2;
|
|
1591
|
+
result[11] = 0;
|
|
1592
|
+
result[12] = column3Row0;
|
|
1593
|
+
result[13] = column3Row1;
|
|
1594
|
+
result[14] = column3Row2;
|
|
1595
|
+
result[15] = column3Row3;
|
|
1596
|
+
return result;
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Computes a Matrix4 instance that transforms from world space to view space.
|
|
1600
|
+
*
|
|
1601
|
+
* @param {Cartesian3} position The position of the camera.
|
|
1602
|
+
* @param {Cartesian3} direction The forward direction.
|
|
1603
|
+
* @param {Cartesian3} up The up direction.
|
|
1604
|
+
* @param {Cartesian3} right The right direction.
|
|
1605
|
+
* @param {Matrix4} result The object in which the result will be stored.
|
|
1606
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1607
|
+
*/
|
|
1608
|
+
static computeView(position, direction, up, right, result) {
|
|
1609
|
+
Check_default.typeOf.object("position", position);
|
|
1610
|
+
Check_default.typeOf.object("direction", direction);
|
|
1611
|
+
Check_default.typeOf.object("up", up);
|
|
1612
|
+
Check_default.typeOf.object("right", right);
|
|
1613
|
+
Check_default.typeOf.object("result", result);
|
|
1614
|
+
result[0] = right.x;
|
|
1615
|
+
result[1] = up.x;
|
|
1616
|
+
result[2] = -direction.x;
|
|
1617
|
+
result[3] = 0;
|
|
1618
|
+
result[4] = right.y;
|
|
1619
|
+
result[5] = up.y;
|
|
1620
|
+
result[6] = -direction.y;
|
|
1621
|
+
result[7] = 0;
|
|
1622
|
+
result[8] = right.z;
|
|
1623
|
+
result[9] = up.z;
|
|
1624
|
+
result[10] = -direction.z;
|
|
1625
|
+
result[11] = 0;
|
|
1626
|
+
result[12] = -Cartesian3_default.dot(right, position);
|
|
1627
|
+
result[13] = -Cartesian3_default.dot(up, position);
|
|
1628
|
+
result[14] = Cartesian3_default.dot(direction, position);
|
|
1629
|
+
result[15] = 1;
|
|
1630
|
+
return result;
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Computes an Array from the provided Matrix4 instance.
|
|
1634
|
+
* The array will be in column-major order.
|
|
1635
|
+
*
|
|
1636
|
+
* @param {Matrix4} matrix The matrix to use..
|
|
1637
|
+
* @param {number[]} [result] The Array onto which to store the result.
|
|
1638
|
+
* @returns {number[]} The modified Array parameter or a new Array instance if one was not provided.
|
|
1639
|
+
*
|
|
1640
|
+
* @example
|
|
1641
|
+
* //create an array from an instance of Matrix4
|
|
1642
|
+
* // m = [10.0, 14.0, 18.0, 22.0]
|
|
1643
|
+
* // [11.0, 15.0, 19.0, 23.0]
|
|
1644
|
+
* // [12.0, 16.0, 20.0, 24.0]
|
|
1645
|
+
* // [13.0, 17.0, 21.0, 25.0]
|
|
1646
|
+
* const a = Cesium.Matrix4.toArray(m);
|
|
1647
|
+
*
|
|
1648
|
+
* // m remains the same
|
|
1649
|
+
* //creates a = [10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0]
|
|
1650
|
+
*/
|
|
1651
|
+
static toArray(matrix, result) {
|
|
1652
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
1653
|
+
if (!defined_default(result)) {
|
|
1654
|
+
return [
|
|
1655
|
+
matrix[0],
|
|
1656
|
+
matrix[1],
|
|
1657
|
+
matrix[2],
|
|
1658
|
+
matrix[3],
|
|
1659
|
+
matrix[4],
|
|
1660
|
+
matrix[5],
|
|
1661
|
+
matrix[6],
|
|
1662
|
+
matrix[7],
|
|
1663
|
+
matrix[8],
|
|
1664
|
+
matrix[9],
|
|
1665
|
+
matrix[10],
|
|
1666
|
+
matrix[11],
|
|
1667
|
+
matrix[12],
|
|
1668
|
+
matrix[13],
|
|
1669
|
+
matrix[14],
|
|
1670
|
+
matrix[15]
|
|
1671
|
+
];
|
|
1672
|
+
}
|
|
1673
|
+
result[0] = matrix[0];
|
|
1674
|
+
result[1] = matrix[1];
|
|
1675
|
+
result[2] = matrix[2];
|
|
1676
|
+
result[3] = matrix[3];
|
|
1677
|
+
result[4] = matrix[4];
|
|
1678
|
+
result[5] = matrix[5];
|
|
1679
|
+
result[6] = matrix[6];
|
|
1680
|
+
result[7] = matrix[7];
|
|
1681
|
+
result[8] = matrix[8];
|
|
1682
|
+
result[9] = matrix[9];
|
|
1683
|
+
result[10] = matrix[10];
|
|
1684
|
+
result[11] = matrix[11];
|
|
1685
|
+
result[12] = matrix[12];
|
|
1686
|
+
result[13] = matrix[13];
|
|
1687
|
+
result[14] = matrix[14];
|
|
1688
|
+
result[15] = matrix[15];
|
|
1689
|
+
return result;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Computes the array index of the element at the provided row and column.
|
|
1693
|
+
*
|
|
1694
|
+
* @param {number} row The zero-based index of the row.
|
|
1695
|
+
* @param {number} column The zero-based index of the column.
|
|
1696
|
+
* @returns {number} The index of the element at the provided row and column.
|
|
1697
|
+
*
|
|
1698
|
+
* @exception {DeveloperError} row must be 0, 1, 2, or 3.
|
|
1699
|
+
* @exception {DeveloperError} column must be 0, 1, 2, or 3.
|
|
1700
|
+
*
|
|
1701
|
+
* @example
|
|
1702
|
+
* const myMatrix = new Cesium.Matrix4();
|
|
1703
|
+
* const column1Row0Index = Cesium.Matrix4.getElementIndex(1, 0);
|
|
1704
|
+
* const column1Row0 = myMatrix[column1Row0Index];
|
|
1705
|
+
* myMatrix[column1Row0Index] = 10.0;
|
|
1706
|
+
*/
|
|
1707
|
+
static getElementIndex(column, row) {
|
|
1708
|
+
Check_default.typeOf.number.greaterThanOrEquals("row", row, 0);
|
|
1709
|
+
Check_default.typeOf.number.lessThanOrEquals("row", row, 3);
|
|
1710
|
+
Check_default.typeOf.number.greaterThanOrEquals("column", column, 0);
|
|
1711
|
+
Check_default.typeOf.number.lessThanOrEquals("column", column, 3);
|
|
1712
|
+
return column * 4 + row;
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Retrieves a copy of the matrix column at the provided index as a Cartesian4 instance.
|
|
1716
|
+
*
|
|
1717
|
+
* @param {Matrix4} matrix The matrix to use.
|
|
1718
|
+
* @param {number} index The zero-based index of the column to retrieve.
|
|
1719
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
1720
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
1721
|
+
*
|
|
1722
|
+
* @exception {DeveloperError} index must be 0, 1, 2, or 3.
|
|
1723
|
+
*
|
|
1724
|
+
* @example
|
|
1725
|
+
* //returns a Cartesian4 instance with values from the specified column
|
|
1726
|
+
* // m = [10.0, 11.0, 12.0, 13.0]
|
|
1727
|
+
* // [14.0, 15.0, 16.0, 17.0]
|
|
1728
|
+
* // [18.0, 19.0, 20.0, 21.0]
|
|
1729
|
+
* // [22.0, 23.0, 24.0, 25.0]
|
|
1730
|
+
*
|
|
1731
|
+
* //Example 1: Creates an instance of Cartesian
|
|
1732
|
+
* const a = Cesium.Matrix4.getColumn(m, 2, new Cesium.Cartesian4());
|
|
1733
|
+
*
|
|
1734
|
+
* @example
|
|
1735
|
+
* //Example 2: Sets values for Cartesian instance
|
|
1736
|
+
* const a = new Cesium.Cartesian4();
|
|
1737
|
+
* Cesium.Matrix4.getColumn(m, 2, a);
|
|
1738
|
+
*
|
|
1739
|
+
* // a.x = 12.0; a.y = 16.0; a.z = 20.0; a.w = 24.0;
|
|
1740
|
+
*/
|
|
1741
|
+
static getColumn(matrix, index, result) {
|
|
1742
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
1743
|
+
Check_default.typeOf.number.greaterThanOrEquals("index", index, 0);
|
|
1744
|
+
Check_default.typeOf.number.lessThanOrEquals("index", index, 3);
|
|
1745
|
+
Check_default.typeOf.object("result", result);
|
|
1746
|
+
const startIndex = index * 4;
|
|
1747
|
+
const x = matrix[startIndex];
|
|
1748
|
+
const y = matrix[startIndex + 1];
|
|
1749
|
+
const z = matrix[startIndex + 2];
|
|
1750
|
+
const w = matrix[startIndex + 3];
|
|
1751
|
+
result.x = x;
|
|
1752
|
+
result.y = y;
|
|
1753
|
+
result.z = z;
|
|
1754
|
+
result.w = w;
|
|
1755
|
+
return result;
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian4 instance.
|
|
1759
|
+
*
|
|
1760
|
+
* @param {Matrix4} matrix The matrix to use.
|
|
1761
|
+
* @param {number} index The zero-based index of the column to set.
|
|
1762
|
+
* @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified column.
|
|
1763
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
1764
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1765
|
+
*
|
|
1766
|
+
* @exception {DeveloperError} index must be 0, 1, 2, or 3.
|
|
1767
|
+
*
|
|
1768
|
+
* @example
|
|
1769
|
+
* //creates a new Matrix4 instance with new column values from the Cartesian4 instance
|
|
1770
|
+
* // m = [10.0, 11.0, 12.0, 13.0]
|
|
1771
|
+
* // [14.0, 15.0, 16.0, 17.0]
|
|
1772
|
+
* // [18.0, 19.0, 20.0, 21.0]
|
|
1773
|
+
* // [22.0, 23.0, 24.0, 25.0]
|
|
1774
|
+
*
|
|
1775
|
+
* const a = Cesium.Matrix4.setColumn(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());
|
|
1776
|
+
*
|
|
1777
|
+
* // m remains the same
|
|
1778
|
+
* // a = [10.0, 11.0, 99.0, 13.0]
|
|
1779
|
+
* // [14.0, 15.0, 98.0, 17.0]
|
|
1780
|
+
* // [18.0, 19.0, 97.0, 21.0]
|
|
1781
|
+
* // [22.0, 23.0, 96.0, 25.0]
|
|
1782
|
+
*/
|
|
1783
|
+
static setColumn(matrix, index, cartesian, result) {
|
|
1784
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
1785
|
+
Check_default.typeOf.number.greaterThanOrEquals("index", index, 0);
|
|
1786
|
+
Check_default.typeOf.number.lessThanOrEquals("index", index, 3);
|
|
1787
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
1788
|
+
Check_default.typeOf.object("result", result);
|
|
1789
|
+
result = _Matrix4.clone(matrix, result);
|
|
1790
|
+
const startIndex = index * 4;
|
|
1791
|
+
result[startIndex] = cartesian.x;
|
|
1792
|
+
result[startIndex + 1] = cartesian.y;
|
|
1793
|
+
result[startIndex + 2] = cartesian.z;
|
|
1794
|
+
result[startIndex + 3] = cartesian.w;
|
|
1795
|
+
return result;
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Retrieves a copy of the matrix row at the provided index as a Cartesian4 instance.
|
|
1799
|
+
*
|
|
1800
|
+
* @param {Matrix4} matrix The matrix to use.
|
|
1801
|
+
* @param {number} index The zero-based index of the row to retrieve.
|
|
1802
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
1803
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
1804
|
+
*
|
|
1805
|
+
* @exception {DeveloperError} index must be 0, 1, 2, or 3.
|
|
1806
|
+
*
|
|
1807
|
+
* @example
|
|
1808
|
+
* //returns a Cartesian4 instance with values from the specified column
|
|
1809
|
+
* // m = [10.0, 11.0, 12.0, 13.0]
|
|
1810
|
+
* // [14.0, 15.0, 16.0, 17.0]
|
|
1811
|
+
* // [18.0, 19.0, 20.0, 21.0]
|
|
1812
|
+
* // [22.0, 23.0, 24.0, 25.0]
|
|
1813
|
+
*
|
|
1814
|
+
* //Example 1: Returns an instance of Cartesian
|
|
1815
|
+
* const a = Cesium.Matrix4.getRow(m, 2, new Cesium.Cartesian4());
|
|
1816
|
+
*
|
|
1817
|
+
* @example
|
|
1818
|
+
* //Example 2: Sets values for a Cartesian instance
|
|
1819
|
+
* const a = new Cesium.Cartesian4();
|
|
1820
|
+
* Cesium.Matrix4.getRow(m, 2, a);
|
|
1821
|
+
*
|
|
1822
|
+
* // a.x = 18.0; a.y = 19.0; a.z = 20.0; a.w = 21.0;
|
|
1823
|
+
*/
|
|
1824
|
+
static getRow(matrix, index, result) {
|
|
1825
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
1826
|
+
Check_default.typeOf.number.greaterThanOrEquals("index", index, 0);
|
|
1827
|
+
Check_default.typeOf.number.lessThanOrEquals("index", index, 3);
|
|
1828
|
+
Check_default.typeOf.object("result", result);
|
|
1829
|
+
const x = matrix[index];
|
|
1830
|
+
const y = matrix[index + 4];
|
|
1831
|
+
const z = matrix[index + 8];
|
|
1832
|
+
const w = matrix[index + 12];
|
|
1833
|
+
result.x = x;
|
|
1834
|
+
result.y = y;
|
|
1835
|
+
result.z = z;
|
|
1836
|
+
result.w = w;
|
|
1837
|
+
return result;
|
|
1838
|
+
}
|
|
1839
|
+
/**
|
|
1840
|
+
* Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian4 instance.
|
|
1841
|
+
*
|
|
1842
|
+
* @param {Matrix4} matrix The matrix to use.
|
|
1843
|
+
* @param {number} index The zero-based index of the row to set.
|
|
1844
|
+
* @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified row.
|
|
1845
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
1846
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1847
|
+
*
|
|
1848
|
+
* @exception {DeveloperError} index must be 0, 1, 2, or 3.
|
|
1849
|
+
*
|
|
1850
|
+
* @example
|
|
1851
|
+
* //create a new Matrix4 instance with new row values from the Cartesian4 instance
|
|
1852
|
+
* // m = [10.0, 11.0, 12.0, 13.0]
|
|
1853
|
+
* // [14.0, 15.0, 16.0, 17.0]
|
|
1854
|
+
* // [18.0, 19.0, 20.0, 21.0]
|
|
1855
|
+
* // [22.0, 23.0, 24.0, 25.0]
|
|
1856
|
+
*
|
|
1857
|
+
* const a = Cesium.Matrix4.setRow(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());
|
|
1858
|
+
*
|
|
1859
|
+
* // m remains the same
|
|
1860
|
+
* // a = [10.0, 11.0, 12.0, 13.0]
|
|
1861
|
+
* // [14.0, 15.0, 16.0, 17.0]
|
|
1862
|
+
* // [99.0, 98.0, 97.0, 96.0]
|
|
1863
|
+
* // [22.0, 23.0, 24.0, 25.0]
|
|
1864
|
+
*/
|
|
1865
|
+
static setRow(matrix, index, cartesian, result) {
|
|
1866
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
1867
|
+
Check_default.typeOf.number.greaterThanOrEquals("index", index, 0);
|
|
1868
|
+
Check_default.typeOf.number.lessThanOrEquals("index", index, 3);
|
|
1869
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
1870
|
+
Check_default.typeOf.object("result", result);
|
|
1871
|
+
result = _Matrix4.clone(matrix, result);
|
|
1872
|
+
result[index] = cartesian.x;
|
|
1873
|
+
result[index + 4] = cartesian.y;
|
|
1874
|
+
result[index + 8] = cartesian.z;
|
|
1875
|
+
result[index + 12] = cartesian.w;
|
|
1876
|
+
return result;
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Computes a new matrix that replaces the translation in the rightmost column of the provided
|
|
1880
|
+
* matrix with the provided translation. This assumes the matrix is an affine transformation.
|
|
1881
|
+
*
|
|
1882
|
+
* @param {Matrix4} matrix The matrix to use.
|
|
1883
|
+
* @param {Cartesian3} translation The translation that replaces the translation of the provided matrix.
|
|
1884
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
1885
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1886
|
+
*/
|
|
1887
|
+
static setTranslation(matrix, translation, result) {
|
|
1888
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
1889
|
+
Check_default.typeOf.object("translation", translation);
|
|
1890
|
+
Check_default.typeOf.object("result", result);
|
|
1891
|
+
result[0] = matrix[0];
|
|
1892
|
+
result[1] = matrix[1];
|
|
1893
|
+
result[2] = matrix[2];
|
|
1894
|
+
result[3] = matrix[3];
|
|
1895
|
+
result[4] = matrix[4];
|
|
1896
|
+
result[5] = matrix[5];
|
|
1897
|
+
result[6] = matrix[6];
|
|
1898
|
+
result[7] = matrix[7];
|
|
1899
|
+
result[8] = matrix[8];
|
|
1900
|
+
result[9] = matrix[9];
|
|
1901
|
+
result[10] = matrix[10];
|
|
1902
|
+
result[11] = matrix[11];
|
|
1903
|
+
result[12] = translation.x;
|
|
1904
|
+
result[13] = translation.y;
|
|
1905
|
+
result[14] = translation.z;
|
|
1906
|
+
result[15] = matrix[15];
|
|
1907
|
+
return result;
|
|
1908
|
+
}
|
|
1909
|
+
/**
|
|
1910
|
+
* Computes a new matrix that replaces the scale with the provided scale.
|
|
1911
|
+
* This assumes the matrix is an affine transformation.
|
|
1912
|
+
*
|
|
1913
|
+
* @param {Matrix4} matrix The matrix to use.
|
|
1914
|
+
* @param {Cartesian3} scale The scale that replaces the scale of the provided matrix.
|
|
1915
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
1916
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1917
|
+
*
|
|
1918
|
+
* @see Matrix4.setUniformScale
|
|
1919
|
+
* @see Matrix4.fromScale
|
|
1920
|
+
* @see Matrix4.fromUniformScale
|
|
1921
|
+
* @see Matrix4.multiplyByScale
|
|
1922
|
+
* @see Matrix4.multiplyByUniformScale
|
|
1923
|
+
* @see Matrix4.getScale
|
|
1924
|
+
*/
|
|
1925
|
+
static setScale(matrix, scale, result) {
|
|
1926
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
1927
|
+
Check_default.typeOf.object("scale", scale);
|
|
1928
|
+
Check_default.typeOf.object("result", result);
|
|
1929
|
+
const existingScale = _Matrix4.getScale(matrix, scaleScratch1);
|
|
1930
|
+
const scaleRatioX = scale.x / existingScale.x;
|
|
1931
|
+
const scaleRatioY = scale.y / existingScale.y;
|
|
1932
|
+
const scaleRatioZ = scale.z / existingScale.z;
|
|
1933
|
+
result[0] = matrix[0] * scaleRatioX;
|
|
1934
|
+
result[1] = matrix[1] * scaleRatioX;
|
|
1935
|
+
result[2] = matrix[2] * scaleRatioX;
|
|
1936
|
+
result[3] = matrix[3];
|
|
1937
|
+
result[4] = matrix[4] * scaleRatioY;
|
|
1938
|
+
result[5] = matrix[5] * scaleRatioY;
|
|
1939
|
+
result[6] = matrix[6] * scaleRatioY;
|
|
1940
|
+
result[7] = matrix[7];
|
|
1941
|
+
result[8] = matrix[8] * scaleRatioZ;
|
|
1942
|
+
result[9] = matrix[9] * scaleRatioZ;
|
|
1943
|
+
result[10] = matrix[10] * scaleRatioZ;
|
|
1944
|
+
result[11] = matrix[11];
|
|
1945
|
+
result[12] = matrix[12];
|
|
1946
|
+
result[13] = matrix[13];
|
|
1947
|
+
result[14] = matrix[14];
|
|
1948
|
+
result[15] = matrix[15];
|
|
1949
|
+
return result;
|
|
1950
|
+
}
|
|
1951
|
+
/**
|
|
1952
|
+
* Computes a new matrix that replaces the scale with the provided uniform scale.
|
|
1953
|
+
* This assumes the matrix is an affine transformation.
|
|
1954
|
+
*
|
|
1955
|
+
* @param {Matrix4} matrix The matrix to use.
|
|
1956
|
+
* @param {number} scale The uniform scale that replaces the scale of the provided matrix.
|
|
1957
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
1958
|
+
* @returns {Matrix4} The modified result parameter.
|
|
1959
|
+
*
|
|
1960
|
+
* @see Matrix4.setScale
|
|
1961
|
+
* @see Matrix4.fromScale
|
|
1962
|
+
* @see Matrix4.fromUniformScale
|
|
1963
|
+
* @see Matrix4.multiplyByScale
|
|
1964
|
+
* @see Matrix4.multiplyByUniformScale
|
|
1965
|
+
* @see Matrix4.getScale
|
|
1966
|
+
*/
|
|
1967
|
+
static setUniformScale(matrix, scale, result) {
|
|
1968
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
1969
|
+
Check_default.typeOf.number("scale", scale);
|
|
1970
|
+
Check_default.typeOf.object("result", result);
|
|
1971
|
+
const existingScale = _Matrix4.getScale(matrix, scaleScratch2);
|
|
1972
|
+
const scaleRatioX = scale / existingScale.x;
|
|
1973
|
+
const scaleRatioY = scale / existingScale.y;
|
|
1974
|
+
const scaleRatioZ = scale / existingScale.z;
|
|
1975
|
+
result[0] = matrix[0] * scaleRatioX;
|
|
1976
|
+
result[1] = matrix[1] * scaleRatioX;
|
|
1977
|
+
result[2] = matrix[2] * scaleRatioX;
|
|
1978
|
+
result[3] = matrix[3];
|
|
1979
|
+
result[4] = matrix[4] * scaleRatioY;
|
|
1980
|
+
result[5] = matrix[5] * scaleRatioY;
|
|
1981
|
+
result[6] = matrix[6] * scaleRatioY;
|
|
1982
|
+
result[7] = matrix[7];
|
|
1983
|
+
result[8] = matrix[8] * scaleRatioZ;
|
|
1984
|
+
result[9] = matrix[9] * scaleRatioZ;
|
|
1985
|
+
result[10] = matrix[10] * scaleRatioZ;
|
|
1986
|
+
result[11] = matrix[11];
|
|
1987
|
+
result[12] = matrix[12];
|
|
1988
|
+
result[13] = matrix[13];
|
|
1989
|
+
result[14] = matrix[14];
|
|
1990
|
+
result[15] = matrix[15];
|
|
1991
|
+
return result;
|
|
1992
|
+
}
|
|
1993
|
+
/**
|
|
1994
|
+
* Extracts the non-uniform scale assuming the matrix is an affine transformation.
|
|
1995
|
+
*
|
|
1996
|
+
* @param {Matrix4} matrix The matrix.
|
|
1997
|
+
* @param {Cartesian3} result The object onto which to store the result.
|
|
1998
|
+
* @returns {Cartesian3} The modified result parameter
|
|
1999
|
+
*
|
|
2000
|
+
* @see Matrix4.multiplyByScale
|
|
2001
|
+
* @see Matrix4.multiplyByUniformScale
|
|
2002
|
+
* @see Matrix4.fromScale
|
|
2003
|
+
* @see Matrix4.fromUniformScale
|
|
2004
|
+
* @see Matrix4.setScale
|
|
2005
|
+
* @see Matrix4.setUniformScale
|
|
2006
|
+
*/
|
|
2007
|
+
static getScale(matrix, result) {
|
|
2008
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2009
|
+
Check_default.typeOf.object("result", result);
|
|
2010
|
+
result.x = Cartesian3_default.magnitude(
|
|
2011
|
+
Cartesian3_default.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn)
|
|
2012
|
+
);
|
|
2013
|
+
result.y = Cartesian3_default.magnitude(
|
|
2014
|
+
Cartesian3_default.fromElements(matrix[4], matrix[5], matrix[6], scratchColumn)
|
|
2015
|
+
);
|
|
2016
|
+
result.z = Cartesian3_default.magnitude(
|
|
2017
|
+
Cartesian3_default.fromElements(matrix[8], matrix[9], matrix[10], scratchColumn)
|
|
2018
|
+
);
|
|
2019
|
+
return result;
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Computes the maximum scale assuming the matrix is an affine transformation.
|
|
2023
|
+
* The maximum scale is the maximum length of the column vectors in the upper-left
|
|
2024
|
+
* 3x3 matrix.
|
|
2025
|
+
*
|
|
2026
|
+
* @param {Matrix4} matrix The matrix.
|
|
2027
|
+
* @returns {number} The maximum scale.
|
|
2028
|
+
*/
|
|
2029
|
+
static getMaximumScale(matrix) {
|
|
2030
|
+
_Matrix4.getScale(matrix, scaleScratch3);
|
|
2031
|
+
return Cartesian3_default.maximumComponent(scaleScratch3);
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* Sets the rotation assuming the matrix is an affine transformation.
|
|
2035
|
+
*
|
|
2036
|
+
* @param {Matrix4} matrix The matrix.
|
|
2037
|
+
* @param {Matrix3} rotation The rotation matrix.
|
|
2038
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2039
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2040
|
+
*
|
|
2041
|
+
* @see Matrix4.fromRotation
|
|
2042
|
+
* @see Matrix4.getRotation
|
|
2043
|
+
*/
|
|
2044
|
+
static setRotation(matrix, rotation, result) {
|
|
2045
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2046
|
+
Check_default.typeOf.object("result", result);
|
|
2047
|
+
const scale = _Matrix4.getScale(matrix, scaleScratch4);
|
|
2048
|
+
result[0] = rotation[0] * scale.x;
|
|
2049
|
+
result[1] = rotation[1] * scale.x;
|
|
2050
|
+
result[2] = rotation[2] * scale.x;
|
|
2051
|
+
result[3] = matrix[3];
|
|
2052
|
+
result[4] = rotation[3] * scale.y;
|
|
2053
|
+
result[5] = rotation[4] * scale.y;
|
|
2054
|
+
result[6] = rotation[5] * scale.y;
|
|
2055
|
+
result[7] = matrix[7];
|
|
2056
|
+
result[8] = rotation[6] * scale.z;
|
|
2057
|
+
result[9] = rotation[7] * scale.z;
|
|
2058
|
+
result[10] = rotation[8] * scale.z;
|
|
2059
|
+
result[11] = matrix[11];
|
|
2060
|
+
result[12] = matrix[12];
|
|
2061
|
+
result[13] = matrix[13];
|
|
2062
|
+
result[14] = matrix[14];
|
|
2063
|
+
result[15] = matrix[15];
|
|
2064
|
+
return result;
|
|
2065
|
+
}
|
|
2066
|
+
/**
|
|
2067
|
+
* Extracts the rotation matrix assuming the matrix is an affine transformation.
|
|
2068
|
+
*
|
|
2069
|
+
* @param {Matrix4} matrix The matrix.
|
|
2070
|
+
* @param {Matrix3} result The object onto which to store the result.
|
|
2071
|
+
* @returns {Matrix3} The modified result parameter.
|
|
2072
|
+
*
|
|
2073
|
+
* @see Matrix4.setRotation
|
|
2074
|
+
* @see Matrix4.fromRotation
|
|
2075
|
+
*/
|
|
2076
|
+
static getRotation(matrix, result) {
|
|
2077
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2078
|
+
Check_default.typeOf.object("result", result);
|
|
2079
|
+
const scale = _Matrix4.getScale(matrix, scaleScratch5);
|
|
2080
|
+
result[0] = matrix[0] / scale.x;
|
|
2081
|
+
result[1] = matrix[1] / scale.x;
|
|
2082
|
+
result[2] = matrix[2] / scale.x;
|
|
2083
|
+
result[3] = matrix[4] / scale.y;
|
|
2084
|
+
result[4] = matrix[5] / scale.y;
|
|
2085
|
+
result[5] = matrix[6] / scale.y;
|
|
2086
|
+
result[6] = matrix[8] / scale.z;
|
|
2087
|
+
result[7] = matrix[9] / scale.z;
|
|
2088
|
+
result[8] = matrix[10] / scale.z;
|
|
2089
|
+
return result;
|
|
2090
|
+
}
|
|
2091
|
+
/**
|
|
2092
|
+
* Computes the product of two matrices.
|
|
2093
|
+
*
|
|
2094
|
+
* @param {Matrix4} left The first matrix.
|
|
2095
|
+
* @param {Matrix4} right The second matrix.
|
|
2096
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2097
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2098
|
+
*/
|
|
2099
|
+
static multiply(left, right, result) {
|
|
2100
|
+
Check_default.typeOf.object("left", left);
|
|
2101
|
+
Check_default.typeOf.object("right", right);
|
|
2102
|
+
Check_default.typeOf.object("result", result);
|
|
2103
|
+
const left0 = left[0];
|
|
2104
|
+
const left1 = left[1];
|
|
2105
|
+
const left2 = left[2];
|
|
2106
|
+
const left3 = left[3];
|
|
2107
|
+
const left4 = left[4];
|
|
2108
|
+
const left5 = left[5];
|
|
2109
|
+
const left6 = left[6];
|
|
2110
|
+
const left7 = left[7];
|
|
2111
|
+
const left8 = left[8];
|
|
2112
|
+
const left9 = left[9];
|
|
2113
|
+
const left10 = left[10];
|
|
2114
|
+
const left11 = left[11];
|
|
2115
|
+
const left12 = left[12];
|
|
2116
|
+
const left13 = left[13];
|
|
2117
|
+
const left14 = left[14];
|
|
2118
|
+
const left15 = left[15];
|
|
2119
|
+
const right0 = right[0];
|
|
2120
|
+
const right1 = right[1];
|
|
2121
|
+
const right2 = right[2];
|
|
2122
|
+
const right3 = right[3];
|
|
2123
|
+
const right4 = right[4];
|
|
2124
|
+
const right5 = right[5];
|
|
2125
|
+
const right6 = right[6];
|
|
2126
|
+
const right7 = right[7];
|
|
2127
|
+
const right8 = right[8];
|
|
2128
|
+
const right9 = right[9];
|
|
2129
|
+
const right10 = right[10];
|
|
2130
|
+
const right11 = right[11];
|
|
2131
|
+
const right12 = right[12];
|
|
2132
|
+
const right13 = right[13];
|
|
2133
|
+
const right14 = right[14];
|
|
2134
|
+
const right15 = right[15];
|
|
2135
|
+
const column0Row0 = left0 * right0 + left4 * right1 + left8 * right2 + left12 * right3;
|
|
2136
|
+
const column0Row1 = left1 * right0 + left5 * right1 + left9 * right2 + left13 * right3;
|
|
2137
|
+
const column0Row2 = left2 * right0 + left6 * right1 + left10 * right2 + left14 * right3;
|
|
2138
|
+
const column0Row3 = left3 * right0 + left7 * right1 + left11 * right2 + left15 * right3;
|
|
2139
|
+
const column1Row0 = left0 * right4 + left4 * right5 + left8 * right6 + left12 * right7;
|
|
2140
|
+
const column1Row1 = left1 * right4 + left5 * right5 + left9 * right6 + left13 * right7;
|
|
2141
|
+
const column1Row2 = left2 * right4 + left6 * right5 + left10 * right6 + left14 * right7;
|
|
2142
|
+
const column1Row3 = left3 * right4 + left7 * right5 + left11 * right6 + left15 * right7;
|
|
2143
|
+
const column2Row0 = left0 * right8 + left4 * right9 + left8 * right10 + left12 * right11;
|
|
2144
|
+
const column2Row1 = left1 * right8 + left5 * right9 + left9 * right10 + left13 * right11;
|
|
2145
|
+
const column2Row2 = left2 * right8 + left6 * right9 + left10 * right10 + left14 * right11;
|
|
2146
|
+
const column2Row3 = left3 * right8 + left7 * right9 + left11 * right10 + left15 * right11;
|
|
2147
|
+
const column3Row0 = left0 * right12 + left4 * right13 + left8 * right14 + left12 * right15;
|
|
2148
|
+
const column3Row1 = left1 * right12 + left5 * right13 + left9 * right14 + left13 * right15;
|
|
2149
|
+
const column3Row2 = left2 * right12 + left6 * right13 + left10 * right14 + left14 * right15;
|
|
2150
|
+
const column3Row3 = left3 * right12 + left7 * right13 + left11 * right14 + left15 * right15;
|
|
2151
|
+
result[0] = column0Row0;
|
|
2152
|
+
result[1] = column0Row1;
|
|
2153
|
+
result[2] = column0Row2;
|
|
2154
|
+
result[3] = column0Row3;
|
|
2155
|
+
result[4] = column1Row0;
|
|
2156
|
+
result[5] = column1Row1;
|
|
2157
|
+
result[6] = column1Row2;
|
|
2158
|
+
result[7] = column1Row3;
|
|
2159
|
+
result[8] = column2Row0;
|
|
2160
|
+
result[9] = column2Row1;
|
|
2161
|
+
result[10] = column2Row2;
|
|
2162
|
+
result[11] = column2Row3;
|
|
2163
|
+
result[12] = column3Row0;
|
|
2164
|
+
result[13] = column3Row1;
|
|
2165
|
+
result[14] = column3Row2;
|
|
2166
|
+
result[15] = column3Row3;
|
|
2167
|
+
return result;
|
|
2168
|
+
}
|
|
2169
|
+
/**
|
|
2170
|
+
* Computes the sum of two matrices.
|
|
2171
|
+
*
|
|
2172
|
+
* @param {Matrix4} left The first matrix.
|
|
2173
|
+
* @param {Matrix4} right The second matrix.
|
|
2174
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2175
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2176
|
+
*/
|
|
2177
|
+
static add(left, right, result) {
|
|
2178
|
+
Check_default.typeOf.object("left", left);
|
|
2179
|
+
Check_default.typeOf.object("right", right);
|
|
2180
|
+
Check_default.typeOf.object("result", result);
|
|
2181
|
+
result[0] = left[0] + right[0];
|
|
2182
|
+
result[1] = left[1] + right[1];
|
|
2183
|
+
result[2] = left[2] + right[2];
|
|
2184
|
+
result[3] = left[3] + right[3];
|
|
2185
|
+
result[4] = left[4] + right[4];
|
|
2186
|
+
result[5] = left[5] + right[5];
|
|
2187
|
+
result[6] = left[6] + right[6];
|
|
2188
|
+
result[7] = left[7] + right[7];
|
|
2189
|
+
result[8] = left[8] + right[8];
|
|
2190
|
+
result[9] = left[9] + right[9];
|
|
2191
|
+
result[10] = left[10] + right[10];
|
|
2192
|
+
result[11] = left[11] + right[11];
|
|
2193
|
+
result[12] = left[12] + right[12];
|
|
2194
|
+
result[13] = left[13] + right[13];
|
|
2195
|
+
result[14] = left[14] + right[14];
|
|
2196
|
+
result[15] = left[15] + right[15];
|
|
2197
|
+
return result;
|
|
2198
|
+
}
|
|
2199
|
+
/**
|
|
2200
|
+
* Computes the difference of two matrices.
|
|
2201
|
+
*
|
|
2202
|
+
* @param {Matrix4} left The first matrix.
|
|
2203
|
+
* @param {Matrix4} right The second matrix.
|
|
2204
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2205
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2206
|
+
*/
|
|
2207
|
+
static subtract(left, right, result) {
|
|
2208
|
+
Check_default.typeOf.object("left", left);
|
|
2209
|
+
Check_default.typeOf.object("right", right);
|
|
2210
|
+
Check_default.typeOf.object("result", result);
|
|
2211
|
+
result[0] = left[0] - right[0];
|
|
2212
|
+
result[1] = left[1] - right[1];
|
|
2213
|
+
result[2] = left[2] - right[2];
|
|
2214
|
+
result[3] = left[3] - right[3];
|
|
2215
|
+
result[4] = left[4] - right[4];
|
|
2216
|
+
result[5] = left[5] - right[5];
|
|
2217
|
+
result[6] = left[6] - right[6];
|
|
2218
|
+
result[7] = left[7] - right[7];
|
|
2219
|
+
result[8] = left[8] - right[8];
|
|
2220
|
+
result[9] = left[9] - right[9];
|
|
2221
|
+
result[10] = left[10] - right[10];
|
|
2222
|
+
result[11] = left[11] - right[11];
|
|
2223
|
+
result[12] = left[12] - right[12];
|
|
2224
|
+
result[13] = left[13] - right[13];
|
|
2225
|
+
result[14] = left[14] - right[14];
|
|
2226
|
+
result[15] = left[15] - right[15];
|
|
2227
|
+
return result;
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Computes the product of two matrices assuming the matrices are affine transformation matrices,
|
|
2231
|
+
* where the upper left 3x3 elements are any matrix, and
|
|
2232
|
+
* the upper three elements in the fourth column are the translation.
|
|
2233
|
+
* The bottom row is assumed to be [0, 0, 0, 1].
|
|
2234
|
+
* The matrix is not verified to be in the proper form.
|
|
2235
|
+
* This method is faster than computing the product for general 4x4
|
|
2236
|
+
* matrices using {@link Matrix4.multiply}.
|
|
2237
|
+
*
|
|
2238
|
+
* @param {Matrix4} left The first matrix.
|
|
2239
|
+
* @param {Matrix4} right The second matrix.
|
|
2240
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2241
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2242
|
+
*
|
|
2243
|
+
* @example
|
|
2244
|
+
* const m1 = new Cesium.Matrix4(1.0, 6.0, 7.0, 0.0, 2.0, 5.0, 8.0, 0.0, 3.0, 4.0, 9.0, 0.0, 0.0, 0.0, 0.0, 1.0);
|
|
2245
|
+
* const m2 = Cesium.Transforms.eastNorthUpToFixedFrame(new Cesium.Cartesian3(1.0, 1.0, 1.0));
|
|
2246
|
+
* const m3 = Cesium.Matrix4.multiplyTransformation(m1, m2, new Cesium.Matrix4());
|
|
2247
|
+
*/
|
|
2248
|
+
static multiplyTransformation(left, right, result) {
|
|
2249
|
+
Check_default.typeOf.object("left", left);
|
|
2250
|
+
Check_default.typeOf.object("right", right);
|
|
2251
|
+
Check_default.typeOf.object("result", result);
|
|
2252
|
+
const left0 = left[0];
|
|
2253
|
+
const left1 = left[1];
|
|
2254
|
+
const left2 = left[2];
|
|
2255
|
+
const left4 = left[4];
|
|
2256
|
+
const left5 = left[5];
|
|
2257
|
+
const left6 = left[6];
|
|
2258
|
+
const left8 = left[8];
|
|
2259
|
+
const left9 = left[9];
|
|
2260
|
+
const left10 = left[10];
|
|
2261
|
+
const left12 = left[12];
|
|
2262
|
+
const left13 = left[13];
|
|
2263
|
+
const left14 = left[14];
|
|
2264
|
+
const right0 = right[0];
|
|
2265
|
+
const right1 = right[1];
|
|
2266
|
+
const right2 = right[2];
|
|
2267
|
+
const right4 = right[4];
|
|
2268
|
+
const right5 = right[5];
|
|
2269
|
+
const right6 = right[6];
|
|
2270
|
+
const right8 = right[8];
|
|
2271
|
+
const right9 = right[9];
|
|
2272
|
+
const right10 = right[10];
|
|
2273
|
+
const right12 = right[12];
|
|
2274
|
+
const right13 = right[13];
|
|
2275
|
+
const right14 = right[14];
|
|
2276
|
+
const column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;
|
|
2277
|
+
const column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;
|
|
2278
|
+
const column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;
|
|
2279
|
+
const column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;
|
|
2280
|
+
const column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;
|
|
2281
|
+
const column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;
|
|
2282
|
+
const column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;
|
|
2283
|
+
const column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;
|
|
2284
|
+
const column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;
|
|
2285
|
+
const column3Row0 = left0 * right12 + left4 * right13 + left8 * right14 + left12;
|
|
2286
|
+
const column3Row1 = left1 * right12 + left5 * right13 + left9 * right14 + left13;
|
|
2287
|
+
const column3Row2 = left2 * right12 + left6 * right13 + left10 * right14 + left14;
|
|
2288
|
+
result[0] = column0Row0;
|
|
2289
|
+
result[1] = column0Row1;
|
|
2290
|
+
result[2] = column0Row2;
|
|
2291
|
+
result[3] = 0;
|
|
2292
|
+
result[4] = column1Row0;
|
|
2293
|
+
result[5] = column1Row1;
|
|
2294
|
+
result[6] = column1Row2;
|
|
2295
|
+
result[7] = 0;
|
|
2296
|
+
result[8] = column2Row0;
|
|
2297
|
+
result[9] = column2Row1;
|
|
2298
|
+
result[10] = column2Row2;
|
|
2299
|
+
result[11] = 0;
|
|
2300
|
+
result[12] = column3Row0;
|
|
2301
|
+
result[13] = column3Row1;
|
|
2302
|
+
result[14] = column3Row2;
|
|
2303
|
+
result[15] = 1;
|
|
2304
|
+
return result;
|
|
2305
|
+
}
|
|
2306
|
+
/**
|
|
2307
|
+
* Multiplies a transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
|
|
2308
|
+
* by a 3x3 rotation matrix. This is an optimization
|
|
2309
|
+
* for <code>Matrix4.multiply(m, Matrix4.fromRotationTranslation(rotation), m);</code> with less allocations and arithmetic operations.
|
|
2310
|
+
*
|
|
2311
|
+
* @param {Matrix4} matrix The matrix on the left-hand side.
|
|
2312
|
+
* @param {Matrix3} rotation The 3x3 rotation matrix on the right-hand side.
|
|
2313
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2314
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2315
|
+
*
|
|
2316
|
+
* @example
|
|
2317
|
+
* // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromRotationTranslation(rotation), m);
|
|
2318
|
+
* Cesium.Matrix4.multiplyByMatrix3(m, rotation, m);
|
|
2319
|
+
*/
|
|
2320
|
+
static multiplyByMatrix3(matrix, rotation, result) {
|
|
2321
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2322
|
+
Check_default.typeOf.object("rotation", rotation);
|
|
2323
|
+
Check_default.typeOf.object("result", result);
|
|
2324
|
+
const left0 = matrix[0];
|
|
2325
|
+
const left1 = matrix[1];
|
|
2326
|
+
const left2 = matrix[2];
|
|
2327
|
+
const left4 = matrix[4];
|
|
2328
|
+
const left5 = matrix[5];
|
|
2329
|
+
const left6 = matrix[6];
|
|
2330
|
+
const left8 = matrix[8];
|
|
2331
|
+
const left9 = matrix[9];
|
|
2332
|
+
const left10 = matrix[10];
|
|
2333
|
+
const right0 = rotation[0];
|
|
2334
|
+
const right1 = rotation[1];
|
|
2335
|
+
const right2 = rotation[2];
|
|
2336
|
+
const right4 = rotation[3];
|
|
2337
|
+
const right5 = rotation[4];
|
|
2338
|
+
const right6 = rotation[5];
|
|
2339
|
+
const right8 = rotation[6];
|
|
2340
|
+
const right9 = rotation[7];
|
|
2341
|
+
const right10 = rotation[8];
|
|
2342
|
+
const column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;
|
|
2343
|
+
const column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;
|
|
2344
|
+
const column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;
|
|
2345
|
+
const column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;
|
|
2346
|
+
const column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;
|
|
2347
|
+
const column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;
|
|
2348
|
+
const column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;
|
|
2349
|
+
const column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;
|
|
2350
|
+
const column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;
|
|
2351
|
+
result[0] = column0Row0;
|
|
2352
|
+
result[1] = column0Row1;
|
|
2353
|
+
result[2] = column0Row2;
|
|
2354
|
+
result[3] = 0;
|
|
2355
|
+
result[4] = column1Row0;
|
|
2356
|
+
result[5] = column1Row1;
|
|
2357
|
+
result[6] = column1Row2;
|
|
2358
|
+
result[7] = 0;
|
|
2359
|
+
result[8] = column2Row0;
|
|
2360
|
+
result[9] = column2Row1;
|
|
2361
|
+
result[10] = column2Row2;
|
|
2362
|
+
result[11] = 0;
|
|
2363
|
+
result[12] = matrix[12];
|
|
2364
|
+
result[13] = matrix[13];
|
|
2365
|
+
result[14] = matrix[14];
|
|
2366
|
+
result[15] = matrix[15];
|
|
2367
|
+
return result;
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* Multiplies a transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
|
|
2371
|
+
* by an implicit translation matrix defined by a {@link Cartesian3}. This is an optimization
|
|
2372
|
+
* for <code>Matrix4.multiply(m, Matrix4.fromTranslation(position), m);</code> with less allocations and arithmetic operations.
|
|
2373
|
+
*
|
|
2374
|
+
* @param {Matrix4} matrix The matrix on the left-hand side.
|
|
2375
|
+
* @param {Cartesian3} translation The translation on the right-hand side.
|
|
2376
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2377
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2378
|
+
*
|
|
2379
|
+
* @example
|
|
2380
|
+
* // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromTranslation(position), m);
|
|
2381
|
+
* Cesium.Matrix4.multiplyByTranslation(m, position, m);
|
|
2382
|
+
*/
|
|
2383
|
+
static multiplyByTranslation(matrix, translation, result) {
|
|
2384
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2385
|
+
Check_default.typeOf.object("translation", translation);
|
|
2386
|
+
Check_default.typeOf.object("result", result);
|
|
2387
|
+
const x = translation.x;
|
|
2388
|
+
const y = translation.y;
|
|
2389
|
+
const z = translation.z;
|
|
2390
|
+
const tx = x * matrix[0] + y * matrix[4] + z * matrix[8] + matrix[12];
|
|
2391
|
+
const ty = x * matrix[1] + y * matrix[5] + z * matrix[9] + matrix[13];
|
|
2392
|
+
const tz = x * matrix[2] + y * matrix[6] + z * matrix[10] + matrix[14];
|
|
2393
|
+
result[0] = matrix[0];
|
|
2394
|
+
result[1] = matrix[1];
|
|
2395
|
+
result[2] = matrix[2];
|
|
2396
|
+
result[3] = matrix[3];
|
|
2397
|
+
result[4] = matrix[4];
|
|
2398
|
+
result[5] = matrix[5];
|
|
2399
|
+
result[6] = matrix[6];
|
|
2400
|
+
result[7] = matrix[7];
|
|
2401
|
+
result[8] = matrix[8];
|
|
2402
|
+
result[9] = matrix[9];
|
|
2403
|
+
result[10] = matrix[10];
|
|
2404
|
+
result[11] = matrix[11];
|
|
2405
|
+
result[12] = tx;
|
|
2406
|
+
result[13] = ty;
|
|
2407
|
+
result[14] = tz;
|
|
2408
|
+
result[15] = matrix[15];
|
|
2409
|
+
return result;
|
|
2410
|
+
}
|
|
2411
|
+
/**
|
|
2412
|
+
* Multiplies an affine transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
|
|
2413
|
+
* by an implicit non-uniform scale matrix. This is an optimization
|
|
2414
|
+
* for <code>Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);</code>, where
|
|
2415
|
+
* <code>m</code> must be an affine matrix.
|
|
2416
|
+
* This function performs fewer allocations and arithmetic operations.
|
|
2417
|
+
*
|
|
2418
|
+
* @param {Matrix4} matrix The affine matrix on the left-hand side.
|
|
2419
|
+
* @param {Cartesian3} scale The non-uniform scale on the right-hand side.
|
|
2420
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2421
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2422
|
+
*
|
|
2423
|
+
*
|
|
2424
|
+
* @example
|
|
2425
|
+
* // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromScale(scale), m);
|
|
2426
|
+
* Cesium.Matrix4.multiplyByScale(m, scale, m);
|
|
2427
|
+
*
|
|
2428
|
+
* @see Matrix4.multiplyByUniformScale
|
|
2429
|
+
* @see Matrix4.fromScale
|
|
2430
|
+
* @see Matrix4.fromUniformScale
|
|
2431
|
+
* @see Matrix4.setScale
|
|
2432
|
+
* @see Matrix4.setUniformScale
|
|
2433
|
+
* @see Matrix4.getScale
|
|
2434
|
+
*/
|
|
2435
|
+
static multiplyByScale(matrix, scale, result) {
|
|
2436
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2437
|
+
Check_default.typeOf.object("scale", scale);
|
|
2438
|
+
Check_default.typeOf.object("result", result);
|
|
2439
|
+
const scaleX = scale.x;
|
|
2440
|
+
const scaleY = scale.y;
|
|
2441
|
+
const scaleZ = scale.z;
|
|
2442
|
+
if (scaleX === 1 && scaleY === 1 && scaleZ === 1) {
|
|
2443
|
+
return _Matrix4.clone(matrix, result);
|
|
2444
|
+
}
|
|
2445
|
+
result[0] = scaleX * matrix[0];
|
|
2446
|
+
result[1] = scaleX * matrix[1];
|
|
2447
|
+
result[2] = scaleX * matrix[2];
|
|
2448
|
+
result[3] = matrix[3];
|
|
2449
|
+
result[4] = scaleY * matrix[4];
|
|
2450
|
+
result[5] = scaleY * matrix[5];
|
|
2451
|
+
result[6] = scaleY * matrix[6];
|
|
2452
|
+
result[7] = matrix[7];
|
|
2453
|
+
result[8] = scaleZ * matrix[8];
|
|
2454
|
+
result[9] = scaleZ * matrix[9];
|
|
2455
|
+
result[10] = scaleZ * matrix[10];
|
|
2456
|
+
result[11] = matrix[11];
|
|
2457
|
+
result[12] = matrix[12];
|
|
2458
|
+
result[13] = matrix[13];
|
|
2459
|
+
result[14] = matrix[14];
|
|
2460
|
+
result[15] = matrix[15];
|
|
2461
|
+
return result;
|
|
2462
|
+
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Computes the product of a matrix times a uniform scale, as if the scale were a scale matrix.
|
|
2465
|
+
*
|
|
2466
|
+
* @param {Matrix4} matrix The matrix on the left-hand side.
|
|
2467
|
+
* @param {number} scale The uniform scale on the right-hand side.
|
|
2468
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2469
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2470
|
+
*
|
|
2471
|
+
* @example
|
|
2472
|
+
* // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromUniformScale(scale), m);
|
|
2473
|
+
* Cesium.Matrix4.multiplyByUniformScale(m, scale, m);
|
|
2474
|
+
*
|
|
2475
|
+
* @see Matrix4.multiplyByScale
|
|
2476
|
+
* @see Matrix4.fromScale
|
|
2477
|
+
* @see Matrix4.fromUniformScale
|
|
2478
|
+
* @see Matrix4.setScale
|
|
2479
|
+
* @see Matrix4.setUniformScale
|
|
2480
|
+
* @see Matrix4.getScale
|
|
2481
|
+
*/
|
|
2482
|
+
static multiplyByUniformScale(matrix, scale, result) {
|
|
2483
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2484
|
+
Check_default.typeOf.number("scale", scale);
|
|
2485
|
+
Check_default.typeOf.object("result", result);
|
|
2486
|
+
result[0] = matrix[0] * scale;
|
|
2487
|
+
result[1] = matrix[1] * scale;
|
|
2488
|
+
result[2] = matrix[2] * scale;
|
|
2489
|
+
result[3] = matrix[3];
|
|
2490
|
+
result[4] = matrix[4] * scale;
|
|
2491
|
+
result[5] = matrix[5] * scale;
|
|
2492
|
+
result[6] = matrix[6] * scale;
|
|
2493
|
+
result[7] = matrix[7];
|
|
2494
|
+
result[8] = matrix[8] * scale;
|
|
2495
|
+
result[9] = matrix[9] * scale;
|
|
2496
|
+
result[10] = matrix[10] * scale;
|
|
2497
|
+
result[11] = matrix[11];
|
|
2498
|
+
result[12] = matrix[12];
|
|
2499
|
+
result[13] = matrix[13];
|
|
2500
|
+
result[14] = matrix[14];
|
|
2501
|
+
result[15] = matrix[15];
|
|
2502
|
+
return result;
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Computes the product of a matrix and a column vector.
|
|
2506
|
+
*
|
|
2507
|
+
* @param {Matrix4} matrix The matrix.
|
|
2508
|
+
* @param {Cartesian4} cartesian The vector.
|
|
2509
|
+
* @param {Cartesian4} result The object onto which to store the result.
|
|
2510
|
+
* @returns {Cartesian4} The modified result parameter.
|
|
2511
|
+
*/
|
|
2512
|
+
static multiplyByVector(matrix, cartesian, result) {
|
|
2513
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2514
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
2515
|
+
Check_default.typeOf.object("result", result);
|
|
2516
|
+
const vX = cartesian.x;
|
|
2517
|
+
const vY = cartesian.y;
|
|
2518
|
+
const vZ = cartesian.z;
|
|
2519
|
+
const vW = cartesian.w;
|
|
2520
|
+
const x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12] * vW;
|
|
2521
|
+
const y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13] * vW;
|
|
2522
|
+
const z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14] * vW;
|
|
2523
|
+
const w = matrix[3] * vX + matrix[7] * vY + matrix[11] * vZ + matrix[15] * vW;
|
|
2524
|
+
result.x = x;
|
|
2525
|
+
result.y = y;
|
|
2526
|
+
result.z = z;
|
|
2527
|
+
result.w = w;
|
|
2528
|
+
return result;
|
|
2529
|
+
}
|
|
2530
|
+
/**
|
|
2531
|
+
* Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}
|
|
2532
|
+
* with a {@link Cartesian4} with a <code>w</code> component of zero.
|
|
2533
|
+
*
|
|
2534
|
+
* @param {Matrix4} matrix The matrix.
|
|
2535
|
+
* @param {Cartesian3} cartesian The point.
|
|
2536
|
+
* @param {Cartesian3} result The object onto which to store the result.
|
|
2537
|
+
* @returns {Cartesian3} The modified result parameter.
|
|
2538
|
+
*
|
|
2539
|
+
* @example
|
|
2540
|
+
* const p = new Cesium.Cartesian3(1.0, 2.0, 3.0);
|
|
2541
|
+
* const result = Cesium.Matrix4.multiplyByPointAsVector(matrix, p, new Cesium.Cartesian3());
|
|
2542
|
+
* // A shortcut for
|
|
2543
|
+
* // Cartesian3 p = ...
|
|
2544
|
+
* // Cesium.Matrix4.multiplyByVector(matrix, new Cesium.Cartesian4(p.x, p.y, p.z, 0.0), result);
|
|
2545
|
+
*/
|
|
2546
|
+
static multiplyByPointAsVector(matrix, cartesian, result) {
|
|
2547
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2548
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
2549
|
+
Check_default.typeOf.object("result", result);
|
|
2550
|
+
const vX = cartesian.x;
|
|
2551
|
+
const vY = cartesian.y;
|
|
2552
|
+
const vZ = cartesian.z;
|
|
2553
|
+
const x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ;
|
|
2554
|
+
const y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ;
|
|
2555
|
+
const z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ;
|
|
2556
|
+
result.x = x;
|
|
2557
|
+
result.y = y;
|
|
2558
|
+
result.z = z;
|
|
2559
|
+
return result;
|
|
2560
|
+
}
|
|
2561
|
+
/**
|
|
2562
|
+
* Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}
|
|
2563
|
+
* with a {@link Cartesian4} with a <code>w</code> component of 1, but returns a {@link Cartesian3} instead of a {@link Cartesian4}.
|
|
2564
|
+
*
|
|
2565
|
+
* @param {Matrix4} matrix The matrix.
|
|
2566
|
+
* @param {Cartesian3} cartesian The point.
|
|
2567
|
+
* @param {Cartesian3} result The object onto which to store the result.
|
|
2568
|
+
* @returns {Cartesian3} The modified result parameter.
|
|
2569
|
+
*
|
|
2570
|
+
* @example
|
|
2571
|
+
* const p = new Cesium.Cartesian3(1.0, 2.0, 3.0);
|
|
2572
|
+
* const result = Cesium.Matrix4.multiplyByPoint(matrix, p, new Cesium.Cartesian3());
|
|
2573
|
+
*/
|
|
2574
|
+
static multiplyByPoint(matrix, cartesian, result) {
|
|
2575
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2576
|
+
Check_default.typeOf.object("cartesian", cartesian);
|
|
2577
|
+
Check_default.typeOf.object("result", result);
|
|
2578
|
+
const vX = cartesian.x;
|
|
2579
|
+
const vY = cartesian.y;
|
|
2580
|
+
const vZ = cartesian.z;
|
|
2581
|
+
const x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12];
|
|
2582
|
+
const y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13];
|
|
2583
|
+
const z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14];
|
|
2584
|
+
result.x = x;
|
|
2585
|
+
result.y = y;
|
|
2586
|
+
result.z = z;
|
|
2587
|
+
return result;
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Computes the product of a matrix and a scalar.
|
|
2591
|
+
*
|
|
2592
|
+
* @param {Matrix4} matrix The matrix.
|
|
2593
|
+
* @param {number} scalar The number to multiply by.
|
|
2594
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2595
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2596
|
+
*
|
|
2597
|
+
* @example
|
|
2598
|
+
* //create a Matrix4 instance which is a scaled version of the supplied Matrix4
|
|
2599
|
+
* // m = [10.0, 11.0, 12.0, 13.0]
|
|
2600
|
+
* // [14.0, 15.0, 16.0, 17.0]
|
|
2601
|
+
* // [18.0, 19.0, 20.0, 21.0]
|
|
2602
|
+
* // [22.0, 23.0, 24.0, 25.0]
|
|
2603
|
+
*
|
|
2604
|
+
* const a = Cesium.Matrix4.multiplyByScalar(m, -2, new Cesium.Matrix4());
|
|
2605
|
+
*
|
|
2606
|
+
* // m remains the same
|
|
2607
|
+
* // a = [-20.0, -22.0, -24.0, -26.0]
|
|
2608
|
+
* // [-28.0, -30.0, -32.0, -34.0]
|
|
2609
|
+
* // [-36.0, -38.0, -40.0, -42.0]
|
|
2610
|
+
* // [-44.0, -46.0, -48.0, -50.0]
|
|
2611
|
+
*/
|
|
2612
|
+
static multiplyByScalar(matrix, scalar, result) {
|
|
2613
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2614
|
+
Check_default.typeOf.number("scalar", scalar);
|
|
2615
|
+
Check_default.typeOf.object("result", result);
|
|
2616
|
+
result[0] = matrix[0] * scalar;
|
|
2617
|
+
result[1] = matrix[1] * scalar;
|
|
2618
|
+
result[2] = matrix[2] * scalar;
|
|
2619
|
+
result[3] = matrix[3] * scalar;
|
|
2620
|
+
result[4] = matrix[4] * scalar;
|
|
2621
|
+
result[5] = matrix[5] * scalar;
|
|
2622
|
+
result[6] = matrix[6] * scalar;
|
|
2623
|
+
result[7] = matrix[7] * scalar;
|
|
2624
|
+
result[8] = matrix[8] * scalar;
|
|
2625
|
+
result[9] = matrix[9] * scalar;
|
|
2626
|
+
result[10] = matrix[10] * scalar;
|
|
2627
|
+
result[11] = matrix[11] * scalar;
|
|
2628
|
+
result[12] = matrix[12] * scalar;
|
|
2629
|
+
result[13] = matrix[13] * scalar;
|
|
2630
|
+
result[14] = matrix[14] * scalar;
|
|
2631
|
+
result[15] = matrix[15] * scalar;
|
|
2632
|
+
return result;
|
|
2633
|
+
}
|
|
2634
|
+
/**
|
|
2635
|
+
* Computes a negated copy of the provided matrix.
|
|
2636
|
+
*
|
|
2637
|
+
* @param {Matrix4} matrix The matrix to negate.
|
|
2638
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2639
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2640
|
+
*
|
|
2641
|
+
* @example
|
|
2642
|
+
* //create a new Matrix4 instance which is a negation of a Matrix4
|
|
2643
|
+
* // m = [10.0, 11.0, 12.0, 13.0]
|
|
2644
|
+
* // [14.0, 15.0, 16.0, 17.0]
|
|
2645
|
+
* // [18.0, 19.0, 20.0, 21.0]
|
|
2646
|
+
* // [22.0, 23.0, 24.0, 25.0]
|
|
2647
|
+
*
|
|
2648
|
+
* const a = Cesium.Matrix4.negate(m, new Cesium.Matrix4());
|
|
2649
|
+
*
|
|
2650
|
+
* // m remains the same
|
|
2651
|
+
* // a = [-10.0, -11.0, -12.0, -13.0]
|
|
2652
|
+
* // [-14.0, -15.0, -16.0, -17.0]
|
|
2653
|
+
* // [-18.0, -19.0, -20.0, -21.0]
|
|
2654
|
+
* // [-22.0, -23.0, -24.0, -25.0]
|
|
2655
|
+
*/
|
|
2656
|
+
static negate(matrix, result) {
|
|
2657
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2658
|
+
Check_default.typeOf.object("result", result);
|
|
2659
|
+
result[0] = -matrix[0];
|
|
2660
|
+
result[1] = -matrix[1];
|
|
2661
|
+
result[2] = -matrix[2];
|
|
2662
|
+
result[3] = -matrix[3];
|
|
2663
|
+
result[4] = -matrix[4];
|
|
2664
|
+
result[5] = -matrix[5];
|
|
2665
|
+
result[6] = -matrix[6];
|
|
2666
|
+
result[7] = -matrix[7];
|
|
2667
|
+
result[8] = -matrix[8];
|
|
2668
|
+
result[9] = -matrix[9];
|
|
2669
|
+
result[10] = -matrix[10];
|
|
2670
|
+
result[11] = -matrix[11];
|
|
2671
|
+
result[12] = -matrix[12];
|
|
2672
|
+
result[13] = -matrix[13];
|
|
2673
|
+
result[14] = -matrix[14];
|
|
2674
|
+
result[15] = -matrix[15];
|
|
2675
|
+
return result;
|
|
2676
|
+
}
|
|
2677
|
+
/**
|
|
2678
|
+
* Computes the transpose of the provided matrix.
|
|
2679
|
+
*
|
|
2680
|
+
* @param {Matrix4} matrix The matrix to transpose.
|
|
2681
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2682
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2683
|
+
*
|
|
2684
|
+
* @example
|
|
2685
|
+
* //returns transpose of a Matrix4
|
|
2686
|
+
* // m = [10.0, 11.0, 12.0, 13.0]
|
|
2687
|
+
* // [14.0, 15.0, 16.0, 17.0]
|
|
2688
|
+
* // [18.0, 19.0, 20.0, 21.0]
|
|
2689
|
+
* // [22.0, 23.0, 24.0, 25.0]
|
|
2690
|
+
*
|
|
2691
|
+
* const a = Cesium.Matrix4.transpose(m, new Cesium.Matrix4());
|
|
2692
|
+
*
|
|
2693
|
+
* // m remains the same
|
|
2694
|
+
* // a = [10.0, 14.0, 18.0, 22.0]
|
|
2695
|
+
* // [11.0, 15.0, 19.0, 23.0]
|
|
2696
|
+
* // [12.0, 16.0, 20.0, 24.0]
|
|
2697
|
+
* // [13.0, 17.0, 21.0, 25.0]
|
|
2698
|
+
*/
|
|
2699
|
+
static transpose(matrix, result) {
|
|
2700
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2701
|
+
Check_default.typeOf.object("result", result);
|
|
2702
|
+
const matrix1 = matrix[1];
|
|
2703
|
+
const matrix2 = matrix[2];
|
|
2704
|
+
const matrix3 = matrix[3];
|
|
2705
|
+
const matrix6 = matrix[6];
|
|
2706
|
+
const matrix7 = matrix[7];
|
|
2707
|
+
const matrix11 = matrix[11];
|
|
2708
|
+
result[0] = matrix[0];
|
|
2709
|
+
result[1] = matrix[4];
|
|
2710
|
+
result[2] = matrix[8];
|
|
2711
|
+
result[3] = matrix[12];
|
|
2712
|
+
result[4] = matrix1;
|
|
2713
|
+
result[5] = matrix[5];
|
|
2714
|
+
result[6] = matrix[9];
|
|
2715
|
+
result[7] = matrix[13];
|
|
2716
|
+
result[8] = matrix2;
|
|
2717
|
+
result[9] = matrix6;
|
|
2718
|
+
result[10] = matrix[10];
|
|
2719
|
+
result[11] = matrix[14];
|
|
2720
|
+
result[12] = matrix3;
|
|
2721
|
+
result[13] = matrix7;
|
|
2722
|
+
result[14] = matrix11;
|
|
2723
|
+
result[15] = matrix[15];
|
|
2724
|
+
return result;
|
|
2725
|
+
}
|
|
2726
|
+
/**
|
|
2727
|
+
* Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
|
|
2728
|
+
*
|
|
2729
|
+
* @param {Matrix4} matrix The matrix with signed elements.
|
|
2730
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2731
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2732
|
+
*/
|
|
2733
|
+
static abs(matrix, result) {
|
|
2734
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2735
|
+
Check_default.typeOf.object("result", result);
|
|
2736
|
+
result[0] = Math.abs(matrix[0]);
|
|
2737
|
+
result[1] = Math.abs(matrix[1]);
|
|
2738
|
+
result[2] = Math.abs(matrix[2]);
|
|
2739
|
+
result[3] = Math.abs(matrix[3]);
|
|
2740
|
+
result[4] = Math.abs(matrix[4]);
|
|
2741
|
+
result[5] = Math.abs(matrix[5]);
|
|
2742
|
+
result[6] = Math.abs(matrix[6]);
|
|
2743
|
+
result[7] = Math.abs(matrix[7]);
|
|
2744
|
+
result[8] = Math.abs(matrix[8]);
|
|
2745
|
+
result[9] = Math.abs(matrix[9]);
|
|
2746
|
+
result[10] = Math.abs(matrix[10]);
|
|
2747
|
+
result[11] = Math.abs(matrix[11]);
|
|
2748
|
+
result[12] = Math.abs(matrix[12]);
|
|
2749
|
+
result[13] = Math.abs(matrix[13]);
|
|
2750
|
+
result[14] = Math.abs(matrix[14]);
|
|
2751
|
+
result[15] = Math.abs(matrix[15]);
|
|
2752
|
+
return result;
|
|
2753
|
+
}
|
|
2754
|
+
/**
|
|
2755
|
+
* Compares the provided matrices componentwise and returns
|
|
2756
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
2757
|
+
*
|
|
2758
|
+
* @param {Matrix4} [left] The first matrix.
|
|
2759
|
+
* @param {Matrix4} [right] The second matrix.
|
|
2760
|
+
* @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
|
|
2761
|
+
*
|
|
2762
|
+
* @example
|
|
2763
|
+
* //compares two Matrix4 instances
|
|
2764
|
+
*
|
|
2765
|
+
* // a = [10.0, 14.0, 18.0, 22.0]
|
|
2766
|
+
* // [11.0, 15.0, 19.0, 23.0]
|
|
2767
|
+
* // [12.0, 16.0, 20.0, 24.0]
|
|
2768
|
+
* // [13.0, 17.0, 21.0, 25.0]
|
|
2769
|
+
*
|
|
2770
|
+
* // b = [10.0, 14.0, 18.0, 22.0]
|
|
2771
|
+
* // [11.0, 15.0, 19.0, 23.0]
|
|
2772
|
+
* // [12.0, 16.0, 20.0, 24.0]
|
|
2773
|
+
* // [13.0, 17.0, 21.0, 25.0]
|
|
2774
|
+
*
|
|
2775
|
+
* if(Cesium.Matrix4.equals(a,b)) {
|
|
2776
|
+
* console.log("Both matrices are equal");
|
|
2777
|
+
* } else {
|
|
2778
|
+
* console.log("They are not equal");
|
|
2779
|
+
* }
|
|
2780
|
+
*
|
|
2781
|
+
* //Prints "Both matrices are equal" on the console
|
|
2782
|
+
*/
|
|
2783
|
+
static equals(left, right) {
|
|
2784
|
+
return left === right || defined_default(left) && defined_default(right) && // Translation
|
|
2785
|
+
left[12] === right[12] && left[13] === right[13] && left[14] === right[14] && // Rotation/scale
|
|
2786
|
+
left[0] === right[0] && left[1] === right[1] && left[2] === right[2] && left[4] === right[4] && left[5] === right[5] && left[6] === right[6] && left[8] === right[8] && left[9] === right[9] && left[10] === right[10] && // Bottom row
|
|
2787
|
+
left[3] === right[3] && left[7] === right[7] && left[11] === right[11] && left[15] === right[15];
|
|
2788
|
+
}
|
|
2789
|
+
/**
|
|
2790
|
+
* Compares the provided matrices componentwise and returns
|
|
2791
|
+
* <code>true</code> if they are within the provided epsilon,
|
|
2792
|
+
* <code>false</code> otherwise.
|
|
2793
|
+
*
|
|
2794
|
+
* @param {Matrix4} [left] The first matrix.
|
|
2795
|
+
* @param {Matrix4} [right] The second matrix.
|
|
2796
|
+
* @param {number} [epsilon=0] The epsilon to use for equality testing.
|
|
2797
|
+
* @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
|
|
2798
|
+
*
|
|
2799
|
+
* @example
|
|
2800
|
+
* //compares two Matrix4 instances
|
|
2801
|
+
*
|
|
2802
|
+
* // a = [10.5, 14.5, 18.5, 22.5]
|
|
2803
|
+
* // [11.5, 15.5, 19.5, 23.5]
|
|
2804
|
+
* // [12.5, 16.5, 20.5, 24.5]
|
|
2805
|
+
* // [13.5, 17.5, 21.5, 25.5]
|
|
2806
|
+
*
|
|
2807
|
+
* // b = [10.0, 14.0, 18.0, 22.0]
|
|
2808
|
+
* // [11.0, 15.0, 19.0, 23.0]
|
|
2809
|
+
* // [12.0, 16.0, 20.0, 24.0]
|
|
2810
|
+
* // [13.0, 17.0, 21.0, 25.0]
|
|
2811
|
+
*
|
|
2812
|
+
* if(Cesium.Matrix4.equalsEpsilon(a,b,0.1)){
|
|
2813
|
+
* console.log("Difference between both the matrices is less than 0.1");
|
|
2814
|
+
* } else {
|
|
2815
|
+
* console.log("Difference between both the matrices is not less than 0.1");
|
|
2816
|
+
* }
|
|
2817
|
+
*
|
|
2818
|
+
* //Prints "Difference between both the matrices is not less than 0.1" on the console
|
|
2819
|
+
*/
|
|
2820
|
+
static equalsEpsilon(left, right, epsilon) {
|
|
2821
|
+
epsilon = epsilon ?? 0;
|
|
2822
|
+
return left === right || defined_default(left) && defined_default(right) && Math.abs(left[0] - right[0]) <= epsilon && Math.abs(left[1] - right[1]) <= epsilon && Math.abs(left[2] - right[2]) <= epsilon && Math.abs(left[3] - right[3]) <= epsilon && Math.abs(left[4] - right[4]) <= epsilon && Math.abs(left[5] - right[5]) <= epsilon && Math.abs(left[6] - right[6]) <= epsilon && Math.abs(left[7] - right[7]) <= epsilon && Math.abs(left[8] - right[8]) <= epsilon && Math.abs(left[9] - right[9]) <= epsilon && Math.abs(left[10] - right[10]) <= epsilon && Math.abs(left[11] - right[11]) <= epsilon && Math.abs(left[12] - right[12]) <= epsilon && Math.abs(left[13] - right[13]) <= epsilon && Math.abs(left[14] - right[14]) <= epsilon && Math.abs(left[15] - right[15]) <= epsilon;
|
|
2823
|
+
}
|
|
2824
|
+
/**
|
|
2825
|
+
* Gets the translation portion of the provided matrix, assuming the matrix is an affine transformation matrix.
|
|
2826
|
+
*
|
|
2827
|
+
* @param {Matrix4} matrix The matrix to use.
|
|
2828
|
+
* @param {Cartesian3} result The object onto which to store the result.
|
|
2829
|
+
* @returns {Cartesian3} The modified result parameter.
|
|
2830
|
+
*/
|
|
2831
|
+
static getTranslation(matrix, result) {
|
|
2832
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2833
|
+
Check_default.typeOf.object("result", result);
|
|
2834
|
+
result.x = matrix[12];
|
|
2835
|
+
result.y = matrix[13];
|
|
2836
|
+
result.z = matrix[14];
|
|
2837
|
+
return result;
|
|
2838
|
+
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Gets the upper left 3x3 matrix of the provided matrix.
|
|
2841
|
+
*
|
|
2842
|
+
* @param {Matrix4} matrix The matrix to use.
|
|
2843
|
+
* @param {Matrix3} result The object onto which to store the result.
|
|
2844
|
+
* @returns {Matrix3} The modified result parameter.
|
|
2845
|
+
*
|
|
2846
|
+
* @example
|
|
2847
|
+
* // returns a Matrix3 instance from a Matrix4 instance
|
|
2848
|
+
*
|
|
2849
|
+
* // m = [10.0, 14.0, 18.0, 22.0]
|
|
2850
|
+
* // [11.0, 15.0, 19.0, 23.0]
|
|
2851
|
+
* // [12.0, 16.0, 20.0, 24.0]
|
|
2852
|
+
* // [13.0, 17.0, 21.0, 25.0]
|
|
2853
|
+
*
|
|
2854
|
+
* const b = new Cesium.Matrix3();
|
|
2855
|
+
* Cesium.Matrix4.getMatrix3(m,b);
|
|
2856
|
+
*
|
|
2857
|
+
* // b = [10.0, 14.0, 18.0]
|
|
2858
|
+
* // [11.0, 15.0, 19.0]
|
|
2859
|
+
* // [12.0, 16.0, 20.0]
|
|
2860
|
+
*/
|
|
2861
|
+
static getMatrix3(matrix, result) {
|
|
2862
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2863
|
+
Check_default.typeOf.object("result", result);
|
|
2864
|
+
result[0] = matrix[0];
|
|
2865
|
+
result[1] = matrix[1];
|
|
2866
|
+
result[2] = matrix[2];
|
|
2867
|
+
result[3] = matrix[4];
|
|
2868
|
+
result[4] = matrix[5];
|
|
2869
|
+
result[5] = matrix[6];
|
|
2870
|
+
result[6] = matrix[8];
|
|
2871
|
+
result[7] = matrix[9];
|
|
2872
|
+
result[8] = matrix[10];
|
|
2873
|
+
return result;
|
|
2874
|
+
}
|
|
2875
|
+
/**
|
|
2876
|
+
* Computes the inverse of the provided matrix using Cramers Rule.
|
|
2877
|
+
* If the determinant is zero, the matrix can not be inverted, and an exception is thrown.
|
|
2878
|
+
* If the matrix is a proper rigid transformation, it is more efficient
|
|
2879
|
+
* to invert it with {@link Matrix4.inverseTransformation}.
|
|
2880
|
+
*
|
|
2881
|
+
* @param {Matrix4} matrix The matrix to invert.
|
|
2882
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
2883
|
+
* @returns {Matrix4} The modified result parameter.
|
|
2884
|
+
*
|
|
2885
|
+
* @exception {RuntimeError} matrix is not invertible because its determinate is zero.
|
|
2886
|
+
*/
|
|
2887
|
+
static inverse(matrix, result) {
|
|
2888
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
2889
|
+
Check_default.typeOf.object("result", result);
|
|
2890
|
+
const src0 = matrix[0];
|
|
2891
|
+
const src1 = matrix[4];
|
|
2892
|
+
const src2 = matrix[8];
|
|
2893
|
+
const src3 = matrix[12];
|
|
2894
|
+
const src4 = matrix[1];
|
|
2895
|
+
const src5 = matrix[5];
|
|
2896
|
+
const src6 = matrix[9];
|
|
2897
|
+
const src7 = matrix[13];
|
|
2898
|
+
const src8 = matrix[2];
|
|
2899
|
+
const src9 = matrix[6];
|
|
2900
|
+
const src10 = matrix[10];
|
|
2901
|
+
const src11 = matrix[14];
|
|
2902
|
+
const src12 = matrix[3];
|
|
2903
|
+
const src13 = matrix[7];
|
|
2904
|
+
const src14 = matrix[11];
|
|
2905
|
+
const src15 = matrix[15];
|
|
2906
|
+
let tmp0 = src10 * src15;
|
|
2907
|
+
let tmp1 = src11 * src14;
|
|
2908
|
+
let tmp2 = src9 * src15;
|
|
2909
|
+
let tmp3 = src11 * src13;
|
|
2910
|
+
let tmp4 = src9 * src14;
|
|
2911
|
+
let tmp5 = src10 * src13;
|
|
2912
|
+
let tmp6 = src8 * src15;
|
|
2913
|
+
let tmp7 = src11 * src12;
|
|
2914
|
+
let tmp8 = src8 * src14;
|
|
2915
|
+
let tmp9 = src10 * src12;
|
|
2916
|
+
let tmp10 = src8 * src13;
|
|
2917
|
+
let tmp11 = src9 * src12;
|
|
2918
|
+
const dst0 = tmp0 * src5 + tmp3 * src6 + tmp4 * src7 - (tmp1 * src5 + tmp2 * src6 + tmp5 * src7);
|
|
2919
|
+
const dst1 = tmp1 * src4 + tmp6 * src6 + tmp9 * src7 - (tmp0 * src4 + tmp7 * src6 + tmp8 * src7);
|
|
2920
|
+
const dst2 = tmp2 * src4 + tmp7 * src5 + tmp10 * src7 - (tmp3 * src4 + tmp6 * src5 + tmp11 * src7);
|
|
2921
|
+
const dst3 = tmp5 * src4 + tmp8 * src5 + tmp11 * src6 - (tmp4 * src4 + tmp9 * src5 + tmp10 * src6);
|
|
2922
|
+
const dst4 = tmp1 * src1 + tmp2 * src2 + tmp5 * src3 - (tmp0 * src1 + tmp3 * src2 + tmp4 * src3);
|
|
2923
|
+
const dst5 = tmp0 * src0 + tmp7 * src2 + tmp8 * src3 - (tmp1 * src0 + tmp6 * src2 + tmp9 * src3);
|
|
2924
|
+
const dst6 = tmp3 * src0 + tmp6 * src1 + tmp11 * src3 - (tmp2 * src0 + tmp7 * src1 + tmp10 * src3);
|
|
2925
|
+
const dst7 = tmp4 * src0 + tmp9 * src1 + tmp10 * src2 - (tmp5 * src0 + tmp8 * src1 + tmp11 * src2);
|
|
2926
|
+
tmp0 = src2 * src7;
|
|
2927
|
+
tmp1 = src3 * src6;
|
|
2928
|
+
tmp2 = src1 * src7;
|
|
2929
|
+
tmp3 = src3 * src5;
|
|
2930
|
+
tmp4 = src1 * src6;
|
|
2931
|
+
tmp5 = src2 * src5;
|
|
2932
|
+
tmp6 = src0 * src7;
|
|
2933
|
+
tmp7 = src3 * src4;
|
|
2934
|
+
tmp8 = src0 * src6;
|
|
2935
|
+
tmp9 = src2 * src4;
|
|
2936
|
+
tmp10 = src0 * src5;
|
|
2937
|
+
tmp11 = src1 * src4;
|
|
2938
|
+
const dst8 = tmp0 * src13 + tmp3 * src14 + tmp4 * src15 - (tmp1 * src13 + tmp2 * src14 + tmp5 * src15);
|
|
2939
|
+
const dst9 = tmp1 * src12 + tmp6 * src14 + tmp9 * src15 - (tmp0 * src12 + tmp7 * src14 + tmp8 * src15);
|
|
2940
|
+
const dst10 = tmp2 * src12 + tmp7 * src13 + tmp10 * src15 - (tmp3 * src12 + tmp6 * src13 + tmp11 * src15);
|
|
2941
|
+
const dst11 = tmp5 * src12 + tmp8 * src13 + tmp11 * src14 - (tmp4 * src12 + tmp9 * src13 + tmp10 * src14);
|
|
2942
|
+
const dst12 = tmp2 * src10 + tmp5 * src11 + tmp1 * src9 - (tmp4 * src11 + tmp0 * src9 + tmp3 * src10);
|
|
2943
|
+
const dst13 = tmp8 * src11 + tmp0 * src8 + tmp7 * src10 - (tmp6 * src10 + tmp9 * src11 + tmp1 * src8);
|
|
2944
|
+
const dst14 = tmp6 * src9 + tmp11 * src11 + tmp3 * src8 - (tmp10 * src11 + tmp2 * src8 + tmp7 * src9);
|
|
2945
|
+
const dst15 = tmp10 * src10 + tmp4 * src8 + tmp9 * src9 - (tmp8 * src9 + tmp11 * src10 + tmp5 * src8);
|
|
2946
|
+
let det = src0 * dst0 + src1 * dst1 + src2 * dst2 + src3 * dst3;
|
|
2947
|
+
if (Math.abs(det) < Math_default.EPSILON21) {
|
|
2948
|
+
if (Matrix3_default.equalsEpsilon(
|
|
2949
|
+
_Matrix4.getMatrix3(matrix, scratchInverseRotation),
|
|
2950
|
+
scratchMatrix3Zero,
|
|
2951
|
+
Math_default.EPSILON7
|
|
2952
|
+
) && Cartesian4_default.equals(
|
|
2953
|
+
_Matrix4.getRow(matrix, 3, scratchBottomRow),
|
|
2954
|
+
scratchExpectedBottomRow
|
|
2955
|
+
)) {
|
|
2956
|
+
result[0] = 0;
|
|
2957
|
+
result[1] = 0;
|
|
2958
|
+
result[2] = 0;
|
|
2959
|
+
result[3] = 0;
|
|
2960
|
+
result[4] = 0;
|
|
2961
|
+
result[5] = 0;
|
|
2962
|
+
result[6] = 0;
|
|
2963
|
+
result[7] = 0;
|
|
2964
|
+
result[8] = 0;
|
|
2965
|
+
result[9] = 0;
|
|
2966
|
+
result[10] = 0;
|
|
2967
|
+
result[11] = 0;
|
|
2968
|
+
result[12] = -matrix[12];
|
|
2969
|
+
result[13] = -matrix[13];
|
|
2970
|
+
result[14] = -matrix[14];
|
|
2971
|
+
result[15] = 1;
|
|
2972
|
+
return result;
|
|
2973
|
+
}
|
|
2974
|
+
throw new RuntimeError_default(
|
|
2975
|
+
"matrix is not invertible because its determinate is zero."
|
|
2976
|
+
);
|
|
2977
|
+
}
|
|
2978
|
+
det = 1 / det;
|
|
2979
|
+
result[0] = dst0 * det;
|
|
2980
|
+
result[1] = dst1 * det;
|
|
2981
|
+
result[2] = dst2 * det;
|
|
2982
|
+
result[3] = dst3 * det;
|
|
2983
|
+
result[4] = dst4 * det;
|
|
2984
|
+
result[5] = dst5 * det;
|
|
2985
|
+
result[6] = dst6 * det;
|
|
2986
|
+
result[7] = dst7 * det;
|
|
2987
|
+
result[8] = dst8 * det;
|
|
2988
|
+
result[9] = dst9 * det;
|
|
2989
|
+
result[10] = dst10 * det;
|
|
2990
|
+
result[11] = dst11 * det;
|
|
2991
|
+
result[12] = dst12 * det;
|
|
2992
|
+
result[13] = dst13 * det;
|
|
2993
|
+
result[14] = dst14 * det;
|
|
2994
|
+
result[15] = dst15 * det;
|
|
2995
|
+
return result;
|
|
2996
|
+
}
|
|
2997
|
+
/**
|
|
2998
|
+
* Computes the inverse of the provided matrix assuming it is a proper rigid matrix,
|
|
2999
|
+
* where the upper left 3x3 elements are a rotation matrix,
|
|
3000
|
+
* and the upper three elements in the fourth column are the translation.
|
|
3001
|
+
* The bottom row is assumed to be [0, 0, 0, 1].
|
|
3002
|
+
* The matrix is not verified to be in the proper form.
|
|
3003
|
+
* This method is faster than computing the inverse for a general 4x4
|
|
3004
|
+
* matrix using {@link Matrix4.inverse}.
|
|
3005
|
+
*
|
|
3006
|
+
* @param {Matrix4} matrix The matrix to invert.
|
|
3007
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
3008
|
+
* @returns {Matrix4} The modified result parameter.
|
|
3009
|
+
*/
|
|
3010
|
+
static inverseTransformation(matrix, result) {
|
|
3011
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
3012
|
+
Check_default.typeOf.object("result", result);
|
|
3013
|
+
const matrix0 = matrix[0];
|
|
3014
|
+
const matrix1 = matrix[1];
|
|
3015
|
+
const matrix2 = matrix[2];
|
|
3016
|
+
const matrix4 = matrix[4];
|
|
3017
|
+
const matrix5 = matrix[5];
|
|
3018
|
+
const matrix6 = matrix[6];
|
|
3019
|
+
const matrix8 = matrix[8];
|
|
3020
|
+
const matrix9 = matrix[9];
|
|
3021
|
+
const matrix10 = matrix[10];
|
|
3022
|
+
const vX = matrix[12];
|
|
3023
|
+
const vY = matrix[13];
|
|
3024
|
+
const vZ = matrix[14];
|
|
3025
|
+
const x = -matrix0 * vX - matrix1 * vY - matrix2 * vZ;
|
|
3026
|
+
const y = -matrix4 * vX - matrix5 * vY - matrix6 * vZ;
|
|
3027
|
+
const z = -matrix8 * vX - matrix9 * vY - matrix10 * vZ;
|
|
3028
|
+
result[0] = matrix0;
|
|
3029
|
+
result[1] = matrix4;
|
|
3030
|
+
result[2] = matrix8;
|
|
3031
|
+
result[3] = 0;
|
|
3032
|
+
result[4] = matrix1;
|
|
3033
|
+
result[5] = matrix5;
|
|
3034
|
+
result[6] = matrix9;
|
|
3035
|
+
result[7] = 0;
|
|
3036
|
+
result[8] = matrix2;
|
|
3037
|
+
result[9] = matrix6;
|
|
3038
|
+
result[10] = matrix10;
|
|
3039
|
+
result[11] = 0;
|
|
3040
|
+
result[12] = x;
|
|
3041
|
+
result[13] = y;
|
|
3042
|
+
result[14] = z;
|
|
3043
|
+
result[15] = 1;
|
|
3044
|
+
return result;
|
|
3045
|
+
}
|
|
3046
|
+
/**
|
|
3047
|
+
* Computes the inverse transpose of a matrix.
|
|
3048
|
+
*
|
|
3049
|
+
* @param {Matrix4} matrix The matrix to transpose and invert.
|
|
3050
|
+
* @param {Matrix4} result The object onto which to store the result.
|
|
3051
|
+
* @returns {Matrix4} The modified result parameter.
|
|
3052
|
+
*/
|
|
3053
|
+
static inverseTranspose(matrix, result) {
|
|
3054
|
+
Check_default.typeOf.object("matrix", matrix);
|
|
3055
|
+
Check_default.typeOf.object("result", result);
|
|
3056
|
+
return _Matrix4.inverse(
|
|
3057
|
+
_Matrix4.transpose(matrix, scratchTransposeMatrix),
|
|
3058
|
+
result
|
|
3059
|
+
);
|
|
3060
|
+
}
|
|
3061
|
+
/**
|
|
3062
|
+
* Gets the number of items in the collection.
|
|
3063
|
+
*
|
|
3064
|
+
* @type {number}
|
|
3065
|
+
*/
|
|
3066
|
+
get length() {
|
|
3067
|
+
return _Matrix4.packedLength;
|
|
3068
|
+
}
|
|
3069
|
+
/**
|
|
3070
|
+
* Duplicates the provided Matrix4 instance.
|
|
3071
|
+
*
|
|
3072
|
+
* @param {Matrix4} [result] The object onto which to store the result.
|
|
3073
|
+
* @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
|
|
3074
|
+
*/
|
|
3075
|
+
clone(result) {
|
|
3076
|
+
return _Matrix4.clone(this, result);
|
|
3077
|
+
}
|
|
3078
|
+
/**
|
|
3079
|
+
* Compares this matrix to the provided matrix componentwise and returns
|
|
3080
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
3081
|
+
*
|
|
3082
|
+
* @param {Matrix4} [right] The right hand side matrix.
|
|
3083
|
+
* @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
3084
|
+
*/
|
|
3085
|
+
equals(right) {
|
|
3086
|
+
return _Matrix4.equals(this, right);
|
|
3087
|
+
}
|
|
3088
|
+
/**
|
|
3089
|
+
* Compares provided matrix and array, starting from a given array offset.
|
|
3090
|
+
*
|
|
3091
|
+
* @param {Matrix4} matrix
|
|
3092
|
+
* @param {number[]} array
|
|
3093
|
+
* @param {number} offset
|
|
3094
|
+
* @ignore
|
|
3095
|
+
*/
|
|
3096
|
+
static equalsArray(matrix, array, offset) {
|
|
3097
|
+
return matrix[0] === array[offset] && matrix[1] === array[offset + 1] && matrix[2] === array[offset + 2] && matrix[3] === array[offset + 3] && matrix[4] === array[offset + 4] && matrix[5] === array[offset + 5] && matrix[6] === array[offset + 6] && matrix[7] === array[offset + 7] && matrix[8] === array[offset + 8] && matrix[9] === array[offset + 9] && matrix[10] === array[offset + 10] && matrix[11] === array[offset + 11] && matrix[12] === array[offset + 12] && matrix[13] === array[offset + 13] && matrix[14] === array[offset + 14] && matrix[15] === array[offset + 15];
|
|
3098
|
+
}
|
|
3099
|
+
/**
|
|
3100
|
+
* Compares this matrix to the provided matrix componentwise and returns
|
|
3101
|
+
* <code>true</code> if they are within the provided epsilon,
|
|
3102
|
+
* <code>false</code> otherwise.
|
|
3103
|
+
*
|
|
3104
|
+
* @param {Matrix4} [right] The right hand side matrix.
|
|
3105
|
+
* @param {number} [epsilon=0] The epsilon to use for equality testing.
|
|
3106
|
+
* @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
|
|
3107
|
+
*/
|
|
3108
|
+
equalsEpsilon(right, epsilon) {
|
|
3109
|
+
return _Matrix4.equalsEpsilon(this, right, epsilon);
|
|
3110
|
+
}
|
|
3111
|
+
/**
|
|
3112
|
+
* Computes a string representing this Matrix with each row being
|
|
3113
|
+
* on a separate line and in the format '(column0, column1, column2, column3)'.
|
|
3114
|
+
*
|
|
3115
|
+
* @returns {string} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2, column3)'.
|
|
3116
|
+
*/
|
|
3117
|
+
toString() {
|
|
3118
|
+
return `(${this[0]}, ${this[4]}, ${this[8]}, ${this[12]})
|
|
3119
|
+
(${this[1]}, ${this[5]}, ${this[9]}, ${this[13]})
|
|
3120
|
+
(${this[2]}, ${this[6]}, ${this[10]}, ${this[14]})
|
|
3121
|
+
(${this[3]}, ${this[7]}, ${this[11]}, ${this[15]})`;
|
|
3122
|
+
}
|
|
3123
|
+
};
|
|
3124
|
+
Matrix4.packedLength = 16;
|
|
3125
|
+
Matrix4.fromArray = Matrix4.unpack;
|
|
3126
|
+
Matrix4.IDENTITY = Object.freeze(
|
|
3127
|
+
new Matrix4(
|
|
3128
|
+
1,
|
|
3129
|
+
0,
|
|
3130
|
+
0,
|
|
3131
|
+
0,
|
|
3132
|
+
0,
|
|
3133
|
+
1,
|
|
3134
|
+
0,
|
|
3135
|
+
0,
|
|
3136
|
+
0,
|
|
3137
|
+
0,
|
|
3138
|
+
1,
|
|
3139
|
+
0,
|
|
3140
|
+
0,
|
|
3141
|
+
0,
|
|
3142
|
+
0,
|
|
3143
|
+
1
|
|
3144
|
+
)
|
|
3145
|
+
);
|
|
3146
|
+
Matrix4.ZERO = Object.freeze(
|
|
3147
|
+
new Matrix4(
|
|
3148
|
+
0,
|
|
3149
|
+
0,
|
|
3150
|
+
0,
|
|
3151
|
+
0,
|
|
3152
|
+
0,
|
|
3153
|
+
0,
|
|
3154
|
+
0,
|
|
3155
|
+
0,
|
|
3156
|
+
0,
|
|
3157
|
+
0,
|
|
3158
|
+
0,
|
|
3159
|
+
0,
|
|
3160
|
+
0,
|
|
3161
|
+
0,
|
|
3162
|
+
0,
|
|
3163
|
+
0
|
|
3164
|
+
)
|
|
3165
|
+
);
|
|
3166
|
+
Matrix4.COLUMN0ROW0 = 0;
|
|
3167
|
+
Matrix4.COLUMN0ROW1 = 1;
|
|
3168
|
+
Matrix4.COLUMN0ROW2 = 2;
|
|
3169
|
+
Matrix4.COLUMN0ROW3 = 3;
|
|
3170
|
+
Matrix4.COLUMN1ROW0 = 4;
|
|
3171
|
+
Matrix4.COLUMN1ROW1 = 5;
|
|
3172
|
+
Matrix4.COLUMN1ROW2 = 6;
|
|
3173
|
+
Matrix4.COLUMN1ROW3 = 7;
|
|
3174
|
+
Matrix4.COLUMN2ROW0 = 8;
|
|
3175
|
+
Matrix4.COLUMN2ROW1 = 9;
|
|
3176
|
+
Matrix4.COLUMN2ROW2 = 10;
|
|
3177
|
+
Matrix4.COLUMN2ROW3 = 11;
|
|
3178
|
+
Matrix4.COLUMN3ROW0 = 12;
|
|
3179
|
+
Matrix4.COLUMN3ROW1 = 13;
|
|
3180
|
+
Matrix4.COLUMN3ROW2 = 14;
|
|
3181
|
+
Matrix4.COLUMN3ROW3 = 15;
|
|
3182
|
+
var fromCameraF = new Cartesian3_default();
|
|
3183
|
+
var fromCameraR = new Cartesian3_default();
|
|
3184
|
+
var fromCameraU = new Cartesian3_default();
|
|
3185
|
+
var scaleScratch1 = new Cartesian3_default();
|
|
3186
|
+
var scaleScratch2 = new Cartesian3_default();
|
|
3187
|
+
var scratchColumn = new Cartesian3_default();
|
|
3188
|
+
var scaleScratch3 = new Cartesian3_default();
|
|
3189
|
+
var scaleScratch4 = new Cartesian3_default();
|
|
3190
|
+
var scaleScratch5 = new Cartesian3_default();
|
|
3191
|
+
var scratchInverseRotation = new Matrix3_default();
|
|
3192
|
+
var scratchMatrix3Zero = new Matrix3_default();
|
|
3193
|
+
var scratchBottomRow = new Cartesian4_default();
|
|
3194
|
+
var scratchExpectedBottomRow = new Cartesian4_default(0, 0, 0, 1);
|
|
3195
|
+
var scratchTransposeMatrix = new Matrix4();
|
|
3196
|
+
var Matrix4_default = Matrix4;
|
|
3197
|
+
|
|
3198
|
+
export {
|
|
3199
|
+
Cartesian4_default,
|
|
3200
|
+
Matrix4_default
|
|
3201
|
+
};
|