UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

176 lines (175 loc) 5.3 kB
/** * @import { Mat4 } from './mat4.js' * @import { Quat } from './quat.js' */ /** * A 3x3 matrix. * * @category Math */ export class Mat3 { /** * A constant matrix set to the identity. * * @type {Mat3} * @readonly */ static readonly IDENTITY: Mat3; /** * A constant matrix with all elements set to 0. * * @type {Mat3} * @readonly */ static readonly ZERO: Mat3; /** * Matrix elements in the form of a flat array. * * @type {Float32Array} */ data: Float32Array; /** * Creates a duplicate of the specified matrix. * * @returns {this} A duplicate matrix. * @example * const src = new pc.Mat3().translate(10, 20, 30); * const dst = src.clone(); * console.log("The two matrices are " + (src.equals(dst) ? "equal" : "different")); */ clone(): this; /** * Copies the contents of a source 3x3 matrix to a destination 3x3 matrix. * * @param {Mat3} rhs - A 3x3 matrix to be copied. * @returns {Mat3} Self for chaining. * @example * const src = new pc.Mat3().translate(10, 20, 30); * const dst = new pc.Mat3(); * dst.copy(src); * console.log("The two matrices are " + (src.equals(dst) ? "equal" : "different")); */ copy(rhs: Mat3): Mat3; /** * Copies the contents of a source array[9] to a destination 3x3 matrix. * * @param {number[]} src - An array[9] to be copied. * @returns {Mat3} Self for chaining. * @example * const dst = new pc.Mat3(); * dst.set([0, 1, 2, 3, 4, 5, 6, 7, 8]); */ set(src: number[]): Mat3; /** * Extracts the x-axis from the specified matrix. * * @param {Vec3} [x] - The vector to receive the x axis of the matrix. * @returns {Vec3} The x-axis of the specified matrix. */ getX(x?: Vec3): Vec3; /** * Extracts the y-axis from the specified matrix. * * @param {Vec3} [y] - The vector to receive the y axis of the matrix. * @returns {Vec3} The y-axis of the specified matrix. */ getY(y?: Vec3): Vec3; /** * Extracts the z-axis from the specified matrix. * * @param {Vec3} [z] - The vector to receive the z axis of the matrix. * @returns {Vec3} The z-axis of the specified matrix. */ getZ(z?: Vec3): Vec3; /** * Reports whether two matrices are equal. * * @param {Mat3} rhs - The other matrix. * @returns {boolean} True if the matrices are equal and false otherwise. * @example * const a = new pc.Mat3().translate(10, 20, 30); * const b = new pc.Mat3(); * console.log("The two matrices are " + (a.equals(b) ? "equal" : "different")); */ equals(rhs: Mat3): boolean; /** * Reports whether the specified matrix is the identity matrix. * * @returns {boolean} True if the matrix is identity and false otherwise. * @example * const m = new pc.Mat3(); * console.log("The matrix is " + (m.isIdentity() ? "identity" : "not identity")); */ isIdentity(): boolean; /** * Sets the matrix to the identity matrix. * * @returns {Mat3} Self for chaining. * @example * m.setIdentity(); * console.log("The matrix is " + (m.isIdentity() ? "identity" : "not identity")); */ setIdentity(): Mat3; /** * Converts the matrix to string form. * * @returns {string} The matrix in string form. * @example * const m = new pc.Mat3(); * // Outputs [1, 0, 0, 0, 1, 0, 0, 0, 1] * console.log(m.toString()); */ toString(): string; /** * Generates the transpose of the specified 3x3 matrix. * * @param {Mat3} [src] - The matrix to transpose. If not set, the matrix is transposed in-place. * @returns {Mat3} Self for chaining. * @example * const m = new pc.Mat3(); * * // Transpose in place * m.transpose(); */ transpose(src?: Mat3): Mat3; /** * Converts the specified 4x4 matrix to a Mat3. * * @param {Mat4} m - The 4x4 matrix to convert. * @returns {Mat3} Self for chaining. */ setFromMat4(m: Mat4): Mat3; /** * Sets this matrix to the given quaternion rotation. * * @param {Quat} r - A quaternion rotation. * @returns {Mat3} Self for chaining. * @example * const r = new pc.Quat(1, 2, 3, 4).normalize(); * * const m = new pc.Mat4(); * m.setFromQuat(r); */ setFromQuat(r: Quat): Mat3; /** * Set the matrix to the inverse of the specified 4x4 matrix. * * @param {Mat4} src - The 4x4 matrix to invert. * @returns {Mat3} Self for chaining. * * @ignore */ invertMat4(src: Mat4): Mat3; /** * Transforms a 3-dimensional vector by a 3x3 matrix. * * @param {Vec3} vec - The 3-dimensional vector to be transformed. * @param {Vec3} [res] - An optional 3-dimensional vector to receive the result of the * transformation. * @returns {Vec3} The input vector v transformed by the current instance. */ transformVector(vec: Vec3, res?: Vec3): Vec3; } import { Vec3 } from './vec3.js'; import type { Mat4 } from './mat4.js'; import type { Quat } from './quat.js';