@xort/cga 0.0.75 → 0.0.78
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/dist/IKanimation/Bone.js +3 -1
- package/dist/IKanimation/CCDSolver.js +2 -2
- package/dist/IKanimation/constaint/hinge.js +3 -1
- package/dist/IKanimation/constaint/slider.js +3 -1
- package/dist/alg/common.js +2 -2
- package/dist/alg/extrude.js +56 -54
- package/dist/alg/pointset.js +5 -5
- package/dist/alg/trianglution.js +12 -10
- package/dist/app.js +18 -11
- package/dist/diamondMaterialShader.js +6 -2
- package/dist/effect/breath-light.js +3 -1
- package/dist/extends/geometryaid.js +7 -7
- package/dist/index.js +6 -2
- package/dist/math/Color.d.ts +6 -9
- package/dist/math/Color.js +18 -55
- package/dist/math/Euler.js +12 -10
- package/dist/math/HVec3.js +3 -1
- package/dist/math/Mat3.js +1 -1
- package/dist/math/Mat4.js +6 -6
- package/dist/math/Quat.js +4 -2
- package/dist/math/Vec.js +3 -1
- package/dist/math/Vec2.js +3 -1
- package/dist/math/Vec3.js +7 -5
- package/dist/math/Vec4.js +3 -1
- package/dist/math/vector.js +9 -7
- package/dist/render/buffer-attribute.js +12 -28
- package/dist/render/eventhandler.d.ts +1 -1
- package/dist/render/eventhandler.js +9 -7
- package/dist/render/geometry.js +2 -2
- package/dist/render/mesh.js +11 -9
- package/dist/render/thing.js +10 -8
- package/dist/render/types.js +2 -1
- package/dist/struct/3d/Box.js +3 -3
- package/dist/struct/3d/Capsule.js +3 -1
- package/dist/struct/3d/Circle.js +2 -2
- package/dist/struct/3d/Disk.js +1 -1
- package/dist/struct/3d/Line.js +4 -4
- package/dist/struct/3d/Path.js +13 -11
- package/dist/struct/3d/Plane.js +12 -10
- package/dist/struct/3d/Point.js +3 -1
- package/dist/struct/3d/Polygon.js +3 -1
- package/dist/struct/3d/Polyline.js +3 -1
- package/dist/struct/3d/Rectangle.js +3 -1
- package/dist/struct/3d/Segment.js +9 -7
- package/dist/struct/3d/Shape.js +3 -1
- package/dist/struct/3d/Sphere.js +1 -1
- package/dist/struct/3d/Triangle.js +3 -1
- package/dist/struct/data/ArrayList.js +11 -9
- package/dist/struct/data/ArrayObject.js +3 -1
- package/package.json +4 -3
- package/src/app.ts +4 -1
- package/src/index.ts +1 -0
- package/src/math/Color.ts +14 -32
- package/dist/src/IKanimation/Bone.d.ts +0 -9
- package/dist/src/IKanimation/Bone.js +0 -40
- package/dist/src/IKanimation/CCDSolver.d.ts +0 -37
- package/dist/src/IKanimation/CCDSolver.js +0 -93
- package/dist/src/IKanimation/Joint.d.ts +0 -3
- package/dist/src/IKanimation/Joint.js +0 -17
- package/dist/src/IKanimation/constaint/constraint.d.ts +0 -10
- package/dist/src/IKanimation/constaint/constraint.js +0 -25
- package/dist/src/IKanimation/constaint/hinge.d.ts +0 -12
- package/dist/src/IKanimation/constaint/hinge.js +0 -46
- package/dist/src/IKanimation/constaint/slider.d.ts +0 -12
- package/dist/src/IKanimation/constaint/slider.js +0 -44
- package/dist/src/IKanimation/index.d.ts +0 -0
- package/dist/src/IKanimation/index.js +0 -9
- package/dist/src/IKanimation/isolver.d.ts +0 -4
- package/dist/src/IKanimation/isolver.js +0 -10
- package/dist/src/IKanimation/skeleton.d.ts +0 -13
- package/dist/src/IKanimation/skeleton.js +0 -31
- package/dist/src/alg/common.d.ts +0 -114
- package/dist/src/alg/common.js +0 -302
- package/dist/src/alg/curve.d.ts +0 -4
- package/dist/src/alg/curve.js +0 -11
- package/dist/src/alg/delaunator.d.ts +0 -29
- package/dist/src/alg/delaunator.js +0 -442
- package/dist/src/alg/delaunay.d.ts +0 -20
- package/dist/src/alg/delaunay.js +0 -199
- package/dist/src/alg/delaunayslow.d.ts +0 -18
- package/dist/src/alg/delaunayslow.js +0 -140
- package/dist/src/alg/extrude/extrude.d.ts +0 -3
- package/dist/src/alg/extrude/extrude.js +0 -17
- package/dist/src/alg/extrude.d.ts +0 -199
- package/dist/src/alg/extrude.js +0 -731
- package/dist/src/alg/offset/index.d.ts +0 -0
- package/dist/src/alg/offset/index.js +0 -9
- package/dist/src/alg/offset.d.ts +0 -0
- package/dist/src/alg/offset.js +0 -472
- package/dist/src/alg/pointset.d.ts +0 -94
- package/dist/src/alg/pointset.js +0 -223
- package/dist/src/alg/recognition.d.ts +0 -14
- package/dist/src/alg/recognition.js +0 -37
- package/dist/src/alg/result.d.ts +0 -22
- package/dist/src/alg/result.js +0 -2
- package/dist/src/alg/segmentset.d.ts +0 -11
- package/dist/src/alg/segmentset.js +0 -45
- package/dist/src/alg/sort.d.ts +0 -2
- package/dist/src/alg/sort.js +0 -14
- package/dist/src/alg/split.d.ts +0 -8
- package/dist/src/alg/split.js +0 -10
- package/dist/src/alg/trianglution.d.ts +0 -20
- package/dist/src/alg/trianglution.js +0 -77
- package/dist/src/alg/vol.d.ts +0 -6
- package/dist/src/alg/vol.js +0 -18
- package/dist/src/alg/voronoi.d.ts +0 -31
- package/dist/src/alg/voronoi.js +0 -418
- package/dist/src/app.d.ts +0 -1
- package/dist/src/app.js +0 -245
- package/dist/src/basic/distance.d.ts +0 -12
- package/dist/src/basic/distance.js +0 -42
- package/dist/src/csg/bsp.d.ts +0 -9
- package/dist/src/csg/bsp.js +0 -22
- package/dist/src/csg/node.d.ts +0 -12
- package/dist/src/csg/node.js +0 -75
- package/dist/src/csg/polygon.d.ts +0 -43
- package/dist/src/csg/polygon.js +0 -161
- package/dist/src/diamondMaterialShader.d.ts +0 -92
- package/dist/src/diamondMaterialShader.js +0 -118
- package/dist/src/effect/breath-light.d.ts +0 -4
- package/dist/src/effect/breath-light.js +0 -39
- package/dist/src/extends/geometryaid.d.ts +0 -28
- package/dist/src/extends/geometryaid.js +0 -80
- package/dist/src/extends/split.d.ts +0 -3
- package/dist/src/extends/split.js +0 -13
- package/dist/src/glview.d.ts +0 -112
- package/dist/src/glview.js +0 -564
- package/dist/src/index.d.ts +0 -36
- package/dist/src/index.js +0 -54
- package/dist/src/math/Euler.d.ts +0 -47
- package/dist/src/math/Euler.js +0 -245
- package/dist/src/math/HVec3.d.ts +0 -44
- package/dist/src/math/HVec3.js +0 -195
- package/dist/src/math/Mat3.d.ts +0 -29
- package/dist/src/math/Mat3.js +0 -244
- package/dist/src/math/Mat4.d.ts +0 -85
- package/dist/src/math/Mat4.js +0 -791
- package/dist/src/math/Math.d.ts +0 -130
- package/dist/src/math/Math.js +0 -198
- package/dist/src/math/Quat.d.ts +0 -83
- package/dist/src/math/Quat.js +0 -440
- package/dist/src/math/Vec.d.ts +0 -7
- package/dist/src/math/Vec.js +0 -43
- package/dist/src/math/Vec2.d.ts +0 -68
- package/dist/src/math/Vec2.js +0 -347
- package/dist/src/math/Vec3.d.ts +0 -232
- package/dist/src/math/Vec3.js +0 -1089
- package/dist/src/math/Vec4.d.ts +0 -81
- package/dist/src/math/Vec4.js +0 -494
- package/dist/src/math/vector.d.ts +0 -114
- package/dist/src/math/vector.js +0 -373
- package/dist/src/render/buffer-attribute.d.ts +0 -100
- package/dist/src/render/buffer-attribute.js +0 -340
- package/dist/src/render/eventhandler.d.ts +0 -78
- package/dist/src/render/eventhandler.js +0 -189
- package/dist/src/render/geometry.d.ts +0 -89
- package/dist/src/render/geometry.js +0 -775
- package/dist/src/render/mesh.d.ts +0 -25
- package/dist/src/render/mesh.js +0 -82
- package/dist/src/render/thing.d.ts +0 -34
- package/dist/src/render/thing.js +0 -196
- package/dist/src/render/types.d.ts +0 -2
- package/dist/src/render/types.js +0 -8
- package/dist/src/robust/plane.d.ts +0 -7
- package/dist/src/robust/plane.js +0 -17
- package/dist/src/robust/vec.d.ts +0 -15
- package/dist/src/robust/vec.js +0 -71
- package/dist/src/shape/arc.d.ts +0 -2
- package/dist/src/shape/arc.js +0 -14
- package/dist/src/struct/3d/Box.d.ts +0 -23
- package/dist/src/struct/3d/Box.js +0 -109
- package/dist/src/struct/3d/Capsule.d.ts +0 -12
- package/dist/src/struct/3d/Capsule.js +0 -36
- package/dist/src/struct/3d/Circle.d.ts +0 -34
- package/dist/src/struct/3d/Circle.js +0 -80
- package/dist/src/struct/3d/Disk.d.ts +0 -10
- package/dist/src/struct/3d/Disk.js +0 -22
- package/dist/src/struct/3d/Frustum.d.ts +0 -35
- package/dist/src/struct/3d/Frustum.js +0 -159
- package/dist/src/struct/3d/Line.d.ts +0 -40
- package/dist/src/struct/3d/Line.js +0 -339
- package/dist/src/struct/3d/Path.d.ts +0 -75
- package/dist/src/struct/3d/Path.js +0 -308
- package/dist/src/struct/3d/Plane.d.ts +0 -74
- package/dist/src/struct/3d/Plane.js +0 -295
- package/dist/src/struct/3d/Point.d.ts +0 -4
- package/dist/src/struct/3d/Point.js +0 -30
- package/dist/src/struct/3d/Polygon.d.ts +0 -8
- package/dist/src/struct/3d/Polygon.js +0 -55
- package/dist/src/struct/3d/Polyline.d.ts +0 -25
- package/dist/src/struct/3d/Polyline.js +0 -109
- package/dist/src/struct/3d/Ray.d.ts +0 -21
- package/dist/src/struct/3d/Ray.js +0 -262
- package/dist/src/struct/3d/Rectangle.d.ts +0 -7
- package/dist/src/struct/3d/Rectangle.js +0 -35
- package/dist/src/struct/3d/Segment.d.ts +0 -32
- package/dist/src/struct/3d/Segment.js +0 -334
- package/dist/src/struct/3d/Shape.d.ts +0 -4
- package/dist/src/struct/3d/Shape.js +0 -27
- package/dist/src/struct/3d/Sphere.d.ts +0 -11
- package/dist/src/struct/3d/Sphere.js +0 -30
- package/dist/src/struct/3d/Triangle.d.ts +0 -8
- package/dist/src/struct/3d/Triangle.js +0 -53
- package/dist/src/struct/data/ArrayList.d.ts +0 -42
- package/dist/src/struct/data/ArrayList.js +0 -172
- package/dist/src/struct/data/ArrayObject.d.ts +0 -30
- package/dist/src/struct/data/ArrayObject.js +0 -131
- package/dist/src/struct/data/type.d.ts +0 -13
- package/dist/src/struct/data/type.js +0 -18
- package/dist/src/utils/array.d.ts +0 -24
- package/dist/src/utils/array.js +0 -89
- package/dist/src/utils/types.d.ts +0 -24
- package/dist/src/utils/types.js +0 -20
- package/dist/src-gis/app.d.ts +0 -1
- package/dist/src-gis/app.js +0 -4
- package/dist/src-gis/core/Cartographic.d.ts +0 -20
- package/dist/src-gis/core/Cartographic.js +0 -52
- package/dist/src-gis/core/EllipsoidGeodesic.d.ts +0 -14
- package/dist/src-gis/core/EllipsoidGeodesic.js +0 -51
- package/dist/src-gis/core/EllipsoidTerrainProvider.d.ts +0 -10
- package/dist/src-gis/core/EllipsoidTerrainProvider.js +0 -29
- package/dist/src-gis/core/HeightmapTerrainData.d.ts +0 -3
- package/dist/src-gis/core/HeightmapTerrainData.js +0 -9
- package/dist/src-gis/core/Rectangle.d.ts +0 -45
- package/dist/src-gis/core/Rectangle.js +0 -127
- package/dist/src-gis/core/TaskProcessor.d.ts +0 -35
- package/dist/src-gis/core/TaskProcessor.js +0 -183
- package/dist/src-gis/gis.d.ts +0 -5
- package/dist/src-gis/gis.js +0 -12
- package/dist/src-gis/globe.d.ts +0 -12
- package/dist/src-gis/globe.js +0 -61
- package/dist/src-gis/math/Cartographic.d.ts +0 -8
- package/dist/src-gis/math/Cartographic.js +0 -26
- package/dist/src-gis/math/GVec3.d.ts +0 -12
- package/dist/src-gis/math/GVec3.js +0 -69
- package/dist/src-gis/math/ellipsoid.d.ts +0 -8
- package/dist/src-gis/math/ellipsoid.js +0 -14
- package/dist/src-gis/provider/DcTerrainProvider.d.ts +0 -15
- package/dist/src-gis/provider/DcTerrainProvider.js +0 -19
- package/dist/src-gis/provider/TerrainProvider.d.ts +0 -3
- package/dist/src-gis/provider/TerrainProvider.js +0 -17
- package/dist/src-gis/scene/DcImageryProvider.d.ts +0 -6
- package/dist/src-gis/scene/DcImageryProvider.js +0 -35
- package/dist/src-gis/scene/GeographicTilingScheme.d.ts +0 -21
- package/dist/src-gis/scene/GeographicTilingScheme.js +0 -46
- package/dist/src-gis/scene/Globe.d.ts +0 -34
- package/dist/src-gis/scene/Globe.js +0 -62
- package/dist/src-gis/scene/GlobeSurfaceShaderSet.d.ts +0 -6
- package/dist/src-gis/scene/GlobeSurfaceShaderSet.js +0 -11
- package/dist/src-gis/scene/GlobeSurfaceTileProvider.d.ts +0 -21
- package/dist/src-gis/scene/GlobeSurfaceTileProvider.js +0 -15
- package/dist/src-gis/scene/ImageryLayerCollection.d.ts +0 -21
- package/dist/src-gis/scene/ImageryLayerCollection.js +0 -87
- package/dist/src-gis/scene/ImageryProvider.d.ts +0 -4
- package/dist/src-gis/scene/ImageryProvider.js +0 -28
- package/dist/src-gis/scene/QuadtreeTile.d.ts +0 -48
- package/dist/src-gis/scene/QuadtreeTile.js +0 -137
- package/dist/src-gis/scene/UrlTemplateImageryProvider.d.ts +0 -9
- package/dist/src-gis/scene/UrlTemplateImageryProvider.js +0 -29
- package/dist/src-gis/scene/quadtree_primitive.d.ts +0 -14
- package/dist/src-gis/scene/quadtree_primitive.js +0 -50
package/dist/src/math/Mat4.js
DELETED
|
@@ -1,791 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.m4 = exports.Mat4 = void 0;
|
|
4
|
-
var Vec3_1 = require("./Vec3");
|
|
5
|
-
var Mat4 = /** @class */ (function () {
|
|
6
|
-
function Mat4() {
|
|
7
|
-
this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
8
|
-
this.isMat4 = true;
|
|
9
|
-
if (arguments.length > 0) {
|
|
10
|
-
console.error(" Mat4: the constructor no longer reads arguments. use .set() instead.");
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
Mat4.prototype.set = function (n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
|
|
14
|
-
var te = this.elements;
|
|
15
|
-
te[0] = n11;
|
|
16
|
-
te[4] = n12;
|
|
17
|
-
te[8] = n13;
|
|
18
|
-
te[12] = n14;
|
|
19
|
-
te[1] = n21;
|
|
20
|
-
te[5] = n22;
|
|
21
|
-
te[9] = n23;
|
|
22
|
-
te[13] = n24;
|
|
23
|
-
te[2] = n31;
|
|
24
|
-
te[6] = n32;
|
|
25
|
-
te[10] = n33;
|
|
26
|
-
te[14] = n34;
|
|
27
|
-
te[3] = n41;
|
|
28
|
-
te[7] = n42;
|
|
29
|
-
te[11] = n43;
|
|
30
|
-
te[15] = n44;
|
|
31
|
-
return this;
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(Mat4, "Identity", {
|
|
34
|
-
get: function () {
|
|
35
|
-
return new Mat4();
|
|
36
|
-
},
|
|
37
|
-
enumerable: false,
|
|
38
|
-
configurable: true
|
|
39
|
-
});
|
|
40
|
-
Mat4.prototype.identity = function () {
|
|
41
|
-
this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
42
|
-
return this;
|
|
43
|
-
};
|
|
44
|
-
Mat4.prototype.clone = function () {
|
|
45
|
-
return new Mat4().fromArray(this.elements);
|
|
46
|
-
};
|
|
47
|
-
Mat4.prototype.copy = function (m) {
|
|
48
|
-
var te = this.elements;
|
|
49
|
-
var me = m.elements;
|
|
50
|
-
te[0] = me[0];
|
|
51
|
-
te[1] = me[1];
|
|
52
|
-
te[2] = me[2];
|
|
53
|
-
te[3] = me[3];
|
|
54
|
-
te[4] = me[4];
|
|
55
|
-
te[5] = me[5];
|
|
56
|
-
te[6] = me[6];
|
|
57
|
-
te[7] = me[7];
|
|
58
|
-
te[8] = me[8];
|
|
59
|
-
te[9] = me[9];
|
|
60
|
-
te[10] = me[10];
|
|
61
|
-
te[11] = me[11];
|
|
62
|
-
te[12] = me[12];
|
|
63
|
-
te[13] = me[13];
|
|
64
|
-
te[14] = me[14];
|
|
65
|
-
te[15] = me[15];
|
|
66
|
-
return this;
|
|
67
|
-
};
|
|
68
|
-
Mat4.prototype.copyPosition = function (m) {
|
|
69
|
-
var te = this.elements, me = m.elements;
|
|
70
|
-
te[12] = me[12];
|
|
71
|
-
te[13] = me[13];
|
|
72
|
-
te[14] = me[14];
|
|
73
|
-
return this;
|
|
74
|
-
};
|
|
75
|
-
Mat4.prototype.extractBasis = function (xAxis, yAxis, zAxis) {
|
|
76
|
-
xAxis.setFromMatColumn(this, 0);
|
|
77
|
-
yAxis.setFromMatColumn(this, 1);
|
|
78
|
-
zAxis.setFromMatColumn(this, 2);
|
|
79
|
-
return this;
|
|
80
|
-
};
|
|
81
|
-
Mat4.prototype.makeBasis = function (xAxis, yAxis, zAxis) {
|
|
82
|
-
this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
|
|
83
|
-
return this;
|
|
84
|
-
};
|
|
85
|
-
Mat4.prototype.extractRotation = function (m) {
|
|
86
|
-
// this method does not support reflection matrices
|
|
87
|
-
var te = this.elements;
|
|
88
|
-
var me = m.elements;
|
|
89
|
-
var scaleX = 1 / _v1.setFromMatColumn(m, 0).length();
|
|
90
|
-
var scaleY = 1 / _v1.setFromMatColumn(m, 1).length();
|
|
91
|
-
var scaleZ = 1 / _v1.setFromMatColumn(m, 2).length();
|
|
92
|
-
te[0] = me[0] * scaleX;
|
|
93
|
-
te[1] = me[1] * scaleX;
|
|
94
|
-
te[2] = me[2] * scaleX;
|
|
95
|
-
te[3] = 0;
|
|
96
|
-
te[4] = me[4] * scaleY;
|
|
97
|
-
te[5] = me[5] * scaleY;
|
|
98
|
-
te[6] = me[6] * scaleY;
|
|
99
|
-
te[7] = 0;
|
|
100
|
-
te[8] = me[8] * scaleZ;
|
|
101
|
-
te[9] = me[9] * scaleZ;
|
|
102
|
-
te[10] = me[10] * scaleZ;
|
|
103
|
-
te[11] = 0;
|
|
104
|
-
te[12] = 0;
|
|
105
|
-
te[13] = 0;
|
|
106
|
-
te[14] = 0;
|
|
107
|
-
te[15] = 1;
|
|
108
|
-
return this;
|
|
109
|
-
};
|
|
110
|
-
Mat4.prototype.makeRotationFromEuler = function (euler) {
|
|
111
|
-
if (!(euler && euler.isEuler)) {
|
|
112
|
-
console.error(" Mat4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vec3 and order.");
|
|
113
|
-
}
|
|
114
|
-
var te = this.elements;
|
|
115
|
-
var x = euler.x, y = euler.y, z = euler.z;
|
|
116
|
-
var a = Math.cos(x), b = Math.sin(x);
|
|
117
|
-
var c = Math.cos(y), d = Math.sin(y);
|
|
118
|
-
var e = Math.cos(z), f = Math.sin(z);
|
|
119
|
-
if (euler.order === "XYZ") {
|
|
120
|
-
var ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
121
|
-
te[0] = c * e;
|
|
122
|
-
te[4] = -c * f;
|
|
123
|
-
te[8] = d;
|
|
124
|
-
te[1] = af + be * d;
|
|
125
|
-
te[5] = ae - bf * d;
|
|
126
|
-
te[9] = -b * c;
|
|
127
|
-
te[2] = bf - ae * d;
|
|
128
|
-
te[6] = be + af * d;
|
|
129
|
-
te[10] = a * c;
|
|
130
|
-
}
|
|
131
|
-
else if (euler.order === "YXZ") {
|
|
132
|
-
var ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
133
|
-
te[0] = ce + df * b;
|
|
134
|
-
te[4] = de * b - cf;
|
|
135
|
-
te[8] = a * d;
|
|
136
|
-
te[1] = a * f;
|
|
137
|
-
te[5] = a * e;
|
|
138
|
-
te[9] = -b;
|
|
139
|
-
te[2] = cf * b - de;
|
|
140
|
-
te[6] = df + ce * b;
|
|
141
|
-
te[10] = a * c;
|
|
142
|
-
}
|
|
143
|
-
else if (euler.order === "ZXY") {
|
|
144
|
-
var ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
145
|
-
te[0] = ce - df * b;
|
|
146
|
-
te[4] = -a * f;
|
|
147
|
-
te[8] = de + cf * b;
|
|
148
|
-
te[1] = cf + de * b;
|
|
149
|
-
te[5] = a * e;
|
|
150
|
-
te[9] = df - ce * b;
|
|
151
|
-
te[2] = -a * d;
|
|
152
|
-
te[6] = b;
|
|
153
|
-
te[10] = a * c;
|
|
154
|
-
}
|
|
155
|
-
else if (euler.order === "ZYX") {
|
|
156
|
-
var ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
157
|
-
te[0] = c * e;
|
|
158
|
-
te[4] = be * d - af;
|
|
159
|
-
te[8] = ae * d + bf;
|
|
160
|
-
te[1] = c * f;
|
|
161
|
-
te[5] = bf * d + ae;
|
|
162
|
-
te[9] = af * d - be;
|
|
163
|
-
te[2] = -d;
|
|
164
|
-
te[6] = b * c;
|
|
165
|
-
te[10] = a * c;
|
|
166
|
-
}
|
|
167
|
-
else if (euler.order === "YZX") {
|
|
168
|
-
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
169
|
-
te[0] = c * e;
|
|
170
|
-
te[4] = bd - ac * f;
|
|
171
|
-
te[8] = bc * f + ad;
|
|
172
|
-
te[1] = f;
|
|
173
|
-
te[5] = a * e;
|
|
174
|
-
te[9] = -b * e;
|
|
175
|
-
te[2] = -d * e;
|
|
176
|
-
te[6] = ad * f + bc;
|
|
177
|
-
te[10] = ac - bd * f;
|
|
178
|
-
}
|
|
179
|
-
else if (euler.order === "XZY") {
|
|
180
|
-
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
181
|
-
te[0] = c * e;
|
|
182
|
-
te[4] = -f;
|
|
183
|
-
te[8] = d * e;
|
|
184
|
-
te[1] = ac * f + bd;
|
|
185
|
-
te[5] = a * e;
|
|
186
|
-
te[9] = ad * f - bc;
|
|
187
|
-
te[2] = bc * f - ad;
|
|
188
|
-
te[6] = b * e;
|
|
189
|
-
te[10] = bd * f + ac;
|
|
190
|
-
}
|
|
191
|
-
// bottom row
|
|
192
|
-
te[3] = 0;
|
|
193
|
-
te[7] = 0;
|
|
194
|
-
te[11] = 0;
|
|
195
|
-
// last column
|
|
196
|
-
te[12] = 0;
|
|
197
|
-
te[13] = 0;
|
|
198
|
-
te[14] = 0;
|
|
199
|
-
te[15] = 1;
|
|
200
|
-
return this;
|
|
201
|
-
};
|
|
202
|
-
Mat4.prototype.makeRotationFromQuat = function (q) {
|
|
203
|
-
return this.compose(_zero, q, _one);
|
|
204
|
-
};
|
|
205
|
-
Mat4.prototype.lookAt = function (eye, target, up) {
|
|
206
|
-
var te = this.elements;
|
|
207
|
-
_z.subVecs(eye, target);
|
|
208
|
-
if (_z.lengthSq() === 0) {
|
|
209
|
-
// eye and target are in the same position
|
|
210
|
-
_z.z = 1;
|
|
211
|
-
}
|
|
212
|
-
_z.normalize();
|
|
213
|
-
_x.crossVecs(up, _z);
|
|
214
|
-
if (_x.lengthSq() === 0) {
|
|
215
|
-
// up and z are parallel
|
|
216
|
-
if (Math.abs(up.z) === 1) {
|
|
217
|
-
_z.x += 0.0001;
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
_z.z += 0.0001;
|
|
221
|
-
}
|
|
222
|
-
_z.normalize();
|
|
223
|
-
_x.crossVecs(up, _z);
|
|
224
|
-
}
|
|
225
|
-
_x.normalize();
|
|
226
|
-
_y.crossVecs(_z, _x);
|
|
227
|
-
te[0] = _x.x;
|
|
228
|
-
te[4] = _y.x;
|
|
229
|
-
te[8] = _z.x;
|
|
230
|
-
te[1] = _x.y;
|
|
231
|
-
te[5] = _y.y;
|
|
232
|
-
te[9] = _z.y;
|
|
233
|
-
te[2] = _x.z;
|
|
234
|
-
te[6] = _y.z;
|
|
235
|
-
te[10] = _z.z;
|
|
236
|
-
return this;
|
|
237
|
-
};
|
|
238
|
-
Mat4.prototype.multiply = function (m, n) {
|
|
239
|
-
if (n !== undefined) {
|
|
240
|
-
return this.multiplyMats(m, n);
|
|
241
|
-
}
|
|
242
|
-
return this.multiplyMats(this, m);
|
|
243
|
-
};
|
|
244
|
-
Mat4.prototype.premultiply = function (m) {
|
|
245
|
-
return this.multiplyMats(m, this);
|
|
246
|
-
};
|
|
247
|
-
Mat4.prototype.multiplyMats = function (a, b) {
|
|
248
|
-
var ae = a.elements;
|
|
249
|
-
var be = b.elements;
|
|
250
|
-
var te = this.elements;
|
|
251
|
-
var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
|
|
252
|
-
var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
|
|
253
|
-
var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
|
|
254
|
-
var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
|
|
255
|
-
var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
|
|
256
|
-
var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
|
|
257
|
-
var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
|
|
258
|
-
var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
|
|
259
|
-
te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
|
|
260
|
-
te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
|
|
261
|
-
te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
|
|
262
|
-
te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
|
|
263
|
-
te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
|
|
264
|
-
te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
|
265
|
-
te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
|
266
|
-
te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
|
267
|
-
te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
|
268
|
-
te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
|
269
|
-
te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
|
270
|
-
te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
|
271
|
-
te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
|
272
|
-
te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
|
273
|
-
te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
|
274
|
-
te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
|
275
|
-
return this;
|
|
276
|
-
};
|
|
277
|
-
Mat4.prototype.multiplyScalar = function (s) {
|
|
278
|
-
var te = this.elements;
|
|
279
|
-
te[0] *= s;
|
|
280
|
-
te[4] *= s;
|
|
281
|
-
te[8] *= s;
|
|
282
|
-
te[12] *= s;
|
|
283
|
-
te[1] *= s;
|
|
284
|
-
te[5] *= s;
|
|
285
|
-
te[9] *= s;
|
|
286
|
-
te[13] *= s;
|
|
287
|
-
te[2] *= s;
|
|
288
|
-
te[6] *= s;
|
|
289
|
-
te[10] *= s;
|
|
290
|
-
te[14] *= s;
|
|
291
|
-
te[3] *= s;
|
|
292
|
-
te[7] *= s;
|
|
293
|
-
te[11] *= s;
|
|
294
|
-
te[15] *= s;
|
|
295
|
-
return this;
|
|
296
|
-
};
|
|
297
|
-
Mat4.prototype.applyToBufferAttribute = function (attribute) {
|
|
298
|
-
for (var i = 0, l = attribute.count; i < l; i++) {
|
|
299
|
-
_v1.x = attribute.getX(i);
|
|
300
|
-
_v1.y = attribute.getY(i);
|
|
301
|
-
_v1.z = attribute.getZ(i);
|
|
302
|
-
_v1.applyMat4(this);
|
|
303
|
-
attribute.setXYZ(i, _v1.x, _v1.y, _v1.z);
|
|
304
|
-
}
|
|
305
|
-
return attribute;
|
|
306
|
-
};
|
|
307
|
-
Mat4.prototype.determinant = function () {
|
|
308
|
-
var te = this.elements;
|
|
309
|
-
var n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
|
|
310
|
-
var n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
|
|
311
|
-
var n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
|
|
312
|
-
var n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
|
|
313
|
-
//TODO: make this more efficient
|
|
314
|
-
//( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
|
|
315
|
-
return (n41 *
|
|
316
|
-
(+n14 * n23 * n32 -
|
|
317
|
-
n13 * n24 * n32 -
|
|
318
|
-
n14 * n22 * n33 +
|
|
319
|
-
n12 * n24 * n33 +
|
|
320
|
-
n13 * n22 * n34 -
|
|
321
|
-
n12 * n23 * n34) +
|
|
322
|
-
n42 *
|
|
323
|
-
(+n11 * n23 * n34 -
|
|
324
|
-
n11 * n24 * n33 +
|
|
325
|
-
n14 * n21 * n33 -
|
|
326
|
-
n13 * n21 * n34 +
|
|
327
|
-
n13 * n24 * n31 -
|
|
328
|
-
n14 * n23 * n31) +
|
|
329
|
-
n43 *
|
|
330
|
-
(+n11 * n24 * n32 -
|
|
331
|
-
n11 * n22 * n34 -
|
|
332
|
-
n14 * n21 * n32 +
|
|
333
|
-
n12 * n21 * n34 +
|
|
334
|
-
n14 * n22 * n31 -
|
|
335
|
-
n12 * n24 * n31) +
|
|
336
|
-
n44 *
|
|
337
|
-
(-n13 * n22 * n31 -
|
|
338
|
-
n11 * n23 * n32 +
|
|
339
|
-
n11 * n22 * n33 +
|
|
340
|
-
n13 * n21 * n32 -
|
|
341
|
-
n12 * n21 * n33 +
|
|
342
|
-
n12 * n23 * n31));
|
|
343
|
-
};
|
|
344
|
-
Mat4.prototype.transpose = function () {
|
|
345
|
-
var te = this.elements;
|
|
346
|
-
var tmp;
|
|
347
|
-
tmp = te[1];
|
|
348
|
-
te[1] = te[4];
|
|
349
|
-
te[4] = tmp;
|
|
350
|
-
tmp = te[2];
|
|
351
|
-
te[2] = te[8];
|
|
352
|
-
te[8] = tmp;
|
|
353
|
-
tmp = te[6];
|
|
354
|
-
te[6] = te[9];
|
|
355
|
-
te[9] = tmp;
|
|
356
|
-
tmp = te[3];
|
|
357
|
-
te[3] = te[12];
|
|
358
|
-
te[12] = tmp;
|
|
359
|
-
tmp = te[7];
|
|
360
|
-
te[7] = te[13];
|
|
361
|
-
te[13] = tmp;
|
|
362
|
-
tmp = te[11];
|
|
363
|
-
te[11] = te[14];
|
|
364
|
-
te[14] = tmp;
|
|
365
|
-
return this;
|
|
366
|
-
};
|
|
367
|
-
Mat4.prototype.setPosition = function (x, y, z) {
|
|
368
|
-
var te = this.elements;
|
|
369
|
-
if (x.isVec3) {
|
|
370
|
-
te[12] = x.x;
|
|
371
|
-
te[13] = x.y;
|
|
372
|
-
te[14] = x.z;
|
|
373
|
-
}
|
|
374
|
-
else if (y !== undefined && z !== undefined) {
|
|
375
|
-
te[12] = x;
|
|
376
|
-
te[13] = y;
|
|
377
|
-
te[14] = z;
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
if (x.x !== undefined && x.y !== undefined && x.z !== undefined) {
|
|
381
|
-
te[12] = x.x;
|
|
382
|
-
te[13] = x.y;
|
|
383
|
-
te[14] = x.z;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return this;
|
|
387
|
-
};
|
|
388
|
-
/**
|
|
389
|
-
* 矩阵求逆
|
|
390
|
-
* @returns 自己
|
|
391
|
-
*/
|
|
392
|
-
Mat4.prototype.invert = function () {
|
|
393
|
-
// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
|
|
394
|
-
var te = this.elements, n11 = te[0], n21 = te[1], n31 = te[2], n41 = te[3], n12 = te[4], n22 = te[5], n32 = te[6], n42 = te[7], n13 = te[8], n23 = te[9], n33 = te[10], n43 = te[11], n14 = te[12], n24 = te[13], n34 = te[14], n44 = te[15], t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44, t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44, t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44, t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
|
|
395
|
-
var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
|
|
396
|
-
if (det === 0)
|
|
397
|
-
return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
398
|
-
var detInv = 1 / det;
|
|
399
|
-
te[0] = t11 * detInv;
|
|
400
|
-
te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
|
|
401
|
-
te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
|
|
402
|
-
te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
|
|
403
|
-
te[4] = t12 * detInv;
|
|
404
|
-
te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
|
|
405
|
-
te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
|
|
406
|
-
te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
|
|
407
|
-
te[8] = t13 * detInv;
|
|
408
|
-
te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
|
|
409
|
-
te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
|
|
410
|
-
te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
|
|
411
|
-
te[12] = t14 * detInv;
|
|
412
|
-
te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
|
|
413
|
-
te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
|
|
414
|
-
te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
|
|
415
|
-
return this;
|
|
416
|
-
};
|
|
417
|
-
Mat4.prototype.getInverse = function (m, throwOnDegenerate) {
|
|
418
|
-
if (throwOnDegenerate === void 0) { throwOnDegenerate = true; }
|
|
419
|
-
// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
|
|
420
|
-
var te = this.elements, me = m.elements, n11 = me[0], n21 = me[1], n31 = me[2], n41 = me[3], n12 = me[4], n22 = me[5], n32 = me[6], n42 = me[7], n13 = me[8], n23 = me[9], n33 = me[10], n43 = me[11], n14 = me[12], n24 = me[13], n34 = me[14], n44 = me[15], t11 = n23 * n34 * n42 -
|
|
421
|
-
n24 * n33 * n42 +
|
|
422
|
-
n24 * n32 * n43 -
|
|
423
|
-
n22 * n34 * n43 -
|
|
424
|
-
n23 * n32 * n44 +
|
|
425
|
-
n22 * n33 * n44, t12 = n14 * n33 * n42 -
|
|
426
|
-
n13 * n34 * n42 -
|
|
427
|
-
n14 * n32 * n43 +
|
|
428
|
-
n12 * n34 * n43 +
|
|
429
|
-
n13 * n32 * n44 -
|
|
430
|
-
n12 * n33 * n44, t13 = n13 * n24 * n42 -
|
|
431
|
-
n14 * n23 * n42 +
|
|
432
|
-
n14 * n22 * n43 -
|
|
433
|
-
n12 * n24 * n43 -
|
|
434
|
-
n13 * n22 * n44 +
|
|
435
|
-
n12 * n23 * n44, t14 = n14 * n23 * n32 -
|
|
436
|
-
n13 * n24 * n32 -
|
|
437
|
-
n14 * n22 * n33 +
|
|
438
|
-
n12 * n24 * n33 +
|
|
439
|
-
n13 * n22 * n34 -
|
|
440
|
-
n12 * n23 * n34;
|
|
441
|
-
var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
|
|
442
|
-
if (det === 0) {
|
|
443
|
-
var msg = " Mat4: .getInverse() can't invert matrix, determinant is 0";
|
|
444
|
-
if (throwOnDegenerate === true) {
|
|
445
|
-
throw new Error(msg);
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
console.warn(msg);
|
|
449
|
-
}
|
|
450
|
-
return this.identity();
|
|
451
|
-
}
|
|
452
|
-
var detInv = 1 / det;
|
|
453
|
-
te[0] = t11 * detInv;
|
|
454
|
-
te[1] =
|
|
455
|
-
(n24 * n33 * n41 -
|
|
456
|
-
n23 * n34 * n41 -
|
|
457
|
-
n24 * n31 * n43 +
|
|
458
|
-
n21 * n34 * n43 +
|
|
459
|
-
n23 * n31 * n44 -
|
|
460
|
-
n21 * n33 * n44) *
|
|
461
|
-
detInv;
|
|
462
|
-
te[2] =
|
|
463
|
-
(n22 * n34 * n41 -
|
|
464
|
-
n24 * n32 * n41 +
|
|
465
|
-
n24 * n31 * n42 -
|
|
466
|
-
n21 * n34 * n42 -
|
|
467
|
-
n22 * n31 * n44 +
|
|
468
|
-
n21 * n32 * n44) *
|
|
469
|
-
detInv;
|
|
470
|
-
te[3] =
|
|
471
|
-
(n23 * n32 * n41 -
|
|
472
|
-
n22 * n33 * n41 -
|
|
473
|
-
n23 * n31 * n42 +
|
|
474
|
-
n21 * n33 * n42 +
|
|
475
|
-
n22 * n31 * n43 -
|
|
476
|
-
n21 * n32 * n43) *
|
|
477
|
-
detInv;
|
|
478
|
-
te[4] = t12 * detInv;
|
|
479
|
-
te[5] =
|
|
480
|
-
(n13 * n34 * n41 -
|
|
481
|
-
n14 * n33 * n41 +
|
|
482
|
-
n14 * n31 * n43 -
|
|
483
|
-
n11 * n34 * n43 -
|
|
484
|
-
n13 * n31 * n44 +
|
|
485
|
-
n11 * n33 * n44) *
|
|
486
|
-
detInv;
|
|
487
|
-
te[6] =
|
|
488
|
-
(n14 * n32 * n41 -
|
|
489
|
-
n12 * n34 * n41 -
|
|
490
|
-
n14 * n31 * n42 +
|
|
491
|
-
n11 * n34 * n42 +
|
|
492
|
-
n12 * n31 * n44 -
|
|
493
|
-
n11 * n32 * n44) *
|
|
494
|
-
detInv;
|
|
495
|
-
te[7] =
|
|
496
|
-
(n12 * n33 * n41 -
|
|
497
|
-
n13 * n32 * n41 +
|
|
498
|
-
n13 * n31 * n42 -
|
|
499
|
-
n11 * n33 * n42 -
|
|
500
|
-
n12 * n31 * n43 +
|
|
501
|
-
n11 * n32 * n43) *
|
|
502
|
-
detInv;
|
|
503
|
-
te[8] = t13 * detInv;
|
|
504
|
-
te[9] =
|
|
505
|
-
(n14 * n23 * n41 -
|
|
506
|
-
n13 * n24 * n41 -
|
|
507
|
-
n14 * n21 * n43 +
|
|
508
|
-
n11 * n24 * n43 +
|
|
509
|
-
n13 * n21 * n44 -
|
|
510
|
-
n11 * n23 * n44) *
|
|
511
|
-
detInv;
|
|
512
|
-
te[10] =
|
|
513
|
-
(n12 * n24 * n41 -
|
|
514
|
-
n14 * n22 * n41 +
|
|
515
|
-
n14 * n21 * n42 -
|
|
516
|
-
n11 * n24 * n42 -
|
|
517
|
-
n12 * n21 * n44 +
|
|
518
|
-
n11 * n22 * n44) *
|
|
519
|
-
detInv;
|
|
520
|
-
te[11] =
|
|
521
|
-
(n13 * n22 * n41 -
|
|
522
|
-
n12 * n23 * n41 -
|
|
523
|
-
n13 * n21 * n42 +
|
|
524
|
-
n11 * n23 * n42 +
|
|
525
|
-
n12 * n21 * n43 -
|
|
526
|
-
n11 * n22 * n43) *
|
|
527
|
-
detInv;
|
|
528
|
-
te[12] = t14 * detInv;
|
|
529
|
-
te[13] =
|
|
530
|
-
(n13 * n24 * n31 -
|
|
531
|
-
n14 * n23 * n31 +
|
|
532
|
-
n14 * n21 * n33 -
|
|
533
|
-
n11 * n24 * n33 -
|
|
534
|
-
n13 * n21 * n34 +
|
|
535
|
-
n11 * n23 * n34) *
|
|
536
|
-
detInv;
|
|
537
|
-
te[14] =
|
|
538
|
-
(n14 * n22 * n31 -
|
|
539
|
-
n12 * n24 * n31 -
|
|
540
|
-
n14 * n21 * n32 +
|
|
541
|
-
n11 * n24 * n32 +
|
|
542
|
-
n12 * n21 * n34 -
|
|
543
|
-
n11 * n22 * n34) *
|
|
544
|
-
detInv;
|
|
545
|
-
te[15] =
|
|
546
|
-
(n12 * n23 * n31 -
|
|
547
|
-
n13 * n22 * n31 +
|
|
548
|
-
n13 * n21 * n32 -
|
|
549
|
-
n11 * n23 * n32 -
|
|
550
|
-
n12 * n21 * n33 +
|
|
551
|
-
n11 * n22 * n33) *
|
|
552
|
-
detInv;
|
|
553
|
-
return this;
|
|
554
|
-
};
|
|
555
|
-
Mat4.prototype.scale = function (v) {
|
|
556
|
-
var te = this.elements;
|
|
557
|
-
var x = v.x, y = v.y, z = v.z;
|
|
558
|
-
te[0] *= x;
|
|
559
|
-
te[4] *= y;
|
|
560
|
-
te[8] *= z;
|
|
561
|
-
te[1] *= x;
|
|
562
|
-
te[5] *= y;
|
|
563
|
-
te[9] *= z;
|
|
564
|
-
te[2] *= x;
|
|
565
|
-
te[6] *= y;
|
|
566
|
-
te[10] *= z;
|
|
567
|
-
te[3] *= x;
|
|
568
|
-
te[7] *= y;
|
|
569
|
-
te[11] *= z;
|
|
570
|
-
return this;
|
|
571
|
-
};
|
|
572
|
-
Mat4.prototype.getMaxScaleOnAxis = function () {
|
|
573
|
-
var te = this.elements;
|
|
574
|
-
var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
|
|
575
|
-
var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
|
|
576
|
-
var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
|
|
577
|
-
return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
|
|
578
|
-
};
|
|
579
|
-
Mat4.prototype.makeTranslation = function (x, y, z) {
|
|
580
|
-
this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
|
|
581
|
-
return this;
|
|
582
|
-
};
|
|
583
|
-
Mat4.prototype.makeRotationX = function (theta) {
|
|
584
|
-
var c = Math.cos(theta), s = Math.sin(theta);
|
|
585
|
-
this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
|
586
|
-
return this;
|
|
587
|
-
};
|
|
588
|
-
Mat4.prototype.makeRotationY = function (theta) {
|
|
589
|
-
var c = Math.cos(theta), s = Math.sin(theta);
|
|
590
|
-
this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
|
591
|
-
return this;
|
|
592
|
-
};
|
|
593
|
-
Mat4.prototype.makeRotationZ = function (theta) {
|
|
594
|
-
var c = Math.cos(theta), s = Math.sin(theta);
|
|
595
|
-
this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
596
|
-
return this;
|
|
597
|
-
};
|
|
598
|
-
Mat4.prototype.makeRotationAxis = function (axis, angle) {
|
|
599
|
-
// Based on http://www.gamedev.net/reference/articles/article1199.asp
|
|
600
|
-
var c = Math.cos(angle);
|
|
601
|
-
var s = Math.sin(angle);
|
|
602
|
-
var t = 1 - c;
|
|
603
|
-
var x = axis.x, y = axis.y, z = axis.z;
|
|
604
|
-
var tx = t * x, ty = t * y;
|
|
605
|
-
this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
|
|
606
|
-
return this;
|
|
607
|
-
};
|
|
608
|
-
Mat4.prototype.makeScale = function (x, y, z) {
|
|
609
|
-
this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
|
|
610
|
-
return this;
|
|
611
|
-
};
|
|
612
|
-
/**
|
|
613
|
-
* 6个参数 都是由两个值来影响 [v1][v2] v1表示v2轴在v1轴产生效果
|
|
614
|
-
* @param xy
|
|
615
|
-
* @param xz
|
|
616
|
-
* @param yx
|
|
617
|
-
* @param yz
|
|
618
|
-
* @param zx
|
|
619
|
-
* @param zy
|
|
620
|
-
* @returns
|
|
621
|
-
*/
|
|
622
|
-
Mat4.prototype.makeShear = function (xy, xz, yx, yz, zx, zy) {
|
|
623
|
-
this.set(1, yx, zx, 0, xy, 1, zy, 0, xz, yz, 1, 0, 0, 0, 0, 1);
|
|
624
|
-
return this;
|
|
625
|
-
};
|
|
626
|
-
Mat4.prototype.compose = function (position, quat, scale) {
|
|
627
|
-
var te = this.elements;
|
|
628
|
-
var x = quat._x, y = quat._y, z = quat._z, w = quat._w;
|
|
629
|
-
var x2 = x + x, y2 = y + y, z2 = z + z;
|
|
630
|
-
var xx = x * x2, xy = x * y2, xz = x * z2;
|
|
631
|
-
var yy = y * y2, yz = y * z2, zz = z * z2;
|
|
632
|
-
var wx = w * x2, wy = w * y2, wz = w * z2;
|
|
633
|
-
var sx = scale.x, sy = scale.y, sz = scale.z;
|
|
634
|
-
te[0] = (1 - (yy + zz)) * sx;
|
|
635
|
-
te[1] = (xy + wz) * sx;
|
|
636
|
-
te[2] = (xz - wy) * sx;
|
|
637
|
-
te[3] = 0;
|
|
638
|
-
te[4] = (xy - wz) * sy;
|
|
639
|
-
te[5] = (1 - (xx + zz)) * sy;
|
|
640
|
-
te[6] = (yz + wx) * sy;
|
|
641
|
-
te[7] = 0;
|
|
642
|
-
te[8] = (xz + wy) * sz;
|
|
643
|
-
te[9] = (yz - wx) * sz;
|
|
644
|
-
te[10] = (1 - (xx + yy)) * sz;
|
|
645
|
-
te[11] = 0;
|
|
646
|
-
te[12] = position.x;
|
|
647
|
-
te[13] = position.y;
|
|
648
|
-
te[14] = position.z;
|
|
649
|
-
te[15] = 1;
|
|
650
|
-
return this;
|
|
651
|
-
};
|
|
652
|
-
Mat4.prototype.decompose = function (position, quat, scale) {
|
|
653
|
-
var te = this.elements;
|
|
654
|
-
var sx = _v1.set(te[0], te[1], te[2]).length();
|
|
655
|
-
var sy = _v1.set(te[4], te[5], te[6]).length();
|
|
656
|
-
var sz = _v1.set(te[8], te[9], te[10]).length();
|
|
657
|
-
// if determine is negative, we need to invert one scale
|
|
658
|
-
var det = this.determinant();
|
|
659
|
-
if (det < 0)
|
|
660
|
-
sx = -sx;
|
|
661
|
-
position.x = te[12];
|
|
662
|
-
position.y = te[13];
|
|
663
|
-
position.z = te[14];
|
|
664
|
-
// scale the rotation part
|
|
665
|
-
_m1.copy(this);
|
|
666
|
-
var invSX = 1 / sx;
|
|
667
|
-
var invSY = 1 / sy;
|
|
668
|
-
var invSZ = 1 / sz;
|
|
669
|
-
_m1.elements[0] *= invSX;
|
|
670
|
-
_m1.elements[1] *= invSX;
|
|
671
|
-
_m1.elements[2] *= invSX;
|
|
672
|
-
_m1.elements[4] *= invSY;
|
|
673
|
-
_m1.elements[5] *= invSY;
|
|
674
|
-
_m1.elements[6] *= invSY;
|
|
675
|
-
_m1.elements[8] *= invSZ;
|
|
676
|
-
_m1.elements[9] *= invSZ;
|
|
677
|
-
_m1.elements[10] *= invSZ;
|
|
678
|
-
quat.setFromRotationMat(_m1);
|
|
679
|
-
scale.x = sx;
|
|
680
|
-
scale.y = sy;
|
|
681
|
-
scale.z = sz;
|
|
682
|
-
return this;
|
|
683
|
-
};
|
|
684
|
-
Mat4.prototype.makePerspective = function (left, right, top, bottom, near, far) {
|
|
685
|
-
if (far === undefined) {
|
|
686
|
-
console.warn(" Mat4: .makePerspective() has been redefined and has a new signature. Please check the docs.");
|
|
687
|
-
}
|
|
688
|
-
var te = this.elements;
|
|
689
|
-
var x = (2 * near) / (right - left);
|
|
690
|
-
var y = (2 * near) / (top - bottom);
|
|
691
|
-
var a = (right + left) / (right - left);
|
|
692
|
-
var b = (top + bottom) / (top - bottom);
|
|
693
|
-
var c = -(far + near) / (far - near);
|
|
694
|
-
var d = (-2 * far * near) / (far - near);
|
|
695
|
-
te[0] = x;
|
|
696
|
-
te[4] = 0;
|
|
697
|
-
te[8] = a;
|
|
698
|
-
te[12] = 0;
|
|
699
|
-
te[1] = 0;
|
|
700
|
-
te[5] = y;
|
|
701
|
-
te[9] = b;
|
|
702
|
-
te[13] = 0;
|
|
703
|
-
te[2] = 0;
|
|
704
|
-
te[6] = 0;
|
|
705
|
-
te[10] = c;
|
|
706
|
-
te[14] = d;
|
|
707
|
-
te[3] = 0;
|
|
708
|
-
te[7] = 0;
|
|
709
|
-
te[11] = -1;
|
|
710
|
-
te[15] = 0;
|
|
711
|
-
return this;
|
|
712
|
-
};
|
|
713
|
-
Mat4.prototype.makeOrthographic = function (left, right, top, bottom, near, far) {
|
|
714
|
-
var te = this.elements;
|
|
715
|
-
var w = 1.0 / (right - left);
|
|
716
|
-
var h = 1.0 / (top - bottom);
|
|
717
|
-
var p = 1.0 / (far - near);
|
|
718
|
-
var x = (right + left) * w;
|
|
719
|
-
var y = (top + bottom) * h;
|
|
720
|
-
var z = (far + near) * p;
|
|
721
|
-
te[0] = 2 * w;
|
|
722
|
-
te[4] = 0;
|
|
723
|
-
te[8] = 0;
|
|
724
|
-
te[12] = -x;
|
|
725
|
-
te[1] = 0;
|
|
726
|
-
te[5] = 2 * h;
|
|
727
|
-
te[9] = 0;
|
|
728
|
-
te[13] = -y;
|
|
729
|
-
te[2] = 0;
|
|
730
|
-
te[6] = 0;
|
|
731
|
-
te[10] = -2 * p;
|
|
732
|
-
te[14] = -z;
|
|
733
|
-
te[3] = 0;
|
|
734
|
-
te[7] = 0;
|
|
735
|
-
te[11] = 0;
|
|
736
|
-
te[15] = 1;
|
|
737
|
-
return this;
|
|
738
|
-
};
|
|
739
|
-
Mat4.prototype.equals = function (matrix) {
|
|
740
|
-
var te = this.elements;
|
|
741
|
-
var me = matrix.elements;
|
|
742
|
-
for (var i = 0; i < 16; i++) {
|
|
743
|
-
if (te[i] !== me[i])
|
|
744
|
-
return false;
|
|
745
|
-
}
|
|
746
|
-
return true;
|
|
747
|
-
};
|
|
748
|
-
Mat4.prototype.fromArray = function (array, offset) {
|
|
749
|
-
if (offset === void 0) { offset = 0; }
|
|
750
|
-
for (var i = 0; i < 16; i++) {
|
|
751
|
-
this.elements[i] = array[i + offset];
|
|
752
|
-
}
|
|
753
|
-
return this;
|
|
754
|
-
};
|
|
755
|
-
Mat4.prototype.toArray = function (array, offset) {
|
|
756
|
-
if (array === void 0) { array = []; }
|
|
757
|
-
if (offset === void 0) { offset = 0; }
|
|
758
|
-
var te = this.elements;
|
|
759
|
-
array[offset] = te[0];
|
|
760
|
-
array[offset + 1] = te[1];
|
|
761
|
-
array[offset + 2] = te[2];
|
|
762
|
-
array[offset + 3] = te[3];
|
|
763
|
-
array[offset + 4] = te[4];
|
|
764
|
-
array[offset + 5] = te[5];
|
|
765
|
-
array[offset + 6] = te[6];
|
|
766
|
-
array[offset + 7] = te[7];
|
|
767
|
-
array[offset + 8] = te[8];
|
|
768
|
-
array[offset + 9] = te[9];
|
|
769
|
-
array[offset + 10] = te[10];
|
|
770
|
-
array[offset + 11] = te[11];
|
|
771
|
-
array[offset + 12] = te[12];
|
|
772
|
-
array[offset + 13] = te[13];
|
|
773
|
-
array[offset + 14] = te[14];
|
|
774
|
-
array[offset + 15] = te[15];
|
|
775
|
-
return array;
|
|
776
|
-
};
|
|
777
|
-
return Mat4;
|
|
778
|
-
}());
|
|
779
|
-
exports.Mat4 = Mat4;
|
|
780
|
-
var _v1 = (0, Vec3_1.v3)();
|
|
781
|
-
var _m1 = m4();
|
|
782
|
-
var _m2 = m4();
|
|
783
|
-
var _zero = (0, Vec3_1.v3)(0, 0, 0);
|
|
784
|
-
var _one = (0, Vec3_1.v3)(1, 1, 1);
|
|
785
|
-
var _x = (0, Vec3_1.v3)();
|
|
786
|
-
var _y = (0, Vec3_1.v3)();
|
|
787
|
-
var _z = (0, Vec3_1.v3)();
|
|
788
|
-
function m4() {
|
|
789
|
-
return new Mat4();
|
|
790
|
-
}
|
|
791
|
-
exports.m4 = m4;
|