123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.SMatrix = void 0;
- var SMatrix = (function () {
- function SMatrix() {
- this.m11 = 1;
- this.m21 = 0;
- this.m31 = 0;
- this.m41 = 0;
- this.m12 = 0;
- this.m22 = 1;
- this.m32 = 0;
- this.m42 = 0;
- this.m13 = 0;
- this.m23 = 0;
- this.m33 = 1;
- this.m43 = 0;
- this.m14 = 0;
- this.m24 = 0;
- this.m34 = 0;
- this.m44 = 1;
- }
- Object.defineProperty(SMatrix.prototype, "a", {
- get: function () {
- return this.m11;
- },
- set: function (v) {
- this.m11 = v;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(SMatrix.prototype, "b", {
- get: function () {
- return this.m12;
- },
- set: function (v) {
- this.m12 = v;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(SMatrix.prototype, "c", {
- get: function () {
- return this.m21;
- },
- set: function (v) {
- this.m21 = v;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(SMatrix.prototype, "d", {
- get: function () {
- return this.m22;
- },
- set: function (v) {
- this.m22 = v;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(SMatrix.prototype, "e", {
- get: function () {
- return this.m41;
- },
- set: function (v) {
- this.m41 = v;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(SMatrix.prototype, "f", {
- get: function () {
- return this.m42;
- },
- set: function (v) {
- this.m42 = v;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(SMatrix.prototype, "is2D", {
- get: function () {
- return true;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(SMatrix.prototype, "isIdentity", {
- get: function () {
- return (this.m11 == 1 &&
- this.m21 == 0 &&
- this.m31 == 0 &&
- this.m41 == 0 &&
- this.m12 == 0 &&
- this.m22 == 1 &&
- this.m32 == 0 &&
- this.m42 == 0 &&
- this.m13 == 0 &&
- this.m23 == 0 &&
- this.m33 == 1 &&
- this.m43 == 0 &&
- this.m14 == 0 &&
- this.m24 == 0 &&
- this.m34 == 0 &&
- this.m44 == 1);
- },
- enumerable: false,
- configurable: true
- });
- SMatrix.prototype.reset = function () {
- this.m11 = 1;
- this.m21 = 0;
- this.m31 = 0;
- this.m41 = 0;
- this.m12 = 0;
- this.m22 = 1;
- this.m32 = 0;
- this.m42 = 0;
- this.m13 = 0;
- this.m23 = 0;
- this.m33 = 1;
- this.m43 = 0;
- this.m14 = 0;
- this.m24 = 0;
- this.m34 = 0;
- this.m44 = 1;
- return this;
- };
- SMatrix.prototype.multiply = function (mat) {
- var _a;
- _a = [
- this.m11 * mat.m11 +
- this.m21 * mat.m12 +
- this.m31 * mat.m13 +
- this.m41 * mat.m14,
- this.m11 * mat.m21 +
- this.m21 * mat.m22 +
- this.m31 * mat.m23 +
- this.m41 * mat.m24,
- this.m11 * mat.m31 +
- this.m21 * mat.m32 +
- this.m31 * mat.m33 +
- this.m41 * mat.m34,
- this.m11 * mat.m41 +
- this.m21 * mat.m42 +
- this.m31 * mat.m43 +
- this.m41 * mat.m44,
- this.m12 * mat.m11 +
- this.m22 * mat.m12 +
- this.m32 * mat.m13 +
- this.m42 * mat.m14,
- this.m12 * mat.m21 +
- this.m22 * mat.m22 +
- this.m32 * mat.m23 +
- this.m42 * mat.m24,
- this.m12 * mat.m31 +
- this.m22 * mat.m32 +
- this.m32 * mat.m33 +
- this.m42 * mat.m34,
- this.m12 * mat.m41 +
- this.m22 * mat.m42 +
- this.m32 * mat.m43 +
- this.m42 * mat.m44,
- this.m13 * mat.m11 +
- this.m23 * mat.m12 +
- this.m33 * mat.m13 +
- this.m43 * mat.m14,
- this.m13 * mat.m21 +
- this.m23 * mat.m22 +
- this.m33 * mat.m23 +
- this.m43 * mat.m24,
- this.m13 * mat.m31 +
- this.m23 * mat.m32 +
- this.m33 * mat.m33 +
- this.m43 * mat.m34,
- this.m13 * mat.m41 +
- this.m23 * mat.m42 +
- this.m33 * mat.m43 +
- this.m43 * mat.m44,
- this.m14 * mat.m11 +
- this.m24 * mat.m12 +
- this.m34 * mat.m13 +
- this.m44 * mat.m14,
- this.m14 * mat.m21 +
- this.m24 * mat.m22 +
- this.m34 * mat.m23 +
- this.m44 * mat.m24,
- this.m14 * mat.m31 +
- this.m24 * mat.m32 +
- this.m34 * mat.m33 +
- this.m44 * mat.m34,
- this.m14 * mat.m41 +
- this.m24 * mat.m42 +
- this.m34 * mat.m43 +
- this.m44 * mat.m44
- ], this.m11 = _a[0], this.m21 = _a[1], this.m31 = _a[2], this.m41 = _a[3], this.m12 = _a[4], this.m22 = _a[5], this.m32 = _a[6], this.m42 = _a[7], this.m13 = _a[8], this.m23 = _a[9], this.m33 = _a[10], this.m43 = _a[11], this.m14 = _a[12], this.m24 = _a[13], this.m34 = _a[14], this.m44 = _a[15];
- return this;
- };
- SMatrix.prototype.translate = function (dx, dy, dz) {
- if (dz === void 0) { dz = 0; }
- var mat = new SMatrix();
- mat.m41 = dx;
- mat.m42 = dy;
- mat.m43 = dz;
- this.multiply(mat);
- return this;
- };
- SMatrix.prototype.scale = function (sx, sy) {
- var mat = new SMatrix();
- mat.m11 = sx;
- mat.m22 = sy;
- this.multiply(mat);
- return this;
- };
- SMatrix.prototype.rotate = function (rotX, rotY, rotZ) {
- var matZ = new SMatrix();
- if (rotY != undefined && rotZ != undefined) {
- var matX = new SMatrix();
- matX.m22 = Math.cos((rotX * Math.PI) / 180);
- matX.m32 = -Math.sin((rotX * Math.PI) / 180);
- matX.m23 = Math.sin((rotX * Math.PI) / 180);
- matX.m33 = Math.cos((rotX * Math.PI) / 180);
- this.multiply(matX);
- var matY = new SMatrix();
- matY.m11 = Math.cos((rotY * Math.PI) / 180);
- matY.m31 = Math.sin((rotY * Math.PI) / 180);
- matY.m13 = -Math.sin((rotY * Math.PI) / 180);
- matY.m33 = Math.cos((rotY * Math.PI) / 180);
- this.multiply(matY);
- matZ.m11 = Math.cos((rotZ * Math.PI) / 180);
- matZ.m21 = -Math.sin((rotZ * Math.PI) / 180);
- matZ.m12 = Math.sin((rotZ * Math.PI) / 180);
- matZ.m22 = Math.cos((rotZ * Math.PI) / 180);
- this.multiply(matZ);
- return this;
- }
- else {
- matZ.m11 = Math.cos((rotX * Math.PI) / 180);
- matZ.m21 = -Math.sin((rotX * Math.PI) / 180);
- matZ.m12 = Math.sin((rotX * Math.PI) / 180);
- matZ.m22 = Math.cos((rotX * Math.PI) / 180);
- this.multiply(matZ);
- return this;
- }
- };
- SMatrix.prototype.transpose = function () {
- var _a, _b, _c, _d, _e, _f;
- _a = [this.m21, this.m12], this.m12 = _a[0], this.m21 = _a[1];
- _b = [this.m31, this.m13], this.m13 = _b[0], this.m31 = _b[1];
- _c = [this.m41, this.m14], this.m14 = _c[0], this.m41 = _c[1];
- _d = [this.m32, this.m23], this.m23 = _d[0], this.m32 = _d[1];
- _e = [this.m42, this.m24], this.m24 = _e[0], this.m42 = _e[1];
- _f = [this.m43, this.m34], this.m34 = _f[0], this.m43 = _f[1];
- return this;
- };
- SMatrix.prototype.inversed = function () {
- var detMat = this.det();
- var d = this.value();
- var ret = new SMatrix();
- ret.m11 = detMat.m11 / d;
- ret.m21 = detMat.m21 / d;
- ret.m31 = detMat.m31 / d;
- ret.m41 = detMat.m41 / d;
- ret.m12 = detMat.m12 / d;
- ret.m22 = detMat.m22 / d;
- ret.m32 = detMat.m32 / d;
- ret.m42 = detMat.m42 / d;
- ret.m13 = detMat.m13 / d;
- ret.m23 = detMat.m23 / d;
- ret.m33 = detMat.m33 / d;
- ret.m43 = detMat.m43 / d;
- ret.m14 = detMat.m14 / d;
- ret.m24 = detMat.m24 / d;
- ret.m34 = detMat.m34 / d;
- ret.m44 = detMat.m44 / d;
- return ret;
- };
- SMatrix.prototype.det = function () {
- var m = new SMatrix();
- m.m11 =
- this.m22 * this.m33 * this.m44 +
- this.m32 * this.m43 * this.m24 +
- this.m42 * this.m23 * this.m34 -
- this.m42 * this.m33 * this.m24 -
- this.m32 * this.m23 * this.m44 -
- this.m22 * this.m43 * this.m34;
- m.m12 = -(this.m12 * this.m33 * this.m44 +
- this.m32 * this.m43 * this.m14 +
- this.m42 * this.m13 * this.m34 -
- this.m42 * this.m33 * this.m14 -
- this.m32 * this.m13 * this.m44 -
- this.m12 * this.m43 * this.m34);
- m.m13 =
- this.m12 * this.m23 * this.m44 +
- this.m22 * this.m43 * this.m14 +
- this.m42 * this.m13 * this.m24 -
- this.m42 * this.m23 * this.m14 -
- this.m22 * this.m13 * this.m44 -
- this.m12 * this.m43 * this.m24;
- m.m14 = -(this.m12 * this.m23 * this.m34 +
- this.m22 * this.m33 * this.m14 +
- this.m32 * this.m13 * this.m24 -
- this.m32 * this.m23 * this.m14 -
- this.m22 * this.m13 * this.m34 -
- this.m12 * this.m33 * this.m24);
- m.m21 = -(this.m21 * this.m33 * this.m44 +
- this.m31 * this.m43 * this.m24 +
- this.m41 * this.m23 * this.m34 -
- this.m41 * this.m33 * this.m24 -
- this.m31 * this.m23 * this.m44 -
- this.m21 * this.m43 * this.m34);
- m.m22 =
- this.m11 * this.m33 * this.m44 +
- this.m31 * this.m43 * this.m14 +
- this.m41 * this.m13 * this.m34 -
- this.m41 * this.m33 * this.m14 -
- this.m31 * this.m13 * this.m44 -
- this.m11 * this.m43 * this.m34;
- m.m23 = -(this.m11 * this.m23 * this.m44 +
- this.m21 * this.m43 * this.m14 +
- this.m41 * this.m13 * this.m24 -
- this.m41 * this.m23 * this.m14 -
- this.m21 * this.m13 * this.m44 -
- this.m11 * this.m43 * this.m24);
- m.m24 =
- this.m11 * this.m23 * this.m34 +
- this.m21 * this.m33 * this.m14 +
- this.m31 * this.m13 * this.m24 -
- this.m31 * this.m23 * this.m14 -
- this.m21 * this.m13 * this.m34 -
- this.m11 * this.m33 * this.m24;
- m.m31 =
- this.m21 * this.m32 * this.m44 +
- this.m31 * this.m42 * this.m24 +
- this.m41 * this.m22 * this.m34 -
- this.m41 * this.m32 * this.m24 -
- this.m31 * this.m22 * this.m44 -
- this.m21 * this.m42 * this.m34;
- m.m32 = -(this.m11 * this.m32 * this.m44 +
- this.m31 * this.m42 * this.m14 +
- this.m41 * this.m12 * this.m34 -
- this.m41 * this.m32 * this.m14 -
- this.m31 * this.m12 * this.m44 -
- this.m11 * this.m42 * this.m34);
- m.m33 =
- this.m11 * this.m22 * this.m44 +
- this.m21 * this.m42 * this.m14 +
- this.m41 * this.m12 * this.m24 -
- this.m41 * this.m22 * this.m14 -
- this.m21 * this.m12 * this.m44 -
- this.m11 * this.m42 * this.m24;
- m.m34 = -(this.m11 * this.m22 * this.m34 +
- this.m21 * this.m32 * this.m14 +
- this.m31 * this.m12 * this.m24 -
- this.m31 * this.m22 * this.m14 -
- this.m21 * this.m12 * this.m34 -
- this.m11 * this.m32 * this.m24);
- m.m41 = -(this.m21 * this.m32 * this.m43 +
- this.m31 * this.m42 * this.m23 +
- this.m41 * this.m22 * this.m33 -
- this.m41 * this.m32 * this.m23 -
- this.m31 * this.m22 * this.m43 -
- this.m21 * this.m42 * this.m33);
- m.m42 =
- this.m11 * this.m32 * this.m43 +
- this.m31 * this.m42 * this.m13 +
- this.m41 * this.m12 * this.m33 -
- this.m41 * this.m32 * this.m13 -
- this.m31 * this.m12 * this.m43 -
- this.m11 * this.m42 * this.m33;
- m.m43 = -(this.m11 * this.m22 * this.m43 +
- this.m21 * this.m42 * this.m13 +
- this.m41 * this.m12 * this.m23 -
- this.m41 * this.m22 * this.m13 -
- this.m21 * this.m12 * this.m43 -
- this.m11 * this.m42 * this.m23);
- m.m44 =
- this.m11 * this.m22 * this.m33 +
- this.m21 * this.m32 * this.m13 +
- this.m31 * this.m12 * this.m23 -
- this.m31 * this.m22 * this.m13 -
- this.m21 * this.m12 * this.m33 -
- this.m11 * this.m32 * this.m23;
- return m;
- };
- SMatrix.prototype.value = function () {
- return (this.m11 *
- (this.m22 * this.m33 * this.m44 +
- this.m32 * this.m43 * this.m24 +
- this.m42 * this.m23 * this.m34 -
- this.m42 * this.m33 * this.m24 -
- this.m32 * this.m23 * this.m44 -
- this.m22 * this.m43 * this.m34) -
- this.m21 *
- (this.m12 * this.m33 * this.m44 +
- this.m32 * this.m43 * this.m14 +
- this.m42 * this.m13 * this.m34 -
- this.m42 * this.m33 * this.m14 -
- this.m32 * this.m13 * this.m44 -
- this.m12 * this.m43 * this.m34) +
- this.m31 *
- (this.m12 * this.m23 * this.m44 +
- this.m22 * this.m43 * this.m14 +
- this.m42 * this.m13 * this.m24 -
- this.m42 * this.m23 * this.m14 -
- this.m22 * this.m13 * this.m44 -
- this.m12 * this.m43 * this.m24) -
- this.m41 *
- (this.m12 * this.m23 * this.m34 +
- this.m22 * this.m33 * this.m14 +
- this.m32 * this.m13 * this.m24 -
- this.m32 * this.m23 * this.m14 -
- this.m22 * this.m13 * this.m34 -
- this.m12 * this.m33 * this.m24));
- };
- return SMatrix;
- }());
- exports.SMatrix = SMatrix;
|