import { quat } from './quat'; import type { vec4 } from './vec4'; import { vec3 } from './vec3'; /** * 4x4 Matrix representing 3D affine transformation. The format is column-major, when typed out it looks like row-major. The matrices are being post multiplied. * ```ts * [xx, xy, xz, 0, * yx, yy, yz, 0, * zx, zy, zz, 0, * tx, ty, tz, 1] * ``` * @category Types */ export type mat4 = readonly [ m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number ]; /** * Functions for {@link mat4}, 3D affine transformation. * @category Modules */ export declare namespace mat4 { /** * Mutable version of {@link mat4} * @category Types */ export type Mutable = [ m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number ]; /** * Creates a new matrix from given elements * @category Generators */ export function of(m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number): mat4; /** * Creates a mutable clone of given mat4 * @category Generators */ export function clone(a: mat4): Mutable; /** * The identity matrix of mat4 * ```ts * [1, 0, 0, 0, * 0, 1, 0, 0, * 0, 0, 1, 0, * 0, 0, 0, 1] * ``` * @category Constants * * @shorthands * - {@link id} * - {@link ident} */ export const identity: mat4; /** * Alias for {@link identity} * @category Shorthands */ export const I: mat4; /** * Alias for {@link identity} * @category Shorthands */ export const id: mat4; /** * Alias for {@link identity} * @category Shorthands */ export const ident: mat4; /** * @category Constants */ export const zero: mat4; /** * Transpose the values of a mat4 */ export function transpose(a: mat4): mat4; /** * Inverts a mat4 * * @shorthands * - {@link inv} */ export function invert(a: mat4): mat4 | null; /** * Alias for {@link invert} * @category Shorthands */ export const inv: typeof invert; /** * Calculates the adjugate of a mat4 */ export function adjoint(a: mat4): mat4; /** * Calculates the determinant of a mat4 * * @shorthands * - {@link det} */ export function determinant(a: mat4): number; /** * Alias for {@link determinant} * @category Shorthands */ export const det: typeof determinant; /** * Multiplies given mat4's * * @shorthands * - {@link mul} */ export function multiply(...ms: mat4[]): mat4; /** * Alias for {@link multiply} * @category Shorthands */ export const mul: typeof multiply; /** * Translate a mat4 by the given vector * * @param a the matrix to translate * @param v vector to translate by */ export function translate(a: mat4, v: vec3): mat4; /** * Scales the mat4 by the dimensions in the given vec3 not using vectorization **/ export function scale(a: mat4, v: vec3): mat4; /** * Rotates a mat4 by the given angle around the given axis */ export function rotate(a: mat4, deg: number, axis: vec3): mat4 | null; /** * Rotates a matrix by the given angle around the X axis */ export function rotateX(a: mat4, deg: number): mat4; /** * Rotates a matrix by the given angle around the Y axis */ export function rotateY(a: mat4, deg: number): mat4; /** * Rotates a matrix by the given angle around the Z axis */ export function rotateZ(a: mat4, deg: number): mat4; /** * Creates a matrix from given axes and translation vector. If either axis is null, it will be calculated from the remaining axes while assuming the other axis is the cross product of the remaining axes. All of axes will not be normalized. * @category Generators */ export function fromAxesTranslation(xAxis: vec3 | null, yAxis: vec3 | null, zAxis?: vec3 | null, trans?: vec3): mat4; /** * Creates a matrix from a vector translation * @category Generators * * @shorthands * - {@link translation} */ export function fromTranslation(v: vec3): mat4; /** * Alias for {@link fromTranslation} * @category Shorthands */ export const translation: typeof fromTranslation; /** * Creates a matrix from a vector scaling * @category Generators * * @shorthands * - {@link scaling} */ export function fromScaling(v: vec3): mat4; /** * Alias for {@link fromScaling} * @category Shorthands */ export const scaling: typeof fromScaling; /** * Creates a matrix from a given angle around a given axis * Creates a matrix from a given angle. * @param deg The angle to rotate the matrix by, in degrees * @param axis The axis to rotate around * @category Generators * * @shorthands * - {@link rotation} */ export function fromRotation(deg: number, axis: vec3): mat4 | null; /** * Alias for {@link fromRotation} * @category Shorthands */ export const rotation: typeof fromRotation; /** * Creates a matrix from the given angle around the X axis * @category Generators */ export function fromXRotation(deg: number): mat4; /** * Creates a matrix from the given angle around the Y axis * @category Generators */ export function fromYRotation(deg: number): mat4; /** * Creates a matrix from the given angle around the Z axis * @category Generators */ export function fromZRotation(deg: number): mat4; /** * Creates a matrix from a quaternion rotation and vector translation * @category Generators */ export function fromRotationTranslation(q: quat, v: vec3): mat4; /** * Returns the translation vector component of a transformation * matrix. If a matrix is built with fromRotationTranslation, * the returned vector will be the same as the translation vector * originally supplied. */ export function getTranslation(mat: mat4): vec3; /** * Returns the scaling factor component of a transformation * matrix. If a matrix is built with fromRotationTranslationScale * with a normalized Quaternion paramter, the returned vector will be * the same as the scaling vector * originally supplied. */ export function getScaling(mat: mat4): vec3; /** * Returns a quaternion representing the rotational component * of a transformation matrix. If a matrix is built with * fromRotationTranslation, the returned quaternion will be the * same as the quaternion originally supplied. */ export function getRotation(mat: mat4): quat; interface DecomposedTRS { rot: quat; trans: vec3; scale: vec3; } /** * Decomposes a transformation matrix into its rotation, translation * and scale components. Returns only the rotation component * * @param mat Matrix to be decomposed (input) */ export function decompose(mat: mat4): DecomposedTRS; /** * Creates a matrix from a quaternion rotation, vector translation and vector scale. * This is equivalent to (but much faster than): * * ```ts * mat4.multiply( * mat4.fromTranslation(trans), * mat4.fromQuat(rot), * mat4.fromScaling(scale), * ) * ``` * * @category Generators * @param rot Rotation quaternion * @param trans Translation vector * @param scale Scaling vector */ export function fromRotationTranslationScale(rot: quat, trans: vec3, scale?: vec3): mat4; /** * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin. * This is equivalent to (but much faster than): * * ```ts * mat4.multiply( * mat4.fromTranslation(trans), * mat4.fromTranslation(origin), * mat4.fromQuat(rot), * mat4.fromScaling(scale), * mat4.fromTranslation(vec3.negate(origin)), * ) * ``` * * @category Generators * @param rot Rotation quaternion * @param trans Translation vector * @param scale Scaling vector * @param origin The origin vector around which to scale and rotate */ export function fromRotationTranslationScaleOrigin(rot: quat, trans: vec3, scale?: vec3, origin?: vec3): number[]; /** * Calculates a 4x4 matrix from the given quaternion * * @param q Quaternion to create matrix from * @category Generators */ export function fromQuat(q: quat): mat4; /** * Generates a frustum matrix with the given bounds * * @param left Left bound of the frustum * @param right Right bound of the frustum * @param bottom Bottom bound of the frustum * @param top Top bound of the frustum * @param near Near bound of the frustum * @param far Far bound of the frustum */ export function frustum(left: number, right: number, bottom: number, top: number, near: number, far: number): number[]; /** * Generates a perspective projection matrix with the given bounds. * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1], * which matches WebGL/OpenGL's clip volume. * Passing null/undefined/no value for far will generate infinite projection matrix. * * @param fovy Vertical field of view in degrees * @param aspect Aspect ratio. typically viewport width/height * @param near Near bound of the frustum * @param far Far bound of the frustum, can be null or Infinity */ export function perspectiveNO(fovy: number, aspect: number, near: number, far: number): mat4; /** * Alias for {@link perspectiveNO} * @function */ export const perspective: typeof perspectiveNO; /** * Generates a perspective projection matrix suitable for WebGPU with the given bounds. * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1], * which matches WebGPU/Vulkan/DirectX/Metal's clip volume. * Passing null/undefined/no value for far will generate infinite projection matrix. * * @param fovy Vertical field of view in degrees * @param aspect Aspect ratio. typically viewport width/height * @param near Near bound of the frustum * @param far Far bound of the frustum, can be null or Infinity */ export function perspectiveZO(fovy: number, aspect: number, near: number, far: number | null): mat4; /** * Represents a field of view expressed in degrees. */ interface FovDegrees { upDegrees: number; downDegrees: number; leftDegrees: number; rightDegrees: number; } /** * Generates a perspective projection matrix with the given field of view. * This is primarily useful for generating projection matrices to be used * with the still experiemental WebVR API. * * @param fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees * @param near Near bound of the frustum * @param far Far bound of the frustum */ export function perspectiveFromFieldOfView(fov: FovDegrees, near: number, far: number): mat4; /** * Generates a orthogonal projection matrix with the given bounds. * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1], * which matches WebGL/OpenGL's clip volume. * * @param left Left bound of the frustum * @param right Right bound of the frustum * @param bottom Bottom bound of the frustum * @param top Top bound of the frustum * @param near Near bound of the frustum * @param far Far bound of the frustum */ export function orthoNO(left: number, right: number, bottom: number, top: number, near: number, far: number): mat4; /** * Alias for {@link orthoNO} * @function */ export const ortho: typeof orthoNO; /** * Generates a orthogonal projection matrix with the given bounds. * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1], * which matches WebGPU/Vulkan/DirectX/Metal's clip volume. * * @param left Left bound of the frustum * @param right Right bound of the frustum * @param bottom Bottom bound of the frustum * @param top Top bound of the frustum * @param near Near bound of the frustum * @param far Far bound of the frustum */ export function orthoZO(left: number, right: number, bottom: number, top: number, near: number, far: number): mat4; /** * Generates a look-at matrix with the given eye position, focal point, and up axis. * If you want a matrix that actually makes an object look at another object, you should use targetTo instead. * * @param eye Position of the viewer * @param center Point the viewer is looking at * @param up vec3 pointing up */ export function lookAt(eye: vec3, center: vec3, up: vec3): mat4; /** * Generates a matrix that makes something look at something else. * * @param eye Position of the viewer * @param center Point the viewer is looking at * @param up vec3 pointing up */ export function targetTo(eye: vec3, target: vec3, up: vec3): mat4; /** * Returns Frobenius norm of a mat4 */ export function frob(a: mat4): number; /** * Adds given mat4's */ export function add(...ms: mat4[]): mat4; /** * Subtracts matrix b from matrix a * * @shorthands * - {@link sub} */ export function subtract(...ms: mat4[]): mat4; /** * Alias for {@link subtract} * @category Shorthands */ export const sub: typeof subtract; /** * Subtracts b from a */ export function delta(a: mat4, b: mat4): mat4; /** * Multiply each element of the matrix by a scalar. */ export function multiplyScalar(a: mat4, s: number): mat4; /** Adds given mat4's after multiplying each element of the second operand by a scalar value. */ export function multiplyScalarAndAdd(a: mat4, b: mat4, scale: number): mat4; /** * Constrain each element to lie between min and max * @see https://thebookofshaders.com/glossary/?search=clamp */ export function clamp(a: mat4, min: number, max: number): mat4; /** * Clamps each element to [0, 1] */ export function clamp01(a: mat4): mat4; /** * Clamps each element to [-1, 1] */ export function clamp11(a: mat4): mat4; /** * Returns whether or not the matrices have exactly the same elements in the same position (when compared with `===`) * * @shorthands * - {@link eq} */ export function exactEquals(a: mat4, b: mat4): boolean; /** * Alias for {@link exactEquals} * @category Shorthands */ export const eq: typeof exactEquals; /** * Returns whether or not the matrices have approximately the same elements in the same position. * * @shorthands * - {@link approx} * - {@link equals} */ export function approxEquals(a: mat4, b: mat4): boolean; /** * Alias for {@link approxEquals} * @category Shorthands */ export const approx: typeof approxEquals; /** * Alias for {@link approxEquals}. This is provided for compatibility with gl-matrix. * @category Shorthands * @deprecated Use {@link approxEquals} instead */ export const equals: typeof approxEquals; /** * Projects a 3D point from object/world space to screen (window) coordinates. * Equivalent to GLM's `glm::project`. * * @param obj The 3D point in object/world space * @param mvp The combined model-view-projection matrix * @param viewport The viewport as [x, y, width, height] * @returns The projected point in screen coordinates [x, y, z] where z is the depth in [0, 1] */ export function project(obj: vec3, mvp: mat4, viewport: vec4): vec3; /** * Unprojects a point from screen (window) coordinates back to object/world space. * Equivalent to GLM's `glm::unProject`. * * @param screen The screen-space point [x, y, z] where z is the depth in [0, 1] * @param mvpInv The inverse of the combined model-view-projection matrix * @param viewport The viewport as [x, y, width, height] * @returns The unprojected 3D point, or null if the operation fails */ export function unProject(screen: vec3, mvpInv: mat4, viewport: vec4): vec3 | null; /** * Returns a string representation of a mat4 * @param m matrix to represent as a string * @param fractionDigits number of digits to appear after the decimal point */ export const toString: (m: mat4, fractionDigits?: number) => string; export {}; } //# sourceMappingURL=mat4.d.ts.map