UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

74 lines 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Matrix4 = void 0; const tslib_1 = require("tslib"); const decorators_1 = require("../../data/decorators"); const THREE = require("./_internal"); /** * Serializable THREE.js Matrix4 */ let Matrix4 = class Matrix4 extends THREE.Matrix4 { static round(value, decimals = 0) { const pow = Math.pow(10, decimals); value.elements.forEach((e, i) => { value.elements[i] = Math.round(e * pow) / pow; }); return value; } /** * Create a matrix from array * @param {number[][]} array Array * @returns {Matrix4} Matrix4 */ static fromArray(array) { const matrix = new this(); matrix.fromArray([].concat(...array)); matrix.transpose(); return matrix; } /** * Create a rotation matrix from quaternion * @param {THREE.Quaternion} quat Quaternion * @returns {Matrix4} Rotation matrix */ static rotationFromQuaternion(quat) { const matrix = new this(); matrix.makeRotationFromQuaternion(quat); return matrix; } /** * Create a rotation matrix from euler angles * @param {THREE.Euler} euler Euler angles * @returns {Matrix4} Rotation matrix */ static rotationFromEuler(euler) { const matrix = new this(); matrix.makeRotationFromEuler(euler); return matrix; } /** * Create a rotation matrix from euler angles * @param {THREE.Vector3} vector Vector * @param {number} angle Angle * @returns {Matrix4} Rotation matrix */ static rotationFromAxisAngle(vector, angle) { const matrix = new this(); matrix.makeRotationAxis(vector, angle); return matrix; } clone() { return new this.constructor().fromArray(this.elements); } }; exports.Matrix4 = Matrix4; tslib_1.__decorate([ (0, decorators_1.SerializableArrayMember)(Number, { numberType: decorators_1.NumberType.DECIMAL, }), tslib_1.__metadata("design:type", Array) ], Matrix4.prototype, "elements", void 0); exports.Matrix4 = Matrix4 = tslib_1.__decorate([ (0, decorators_1.SerializableObject)() ], Matrix4); //# sourceMappingURL=Matrix4.js.map