UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

65 lines 1.93 kB
import { __decorate, __metadata } from "tslib"; import { SerializableArrayMember, SerializableObject, NumberType } from '../../data/decorators'; import * as THREE from './_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); } }; __decorate([SerializableArrayMember(Number, { numberType: NumberType.DECIMAL }), __metadata("design:type", Array)], Matrix4.prototype, "elements", void 0); Matrix4 = __decorate([SerializableObject()], Matrix4); export { Matrix4 };