import Vector3 from "./Vector3" ; import { xywh , vec4 } from "../Sylvain/vec" ; export const GL_EPSILLON = 0.0001 ; export type fov = { upDegrees : number ; downDegrees : number ; leftDegrees : number ; rightDegrees : number ; } ; export class glmatrix_matrix4 { module returns { mat4 } static create ( ) { let out = new Array < number > ( 16 ) ; out [ 0 ] = 1 ; out [ 5 ] = 1 ; out [ 10 ] = 1 ; out [ 15 ] = 1 ; return out ; } param { ReadonlyMat4 } a returns { mat4 } static clone ( a ) { let out = new Array < number > ( 16 ) ; out [ 0 ] = a [ 0 ] ; out [ 1 ] = a [ 1 ] ; out [ 2 ] = a [ 2 ] ; out [ 3 ] = a [ 3 ] ; out [ 4 ] = a [ 4 ] ; out [ 5 ] = a [ 5 ] ; out [ 6 ] = a [ 6 ] ; out [ 7 ] = a [ 7 ] ; out [ 8 ] = a [ 8 ] ; out [ 9 ] = a [ 9 ] ; out [ 10 ] = a [ 10 ] ; out [ 11 ] = a [ 11 ] ; out [ 12 ] = a [ 12 ] ; out [ 13 ] = a [ 13 ] ; out [ 14 ] = a [ 14 ] ; out [ 15 ] = a [ 15 ] ; return out ; } param { mat4 } out param { ReadonlyMat4 } a returns { mat4 } static copy ( out , a ) { out [ 0 ] = a [ 0 ] ; out [ 1 ] = a [ 1 ] ; out [ 2 ] = a [ 2 ] ; out [ 3 ] = a [ 3 ] ; out [ 4 ] = a [ 4 ] ; out [ 5 ] = a [ 5 ] ; out [ 6 ] = a [ 6 ] ; out [ 7 ] = a [ 7 ] ; out [ 8 ] = a [ 8 ] ; out [ 9 ] = a [ 9 ] ; out [ 10 ] = a [ 10 ] ; out [ 11 ] = a [ 11 ] ; out [ 12 ] = a [ 12 ] ; out [ 13 ] = a [ 13 ] ; out [ 14 ] = a [ 14 ] ; out [ 15 ] = a [ 15 ] ; return out ; } param { Number } m00 param { Number } m01 param { Number } m02 param { Number } m03 param { Number } m10 param { Number } m11 param { Number } m12 param { Number } m13 param { Number } m20 param { Number } m21 param { Number } m22 param { Number } m23 param { Number } m30 param { Number } m31 param { Number } m32 param { Number } m33 returns { mat4 } static fromValues ( m00 , m01 , m02 , m03 , m10 , m11 , m12 , m13 , m20 , m21 , m22 , m23 , m30 , m31 , m32 , m33 ) { let out = new Array < number > ( 16 ) ; out [ 0 ] = m00 ; out [ 1 ] = m01 ; out [ 2 ] = m02 ; out [ 3 ] = m03 ; out [ 4 ] = m10 ; out [ 5 ] = m11 ; out [ 6 ] = m12 ; out [ 7 ] = m13 ; out [ 8 ] = m20 ; out [ 9 ] = m21 ; out [ 10 ] = m22 ; out [ 11 ] = m23 ; out [ 12 ] = m30 ; out [ 13 ] = m31 ; out [ 14 ] = m32 ; out [ 15 ] = m33 ; return out ; } param { mat4 } out param { Number } m00 param { Number } m01 param { Number } m02 param { Number } m03 param { Number } m10 param { Number } m11 param { Number } m12 param { Number } m13 param { Number } m20 param { Number } m21 param { Number } m22 param { Number } m23 param { Number } m30 param { Number } m31 param { Number } m32 param { Number } m33 returns { mat4 } static set ( out , m00 , m01 , m02 , m03 , m10 , m11 , m12 , m13 , m20 , m21 , m22 , m23 , m30 , m31 , m32 , m33 ) { out [ 0 ] = m00 ; out [ 1 ] = m01 ; out [ 2 ] = m02 ; out [ 3 ] = m03 ; out [ 4 ] = m10 ; out [ 5 ] = m11 ; out [ 6 ] = m12 ; out [ 7 ] = m13 ; out [ 8 ] = m20 ; out [ 9 ] = m21 ; out [ 10 ] = m22 ; out [ 11 ] = m23 ; out [ 12 ] = m30 ; out [ 13 ] = m31 ; out [ 14 ] = m32 ; out [ 15 ] = m33 ; return out ; } param { mat4 } out returns { mat4 } static identity ( out ) { out [ 0 ] = 1 ; out [ 1 ] = 0 ; out [ 2 ] = 0 ; out [ 3 ] = 0 ; out [ 4 ] = 0 ; out [ 5 ] = 1 ; out [ 6 ] = 0 ; out [ 7 ] = 0 ; out [ 8 ] = 0 ; out [ 9 ] = 0 ; out [ 10 ] = 1 ; out [ 11 ] = 0 ; out [ 12 ] = 0 ; out [ 13 ] = 0 ; out [ 14 ] = 0 ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { ReadonlyMat4 } a returns { mat4 } static transpose ( out , a ) { if ( out === a ) { let a01 = a [ 1 ] , a02 = a [ 2 ] , a03 = a [ 3 ] ; let a12 = a [ 6 ] , a13 = a [ 7 ] ; let a23 = a [ 11 ] ; out [ 1 ] = a [ 4 ] ; out [ 2 ] = a [ 8 ] ; out [ 3 ] = a [ 12 ] ; out [ 4 ] = a01 ; out [ 6 ] = a [ 9 ] ; out [ 7 ] = a [ 13 ] ; out [ 8 ] = a02 ; out [ 9 ] = a12 ; out [ 11 ] = a [ 14 ] ; out [ 12 ] = a03 ; out [ 13 ] = a13 ; out [ 14 ] = a23 ; } else { out [ 0 ] = a [ 0 ] ; out [ 1 ] = a [ 4 ] ; out [ 2 ] = a [ 8 ] ; out [ 3 ] = a [ 12 ] ; out [ 4 ] = a [ 1 ] ; out [ 5 ] = a [ 5 ] ; out [ 6 ] = a [ 9 ] ; out [ 7 ] = a [ 13 ] ; out [ 8 ] = a [ 2 ] ; out [ 9 ] = a [ 6 ] ; out [ 10 ] = a [ 10 ] ; out [ 11 ] = a [ 14 ] ; out [ 12 ] = a [ 3 ] ; out [ 13 ] = a [ 7 ] ; out [ 14 ] = a [ 11 ] ; out [ 15 ] = a [ 15 ] ; } return out ; } param { mat4 } out param { ReadonlyMat4 } a returns { mat4 } static invert ( out , a ) { let a00 = a [ 0 ] , a01 = a [ 1 ] , a02 = a [ 2 ] , a03 = a [ 3 ] ; let a10 = a [ 4 ] , a11 = a [ 5 ] , a12 = a [ 6 ] , a13 = a [ 7 ] ; let a20 = a [ 8 ] , a21 = a [ 9 ] , a22 = a [ 10 ] , a23 = a [ 11 ] ; let a30 = a [ 12 ] , a31 = a [ 13 ] , a32 = a [ 14 ] , a33 = a [ 15 ] ; let b00 = a00 * a11 - a01 * a10 ; let b01 = a00 * a12 - a02 * a10 ; let b02 = a00 * a13 - a03 * a10 ; let b03 = a01 * a12 - a02 * a11 ; let b04 = a01 * a13 - a03 * a11 ; let b05 = a02 * a13 - a03 * a12 ; let b06 = a20 * a31 - a21 * a30 ; let b07 = a20 * a32 - a22 * a30 ; let b08 = a20 * a33 - a23 * a30 ; let b09 = a21 * a32 - a22 * a31 ; let b10 = a21 * a33 - a23 * a31 ; let b11 = a22 * a33 - a23 * a32 ; let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06 ; if ( ! det ) { return null ; } det = 1.0 / det ; out [ 0 ] = ( a11 * b11 - a12 * b10 + a13 * b09 ) * det ; out [ 1 ] = ( a02 * b10 - a01 * b11 - a03 * b09 ) * det ; out [ 2 ] = ( a31 * b05 - a32 * b04 + a33 * b03 ) * det ; out [ 3 ] = ( a22 * b04 - a21 * b05 - a23 * b03 ) * det ; out [ 4 ] = ( a12 * b08 - a10 * b11 - a13 * b07 ) * det ; out [ 5 ] = ( a00 * b11 - a02 * b08 + a03 * b07 ) * det ; out [ 6 ] = ( a32 * b02 - a30 * b05 - a33 * b01 ) * det ; out [ 7 ] = ( a20 * b05 - a22 * b02 + a23 * b01 ) * det ; out [ 8 ] = ( a10 * b10 - a11 * b08 + a13 * b06 ) * det ; out [ 9 ] = ( a01 * b08 - a00 * b10 - a03 * b06 ) * det ; out [ 10 ] = ( a30 * b04 - a31 * b02 + a33 * b00 ) * det ; out [ 11 ] = ( a21 * b02 - a20 * b04 - a23 * b00 ) * det ; out [ 12 ] = ( a11 * b07 - a10 * b09 - a12 * b06 ) * det ; out [ 13 ] = ( a00 * b09 - a01 * b07 + a02 * b06 ) * det ; out [ 14 ] = ( a31 * b01 - a30 * b03 - a32 * b00 ) * det ; out [ 15 ] = ( a20 * b03 - a21 * b01 + a22 * b00 ) * det ; return out ; } param { mat4 } out param { ReadonlyMat4 } a returns { mat4 } static adjoint ( out , a ) { let a00 = a [ 0 ] , a01 = a [ 1 ] , a02 = a [ 2 ] , a03 = a [ 3 ] ; let a10 = a [ 4 ] , a11 = a [ 5 ] , a12 = a [ 6 ] , a13 = a [ 7 ] ; let a20 = a [ 8 ] , a21 = a [ 9 ] , a22 = a [ 10 ] , a23 = a [ 11 ] ; let a30 = a [ 12 ] , a31 = a [ 13 ] , a32 = a [ 14 ] , a33 = a [ 15 ] ; let b00 = a00 * a11 - a01 * a10 ; let b01 = a00 * a12 - a02 * a10 ; let b02 = a00 * a13 - a03 * a10 ; let b03 = a01 * a12 - a02 * a11 ; let b04 = a01 * a13 - a03 * a11 ; let b05 = a02 * a13 - a03 * a12 ; let b06 = a20 * a31 - a21 * a30 ; let b07 = a20 * a32 - a22 * a30 ; let b08 = a20 * a33 - a23 * a30 ; let b09 = a21 * a32 - a22 * a31 ; let b10 = a21 * a33 - a23 * a31 ; let b11 = a22 * a33 - a23 * a32 ; out [ 0 ] = a11 * b11 - a12 * b10 + a13 * b09 ; out [ 1 ] = a02 * b10 - a01 * b11 - a03 * b09 ; out [ 2 ] = a31 * b05 - a32 * b04 + a33 * b03 ; out [ 3 ] = a22 * b04 - a21 * b05 - a23 * b03 ; out [ 4 ] = a12 * b08 - a10 * b11 - a13 * b07 ; out [ 5 ] = a00 * b11 - a02 * b08 + a03 * b07 ; out [ 6 ] = a32 * b02 - a30 * b05 - a33 * b01 ; out [ 7 ] = a20 * b05 - a22 * b02 + a23 * b01 ; out [ 8 ] = a10 * b10 - a11 * b08 + a13 * b06 ; out [ 9 ] = a01 * b08 - a00 * b10 - a03 * b06 ; out [ 10 ] = a30 * b04 - a31 * b02 + a33 * b00 ; out [ 11 ] = a21 * b02 - a20 * b04 - a23 * b00 ; out [ 12 ] = a11 * b07 - a10 * b09 - a12 * b06 ; out [ 13 ] = a00 * b09 - a01 * b07 + a02 * b06 ; out [ 14 ] = a31 * b01 - a30 * b03 - a32 * b00 ; out [ 15 ] = a20 * b03 - a21 * b01 + a22 * b00 ; return out ; } param { ReadonlyMat4 } a returns { Number } static eterminant ( a ) { let a00 = a [ 0 ] , a01 = a [ 1 ] , a02 = a [ 2 ] , a03 = a [ 3 ] ; let a10 = a [ 4 ] , a11 = a [ 5 ] , a12 = a [ 6 ] , a13 = a [ 7 ] ; let a20 = a [ 8 ] , a21 = a [ 9 ] , a22 = a [ 10 ] , a23 = a [ 11 ] ; let a30 = a [ 12 ] , a31 = a [ 13 ] , a32 = a [ 14 ] , a33 = a [ 15 ] ; let b0 = a00 * a11 - a01 * a10 ; let b1 = a00 * a12 - a02 * a10 ; let b2 = a01 * a12 - a02 * a11 ; let b3 = a20 * a31 - a21 * a30 ; let b4 = a20 * a32 - a22 * a30 ; let b5 = a21 * a32 - a22 * a31 ; let b6 = a00 * b5 - a01 * b4 + a02 * b3 ; let b7 = a10 * b5 - a11 * b4 + a12 * b3 ; let b8 = a20 * b2 - a21 * b1 + a22 * b0 ; let b9 = a30 * b2 - a31 * b1 + a32 * b0 ; return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9 ; } param { mat4 } out param { ReadonlyMat4 } a param { ReadonlyMat4 } b returns { mat4 } static multiply ( out , a , b ) { let a00 = a [ 0 ] , a01 = a [ 1 ] , a02 = a [ 2 ] , a03 = a [ 3 ] ; let a10 = a [ 4 ] , a11 = a [ 5 ] , a12 = a [ 6 ] , a13 = a [ 7 ] ; let a20 = a [ 8 ] , a21 = a [ 9 ] , a22 = a [ 10 ] , a23 = a [ 11 ] ; let a30 = a [ 12 ] , a31 = a [ 13 ] , a32 = a [ 14 ] , a33 = a [ 15 ] ; let b0 = b [ 0 ] , b1 = b [ 1 ] , b2 = b [ 2 ] , b3 = b [ 3 ] ; out [ 0 ] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30 ; out [ 1 ] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31 ; out [ 2 ] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32 ; out [ 3 ] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33 ; b0 = b [ 4 ] ; b1 = b [ 5 ] ; b2 = b [ 6 ] ; b3 = b [ 7 ] ; out [ 4 ] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30 ; out [ 5 ] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31 ; out [ 6 ] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32 ; out [ 7 ] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33 ; b0 = b [ 8 ] ; b1 = b [ 9 ] ; b2 = b [ 10 ] ; b3 = b [ 11 ] ; out [ 8 ] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30 ; out [ 9 ] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31 ; out [ 10 ] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32 ; out [ 11 ] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33 ; b0 = b [ 12 ] ; b1 = b [ 13 ] ; b2 = b [ 14 ] ; b3 = b [ 15 ] ; out [ 12 ] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30 ; out [ 13 ] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31 ; out [ 14 ] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32 ; out [ 15 ] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33 ; return out ; } param { mat4 } out param { ReadonlyMat4 } a param { ReadonlyVec3 } v returns { mat4 } static anslate ( out , a , v ) { let x = v . x , y = v . y , z = v . z ; let a00 , a01 , a02 , a03 ; let a10 , a11 , a12 , a13 ; let a20 , a21 , a22 , a23 ; if ( a === out ) { out [ 12 ] = a [ 0 ] * x + a [ 4 ] * y + a [ 8 ] * z + a [ 12 ] ; out [ 13 ] = a [ 1 ] * x + a [ 5 ] * y + a [ 9 ] * z + a [ 13 ] ; out [ 14 ] = a [ 2 ] * x + a [ 6 ] * y + a [ 10 ] * z + a [ 14 ] ; out [ 15 ] = a [ 3 ] * x + a [ 7 ] * y + a [ 11 ] * z + a [ 15 ] ; } else { a00 = a [ 0 ] ; a01 = a [ 1 ] ; a02 = a [ 2 ] ; a03 = a [ 3 ] ; a10 = a [ 4 ] ; a11 = a [ 5 ] ; a12 = a [ 6 ] ; a13 = a [ 7 ] ; a20 = a [ 8 ] ; a21 = a [ 9 ] ; a22 = a [ 10 ] ; a23 = a [ 11 ] ; out [ 0 ] = a00 ; out [ 1 ] = a01 ; out [ 2 ] = a02 ; out [ 3 ] = a03 ; out [ 4 ] = a10 ; out [ 5 ] = a11 ; out [ 6 ] = a12 ; out [ 7 ] = a13 ; out [ 8 ] = a20 ; out [ 9 ] = a21 ; out [ 10 ] = a22 ; out [ 11 ] = a23 ; out [ 12 ] = a00 * x + a10 * y + a20 * z + a [ 12 ] ; out [ 13 ] = a01 * x + a11 * y + a21 * z + a [ 13 ] ; out [ 14 ] = a02 * x + a12 * y + a22 * z + a [ 14 ] ; out [ 15 ] = a03 * x + a13 * y + a23 * z + a [ 15 ] ; } return out ; } param { mat4 } out param { ReadonlyMat4 } a param { ReadonlyVec3 } v returns { mat4 } static scale ( out , a , v ) { let x = v . x , y = v . y , z = v . z ; out [ 0 ] = a [ 0 ] * x ; out [ 1 ] = a [ 1 ] * x ; out [ 2 ] = a [ 2 ] * x ; out [ 3 ] = a [ 3 ] * x ; out [ 4 ] = a [ 4 ] * y ; out [ 5 ] = a [ 5 ] * y ; out [ 6 ] = a [ 6 ] * y ; out [ 7 ] = a [ 7 ] * y ; out [ 8 ] = a [ 8 ] * z ; out [ 9 ] = a [ 9 ] * z ; out [ 10 ] = a [ 10 ] * z ; out [ 11 ] = a [ 11 ] * z ; out [ 12 ] = a [ 12 ] ; out [ 13 ] = a [ 13 ] ; out [ 14 ] = a [ 14 ] ; out [ 15 ] = a [ 15 ] ; return out ; } param { mat4 } out param { ReadonlyMat4 } a param { Number } rad param { ReadonlyVec3 } axis returns { mat4 } static rotate ( out , a , rad , axis ) { let x = axis . x , y = axis . y , z = axis . z ; let len = Math . hypot ( x , y , z ) ; let s , c , t ; let a00 , a01 , a02 , a03 ; let a10 , a11 , a12 , a13 ; let a20 , a21 , a22 , a23 ; let b00 , b01 , b02 ; let b10 , b11 , b12 ; let b20 , b21 , b22 ; len = 1 / len ; x *= len ; y *= len ; z *= len ; s = Math . sin ( rad ) ; c = Math . cos ( rad ) ; t = 1 - c ; a00 = a [ 0 ] ; a01 = a [ 1 ] ; a02 = a [ 2 ] ; a03 = a [ 3 ] ; a10 = a [ 4 ] ; a11 = a [ 5 ] ; a12 = a [ 6 ] ; a13 = a [ 7 ] ; a20 = a [ 8 ] ; a21 = a [ 9 ] ; a22 = a [ 10 ] ; a23 = a [ 11 ] ; b00 = x * x * t + c ; b01 = y * x * t + z * s ; b02 = z * x * t - y * s ; b10 = x * y * t - z * s ; b11 = y * y * t + c ; b12 = z * y * t + x * s ; b20 = x * z * t + y * s ; b21 = y * z * t - x * s ; b22 = z * z * t + c ; out [ 0 ] = a00 * b00 + a10 * b01 + a20 * b02 ; out [ 1 ] = a01 * b00 + a11 * b01 + a21 * b02 ; out [ 2 ] = a02 * b00 + a12 * b01 + a22 * b02 ; out [ 3 ] = a03 * b00 + a13 * b01 + a23 * b02 ; out [ 4 ] = a00 * b10 + a10 * b11 + a20 * b12 ; out [ 5 ] = a01 * b10 + a11 * b11 + a21 * b12 ; out [ 6 ] = a02 * b10 + a12 * b11 + a22 * b12 ; out [ 7 ] = a03 * b10 + a13 * b11 + a23 * b12 ; out [ 8 ] = a00 * b20 + a10 * b21 + a20 * b22 ; out [ 9 ] = a01 * b20 + a11 * b21 + a21 * b22 ; out [ 10 ] = a02 * b20 + a12 * b21 + a22 * b22 ; out [ 11 ] = a03 * b20 + a13 * b21 + a23 * b22 ; if ( a !== out ) { out [ 12 ] = a [ 12 ] ; out [ 13 ] = a [ 13 ] ; out [ 14 ] = a [ 14 ] ; out [ 15 ] = a [ 15 ] ; } return out ; } param { mat4 } out param { ReadonlyMat4 } a param { Number } rad returns { mat4 } static rotateX ( out , a , rad ) { let s = Math . sin ( rad ) ; let c = Math . cos ( rad ) ; let a10 = a [ 4 ] ; let a11 = a [ 5 ] ; let a12 = a [ 6 ] ; let a13 = a [ 7 ] ; let a20 = a [ 8 ] ; let a21 = a [ 9 ] ; let a22 = a [ 10 ] ; let a23 = a [ 11 ] ; if ( a !== out ) { out [ 0 ] = a [ 0 ] ; out [ 1 ] = a [ 1 ] ; out [ 2 ] = a [ 2 ] ; out [ 3 ] = a [ 3 ] ; out [ 12 ] = a [ 12 ] ; out [ 13 ] = a [ 13 ] ; out [ 14 ] = a [ 14 ] ; out [ 15 ] = a [ 15 ] ; } out [ 4 ] = a10 * c + a20 * s ; out [ 5 ] = a11 * c + a21 * s ; out [ 6 ] = a12 * c + a22 * s ; out [ 7 ] = a13 * c + a23 * s ; out [ 8 ] = a20 * c - a10 * s ; out [ 9 ] = a21 * c - a11 * s ; out [ 10 ] = a22 * c - a12 * s ; out [ 11 ] = a23 * c - a13 * s ; return out ; } param { mat4 } out param { ReadonlyMat4 } a param { Number } rad returns { mat4 } static rotateY ( out , a , rad ) { let s = Math . sin ( rad ) ; let c = Math . cos ( rad ) ; let a00 = a [ 0 ] ; let a01 = a [ 1 ] ; let a02 = a [ 2 ] ; let a03 = a [ 3 ] ; let a20 = a [ 8 ] ; let a21 = a [ 9 ] ; let a22 = a [ 10 ] ; let a23 = a [ 11 ] ; if ( a !== out ) { out [ 4 ] = a [ 4 ] ; out [ 5 ] = a [ 5 ] ; out [ 6 ] = a [ 6 ] ; out [ 7 ] = a [ 7 ] ; out [ 12 ] = a [ 12 ] ; out [ 13 ] = a [ 13 ] ; out [ 14 ] = a [ 14 ] ; out [ 15 ] = a [ 15 ] ; } out [ 0 ] = a00 * c - a20 * s ; out [ 1 ] = a01 * c - a21 * s ; out [ 2 ] = a02 * c - a22 * s ; out [ 3 ] = a03 * c - a23 * s ; out [ 8 ] = a00 * s + a20 * c ; out [ 9 ] = a01 * s + a21 * c ; out [ 10 ] = a02 * s + a22 * c ; out [ 11 ] = a03 * s + a23 * c ; return out ; } param { mat4 } out param { ReadonlyMat4 } a param { Number } rad returns { mat4 } static rotateZ ( out , a , rad ) { let s = Math . sin ( rad ) ; let c = Math . cos ( rad ) ; let a00 = a [ 0 ] ; let a01 = a [ 1 ] ; let a02 = a [ 2 ] ; let a03 = a [ 3 ] ; let a10 = a [ 4 ] ; let a11 = a [ 5 ] ; let a12 = a [ 6 ] ; let a13 = a [ 7 ] ; if ( a !== out ) { out [ 8 ] = a [ 8 ] ; out [ 9 ] = a [ 9 ] ; out [ 10 ] = a [ 10 ] ; out [ 11 ] = a [ 11 ] ; out [ 12 ] = a [ 12 ] ; out [ 13 ] = a [ 13 ] ; out [ 14 ] = a [ 14 ] ; out [ 15 ] = a [ 15 ] ; } out [ 0 ] = a00 * c + a10 * s ; out [ 1 ] = a01 * c + a11 * s ; out [ 2 ] = a02 * c + a12 * s ; out [ 3 ] = a03 * c + a13 * s ; out [ 4 ] = a10 * c - a00 * s ; out [ 5 ] = a11 * c - a01 * s ; out [ 6 ] = a12 * c - a02 * s ; out [ 7 ] = a13 * c - a03 * s ; return out ; } param { mat4 } out param { ReadonlyVec3 } v returns { mat4 } static fromTranslation ( out , v ) { out [ 0 ] = 1 ; out [ 1 ] = 0 ; out [ 2 ] = 0 ; out [ 3 ] = 0 ; out [ 4 ] = 0 ; out [ 5 ] = 1 ; out [ 6 ] = 0 ; out [ 7 ] = 0 ; out [ 8 ] = 0 ; out [ 9 ] = 0 ; out [ 10 ] = 1 ; out [ 11 ] = 0 ; out [ 12 ] = v . x ; out [ 13 ] = v . y ; out [ 14 ] = v . z ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { ReadonlyVec3 } v returns { mat4 } static fromScaling ( out , v ) { out [ 0 ] = v . x ; out [ 1 ] = 0 ; out [ 2 ] = 0 ; out [ 3 ] = 0 ; out [ 4 ] = 0 ; out [ 5 ] = v . x ; out [ 6 ] = 0 ; out [ 7 ] = 0 ; out [ 8 ] = 0 ; out [ 9 ] = 0 ; out [ 10 ] = v . z ; out [ 11 ] = 0 ; out [ 12 ] = 0 ; out [ 13 ] = 0 ; out [ 14 ] = 0 ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { Number } rad param { ReadonlyVec3 } axis returns { mat4 } static fromRotation ( out , rad , axis ) { let x = axis . x , y = axis . y , z = axis . z ; let len = Math . hypot ( x , y , z ) ; let s , c , t ; len = 1 / len ; x *= len ; y *= len ; z *= len ; s = Math . sin ( rad ) ; c = Math . cos ( rad ) ; t = 1 - c ; out [ 0 ] = x * x * t + c ; out [ 1 ] = y * x * t + z * s ; out [ 2 ] = z * x * t - y * s ; out [ 3 ] = 0 ; out [ 4 ] = x * y * t - z * s ; out [ 5 ] = y * y * t + c ; out [ 6 ] = z * y * t + x * s ; out [ 7 ] = 0 ; out [ 8 ] = x * z * t + y * s ; out [ 9 ] = y * z * t - x * s ; out [ 10 ] = z * z * t + c ; out [ 11 ] = 0 ; out [ 12 ] = 0 ; out [ 13 ] = 0 ; out [ 14 ] = 0 ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { Number } rad returns { mat4 } static fromXRotation ( out , rad ) { let s = Math . sin ( rad ) ; let c = Math . cos ( rad ) ; out [ 0 ] = 1 ; out [ 1 ] = 0 ; out [ 2 ] = 0 ; out [ 3 ] = 0 ; out [ 4 ] = 0 ; out [ 5 ] = c ; out [ 6 ] = s ; out [ 7 ] = 0 ; out [ 8 ] = 0 ; out [ 9 ] = - s ; out [ 10 ] = c ; out [ 11 ] = 0 ; out [ 12 ] = 0 ; out [ 13 ] = 0 ; out [ 14 ] = 0 ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { Number } rad returns { mat4 } static fromYRotation ( out , rad ) { let s = Math . sin ( rad ) ; let c = Math . cos ( rad ) ; out [ 0 ] = c ; out [ 1 ] = 0 ; out [ 2 ] = - s ; out [ 3 ] = 0 ; out [ 4 ] = 0 ; out [ 5 ] = 1 ; out [ 6 ] = 0 ; out [ 7 ] = 0 ; out [ 8 ] = s ; out [ 9 ] = 0 ; out [ 10 ] = c ; out [ 11 ] = 0 ; out [ 12 ] = 0 ; out [ 13 ] = 0 ; out [ 14 ] = 0 ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { Number } rad returns { mat4 } static fromZRotation ( out , rad ) { let s = Math . sin ( rad ) ; let c = Math . cos ( rad ) ; out [ 0 ] = c ; out [ 1 ] = s ; out [ 2 ] = 0 ; out [ 3 ] = 0 ; out [ 4 ] = - s ; out [ 5 ] = c ; out [ 6 ] = 0 ; out [ 7 ] = 0 ; out [ 8 ] = 0 ; out [ 9 ] = 0 ; out [ 10 ] = 1 ; out [ 11 ] = 0 ; out [ 12 ] = 0 ; out [ 13 ] = 0 ; out [ 14 ] = 0 ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { quat4 } q param { ReadonlyVec3 } v returns { mat4 } static fromRotationTranslation ( out , q , v ) { let x = q [ 0 ] , y = q [ 1 ] , z = q [ 2 ] , w = q [ 3 ] ; let x2 = x + x ; let y2 = y + y ; let z2 = z + z ; let xx = x * x2 ; let xy = x * y2 ; let xz = x * z2 ; let yy = y * y2 ; let yz = y * z2 ; let zz = z * z2 ; let wx = w * x2 ; let wy = w * y2 ; let wz = w * z2 ; out [ 0 ] = 1 - ( yy + zz ) ; out [ 1 ] = xy + wz ; out [ 2 ] = xz - wy ; out [ 3 ] = 0 ; out [ 4 ] = xy - wz ; out [ 5 ] = 1 - ( xx + zz ) ; out [ 6 ] = yz + wx ; out [ 7 ] = 0 ; out [ 8 ] = xz + wy ; out [ 9 ] = yz - wx ; out [ 10 ] = 1 - ( xx + yy ) ; out [ 11 ] = 0 ; out [ 12 ] = v . x ; out [ 13 ] = v . y ; out [ 14 ] = v . z ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { ReadonlyQuat2 } a returns { mat4 } static fromQuat2 ( out , a ) { let translation = new Vector3 ( ) ; let bx = - a [ 0 ] , by = - a [ 1 ] , bz = - a [ 2 ] , bw = a [ 3 ] , ax = a [ 4 ] , ay = a [ 5 ] , az = a [ 6 ] , aw = a [ 7 ] ; let magnitude = bx * bx + by * by + bz * bz + bw * bw ; if ( magnitude > 0 ) { translation . x = ( ( ax * bw + aw * bx + ay * bz - az * by ) * 2 ) / magnitude ; translation . y = ( ( ay * bw + aw * by + az * bx - ax * bz ) * 2 ) / magnitude ; translation . z = ( ( az * bw + aw * bz + ax * by - ay * bx ) * 2 ) / magnitude ; } else { translation . x = ( ax * bw + aw * bx + ay * bz - az * by ) * 2 ; translation . y = ( ay * bw + aw * by + az * bx - ax * bz ) * 2 ; translation . z = ( az * bw + aw * bz + ax * by - ay * bx ) * 2 ; } glmatrix_matrix4 . fromRotationTranslation ( out , a , translation ) ; return out ; } param { vec3 } out param { ReadonlyMat4 } mat return { vec3 } static getTranslation ( out , mat ) { out . x = mat [ 12 ] ; out . y = mat [ 13 ] ; out . z = mat [ 14 ] ; return out ; } param { vec3 } out param { ReadonlyMat4 } mat return { vec3 } static getScaling ( out , mat ) { let m11 = mat [ 0 ] ; let m12 = mat [ 1 ] ; let m13 = mat [ 2 ] ; let m21 = mat [ 4 ] ; let m22 = mat [ 5 ] ; let m23 = mat [ 6 ] ; let m31 = mat [ 8 ] ; let m32 = mat [ 9 ] ; let m33 = mat [ 10 ] ; out . x = Math . hypot ( m11 , m12 , m13 ) ; out . y = Math . hypot ( m21 , m22 , m23 ) ; out . z = Math . hypot ( m31 , m32 , m33 ) ; return out ; } param { quat } out param { ReadonlyMat4 } mat return { quat } static getRotation ( out , mat ) { let scaling = new Vector3 ( ) ; glmatrix_matrix4 . getScaling ( scaling , mat ) ; let is1 = 1 / scaling . x ; let is2 = 1 / scaling . y ; let is3 = 1 / scaling . z ; let sm11 = mat [ 0 ] * is1 ; let sm12 = mat [ 1 ] * is2 ; let sm13 = mat [ 2 ] * is3 ; let sm21 = mat [ 4 ] * is1 ; let sm22 = mat [ 5 ] * is2 ; let sm23 = mat [ 6 ] * is3 ; let sm31 = mat [ 8 ] * is1 ; let sm32 = mat [ 9 ] * is2 ; let sm33 = mat [ 10 ] * is3 ; let trace = sm11 + sm22 + sm33 ; let S = 0 ; if ( trace > 0 ) { S = Math . sqrt ( trace + 1.0 ) * 2 ; out [ 3 ] = 0.25 * S ; out [ 0 ] = ( sm23 - sm32 ) / S ; out [ 1 ] = ( sm31 - sm13 ) / S ; out [ 2 ] = ( sm12 - sm21 ) / S ; } else if ( sm11 > sm22 && sm11 > sm33 ) { S = Math . sqrt ( 1.0 + sm11 - sm22 - sm33 ) * 2 ; out [ 3 ] = ( sm23 - sm32 ) / S ; out [ 0 ] = 0.25 * S ; out [ 1 ] = ( sm12 + sm21 ) / S ; out [ 2 ] = ( sm31 + sm13 ) / S ; } else if ( sm22 > sm33 ) { S = Math . sqrt ( 1.0 + sm22 - sm11 - sm33 ) * 2 ; out [ 3 ] = ( sm31 - sm13 ) / S ; out [ 0 ] = ( sm12 + sm21 ) / S ; out [ 1 ] = 0.25 * S ; out [ 2 ] = ( sm23 + sm32 ) / S ; } else { S = Math . sqrt ( 1.0 + sm33 - sm11 - sm22 ) * 2 ; out [ 3 ] = ( sm12 - sm21 ) / S ; out [ 0 ] = ( sm31 + sm13 ) / S ; out [ 1 ] = ( sm23 + sm32 ) / S ; out [ 2 ] = 0.25 * S ; } return out ; } param { quat } out_r param { vec3 } out_t param { vec3 } out_s param { ReadonlyMat4 } mat returns { quat } static decompose ( out_r , out_t , out_s , mat ) { out_t . x = mat [ 12 ] ; out_t . y = mat [ 13 ] ; out_t . z = mat [ 14 ] ; let m11 = mat [ 0 ] ; let m12 = mat [ 1 ] ; let m13 = mat [ 2 ] ; let m21 = mat [ 4 ] ; let m22 = mat [ 5 ] ; let m23 = mat [ 6 ] ; let m31 = mat [ 8 ] ; let m32 = mat [ 9 ] ; let m33 = mat [ 10 ] ; out_s . x = Math . hypot ( m11 , m12 , m13 ) ; out_s . y = Math . hypot ( m21 , m22 , m23 ) ; out_s . z = Math . hypot ( m31 , m32 , m33 ) ; let is1 = 1 / out_s . x ; let is2 = 1 / out_s . y ; let is3 = 1 / out_s . z ; let sm11 = m11 * is1 ; let sm12 = m12 * is2 ; let sm13 = m13 * is3 ; let sm21 = m21 * is1 ; let sm22 = m22 * is2 ; let sm23 = m23 * is3 ; let sm31 = m31 * is1 ; let sm32 = m32 * is2 ; let sm33 = m33 * is3 ; let trace = sm11 + sm22 + sm33 ; let S = 0 ; if ( trace > 0 ) { S = Math . sqrt ( trace + 1.0 ) * 2 ; out_r [ 3 ] = 0.25 * S ; out_r [ 0 ] = ( sm23 - sm32 ) / S ; out_r [ 1 ] = ( sm31 - sm13 ) / S ; out_r [ 2 ] = ( sm12 - sm21 ) / S ; } else if ( sm11 > sm22 && sm11 > sm33 ) { S = Math . sqrt ( 1.0 + sm11 - sm22 - sm33 ) * 2 ; out_r [ 3 ] = ( sm23 - sm32 ) / S ; out_r [ 0 ] = 0.25 * S ; out_r [ 1 ] = ( sm12 + sm21 ) / S ; out_r [ 2 ] = ( sm31 + sm13 ) / S ; } else if ( sm22 > sm33 ) { S = Math . sqrt ( 1.0 + sm22 - sm11 - sm33 ) * 2 ; out_r [ 3 ] = ( sm31 - sm13 ) / S ; out_r [ 0 ] = ( sm12 + sm21 ) / S ; out_r [ 1 ] = 0.25 * S ; out_r [ 2 ] = ( sm23 + sm32 ) / S ; } else { S = Math . sqrt ( 1.0 + sm33 - sm11 - sm22 ) * 2 ; out_r [ 3 ] = ( sm12 - sm21 ) / S ; out_r [ 0 ] = ( sm31 + sm13 ) / S ; out_r [ 1 ] = ( sm23 + sm32 ) / S ; out_r [ 2 ] = 0.25 * S ; } return out_r ; } param { mat4 } out param { quat4 } q param { ReadonlyVec3 } v param { ReadonlyVec3 } s returns { mat4 } static fromRotationTranslationScale ( out , q , v , s ) { let x = q [ 0 ] , y = q [ 1 ] , z = q [ 2 ] , w = q [ 3 ] ; let x2 = x + x ; let y2 = y + y ; let z2 = z + z ; let xx = x * x2 ; let xy = x * y2 ; let xz = x * z2 ; let yy = y * y2 ; let yz = y * z2 ; let zz = z * z2 ; let wx = w * x2 ; let wy = w * y2 ; let wz = w * z2 ; let sx = s . x ; let sy = s . y ; let sz = s . z ; out [ 0 ] = ( 1 - ( yy + zz ) ) * sx ; out [ 1 ] = ( xy + wz ) * sx ; out [ 2 ] = ( xz - wy ) * sx ; out [ 3 ] = 0 ; out [ 4 ] = ( xy - wz ) * sy ; out [ 5 ] = ( 1 - ( xx + zz ) ) * sy ; out [ 6 ] = ( yz + wx ) * sy ; out [ 7 ] = 0 ; out [ 8 ] = ( xz + wy ) * sz ; out [ 9 ] = ( yz - wx ) * sz ; out [ 10 ] = ( 1 - ( xx + yy ) ) * sz ; out [ 11 ] = 0 ; out [ 12 ] = v . x ; out [ 13 ] = v . z ; out [ 14 ] = v . y ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { quat4 } q param { ReadonlyVec3 } v param { ReadonlyVec3 } s param { ReadonlyVec3 } o returns { mat4 } static fromRotationTranslationScaleOrigin ( out , q , v , s , o ) { let x = q [ 0 ] , y = q [ 1 ] , z = q [ 2 ] , w = q [ 3 ] ; let x2 = x + x ; let y2 = y + y ; let z2 = z + z ; let xx = x * x2 ; let xy = x * y2 ; let xz = x * z2 ; let yy = y * y2 ; let yz = y * z2 ; let zz = z * z2 ; let wx = w * x2 ; let wy = w * y2 ; let wz = w * z2 ; let sx = s . x ; let sy = s . y ; let sz = s . z ; let ox = o . x ; let oy = o . y ; let oz = o . z ; let out0 = ( 1 - ( yy + zz ) ) * sx ; let out1 = ( xy + wz ) * sx ; let out2 = ( xz - wy ) * sx ; let out4 = ( xy - wz ) * sy ; let out5 = ( 1 - ( xx + zz ) ) * sy ; let out6 = ( yz + wx ) * sy ; let out8 = ( xz + wy ) * sz ; let out9 = ( yz - wx ) * sz ; let out10 = ( 1 - ( xx + yy ) ) * sz ; out [ 0 ] = out0 ; out [ 1 ] = out1 ; out [ 2 ] = out2 ; out [ 3 ] = 0 ; out [ 4 ] = out4 ; out [ 5 ] = out5 ; out [ 6 ] = out6 ; out [ 7 ] = 0 ; out [ 8 ] = out8 ; out [ 9 ] = out9 ; out [ 10 ] = out10 ; out [ 11 ] = 0 ; out [ 12 ] = v . x + ox - ( out0 * ox + out4 * oy + out8 * oz ) ; out [ 13 ] = v . y + oy - ( out1 * ox + out5 * oy + out9 * oz ) ; out [ 14 ] = v . z + oz - ( out2 * ox + out6 * oy + out10 * oz ) ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { ReadonlyQuat } q returns { mat4 } static fromQuat ( out , q ) { let x = q [ 0 ] , y = q [ 1 ] , z = q [ 2 ] , w = q [ 3 ] ; let x2 = x + x ; let y2 = y + y ; let z2 = z + z ; let xx = x * x2 ; let yx = y * x2 ; let yy = y * y2 ; let zx = z * x2 ; let zy = z * y2 ; let zz = z * z2 ; let wx = w * x2 ; let wy = w * y2 ; let wz = w * z2 ; out [ 0 ] = 1 - yy - zz ; out [ 1 ] = yx + wz ; out [ 2 ] = zx - wy ; out [ 3 ] = 0 ; out [ 4 ] = yx - wz ; out [ 5 ] = 1 - xx - zz ; out [ 6 ] = zy + wx ; out [ 7 ] = 0 ; out [ 8 ] = zx + wy ; out [ 9 ] = zy - wx ; out [ 10 ] = 1 - xx - yy ; out [ 11 ] = 0 ; out [ 12 ] = 0 ; out [ 13 ] = 0 ; out [ 14 ] = 0 ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { Number } left param { Number } right param { Number } bottom param { Number } top param { Number } near param { Number } far returns { mat4 } static frustum ( out , left , right , bottom , top , near , far ) { let rl = 1 / ( right - left ) ; let tb = 1 / ( top - bottom ) ; let nf = 1 / ( near - far ) ; out [ 0 ] = near * 2 * rl ; out [ 1 ] = 0 ; out [ 2 ] = 0 ; out [ 3 ] = 0 ; out [ 4 ] = 0 ; out [ 5 ] = near * 2 * tb ; out [ 6 ] = 0 ; out [ 7 ] = 0 ; out [ 8 ] = ( right + left ) * rl ; out [ 9 ] = ( top + bottom ) * tb ; out [ 10 ] = ( far + near ) * nf ; out [ 11 ] = - 1 ; out [ 12 ] = 0 ; out [ 13 ] = 0 ; out [ 14 ] = far * near * 2 * nf ; out [ 15 ] = 0 ; return out ; } param { mat4 } out param { number } fovy param { number } aspect param { number } near param { number } far returns { mat4 } static perspective ( out , fovy , aspect , near , far ) { let f = 1.0 / Math . tan ( fovy / 2 ) , nf ; out [ 0 ] = f / aspect ; out [ 1 ] = 0 ; out [ 2 ] = 0 ; out [ 3 ] = 0 ; out [ 4 ] = 0 ; out [ 5 ] = f ; out [ 6 ] = 0 ; out [ 7 ] = 0 ; out [ 8 ] = 0 ; out [ 9 ] = 0 ; out [ 11 ] = - 1 ; out [ 12 ] = 0 ; out [ 13 ] = 0 ; out [ 15 ] = 0 ; if ( far != null && far !== Infinity ) { nf = 1 / ( near - far ) ; out [ 10 ] = ( far + near ) * nf ; out [ 14 ] = 2 * far * near * nf ; } else { out [ 10 ] = - 1 ; out [ 14 ] = - 2 * near ; } return out ; } param { mat4 } out param { Object } fov param { number } near param { number } far returns { mat4 } static perspectiveFromFieldOfView ( out , fov , near , far ) { let upTan = Math . tan ( ( fov . upDegrees * Math . PI ) / 180.0 ) ; let downTan = Math . tan ( ( fov . downDegrees * Math . PI ) / 180.0 ) ; let leftTan = Math . tan ( ( fov . leftDegrees * Math . PI ) / 180.0 ) ; let rightTan = Math . tan ( ( fov . rightDegrees * Math . PI ) / 180.0 ) ; let xScale = 2.0 / ( leftTan + rightTan ) ; let yScale = 2.0 / ( upTan + downTan ) ; out [ 0 ] = xScale ; out [ 1 ] = 0.0 ; out [ 2 ] = 0.0 ; out [ 3 ] = 0.0 ; out [ 4 ] = 0.0 ; out [ 5 ] = yScale ; out [ 6 ] = 0.0 ; out [ 7 ] = 0.0 ; out [ 8 ] = - ( ( leftTan - rightTan ) * xScale * 0.5 ) ; out [ 9 ] = ( upTan - downTan ) * yScale * 0.5 ; out [ 10 ] = far / ( near - far ) ; out [ 11 ] = - 1.0 ; out [ 12 ] = 0.0 ; out [ 13 ] = 0.0 ; out [ 14 ] = ( far * near ) / ( near - far ) ; out [ 15 ] = 0.0 ; return out ; } param { mat4 } out param { number } left param { number } right param { number } bottom param { number } top param { number } near param { number } far returns { mat4 } static ortho ( out , left , right , bottom , top , near , far ) { let lr = 1 / ( left - right ) ; let bt = 1 / ( bottom - top ) ; let nf = 1 / ( near - far ) ; out [ 0 ] = - 2 * lr ; out [ 1 ] = 0 ; out [ 2 ] = 0 ; out [ 3 ] = 0 ; out [ 4 ] = 0 ; out [ 5 ] = - 2 * bt ; out [ 6 ] = 0 ; out [ 7 ] = 0 ; out [ 8 ] = 0 ; out [ 9 ] = 0 ; out [ 10 ] = 2 * nf ; out [ 11 ] = 0 ; out [ 12 ] = ( left + right ) * lr ; out [ 13 ] = ( top + bottom ) * bt ; out [ 14 ] = ( far + near ) * nf ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { ReadonlyVec3 } eye param { ReadonlyVec3 } center param { ReadonlyVec3 } up returns { mat4 } static lookAt ( out , eye , center , up ) { let x0 , x1 , x2 , y0 , y1 , y2 , z0 , z1 , z2 , len ; let eyex = eye . x ; let eyey = eye . y ; let eyez = eye . z ; let upx = up . x ; let upy = up . y ; let upz = up . z ; let centerx = center . x ; let centery = center . y ; let centerz = center . z ; if ( Math . abs ( eyex - centerx ) < GL_EPSILLON && Math . abs ( eyey - centery ) < GL_EPSILLON && Math . abs ( eyez - centerz ) < GL_EPSILLON ) { return glmatrix_matrix4 . identity ( out ) ; } z0 = eyex - centerx ; z1 = eyey - centery ; z2 = eyez - centerz ; len = 1 / Math . hypot ( z0 , z1 , z2 ) ; z0 *= len ; z1 *= len ; z2 *= len ; x0 = upy * z2 - upz * z1 ; x1 = upz * z0 - upx * z2 ; x2 = upx * z1 - upy * z0 ; len = Math . hypot ( x0 , x1 , x2 ) ; if ( ! len ) { x0 = 0 ; x1 = 0 ; x2 = 0 ; } else { len = 1 / len ; x0 *= len ; x1 *= len ; x2 *= len ; } y0 = z1 * x2 - z2 * x1 ; y1 = z2 * x0 - z0 * x2 ; y2 = z0 * x1 - z1 * x0 ; len = Math . hypot ( y0 , y1 , y2 ) ; if ( ! len ) { y0 = 0 ; y1 = 0 ; y2 = 0 ; } else { len = 1 / len ; y0 *= len ; y1 *= len ; y2 *= len ; } out [ 0 ] = x0 ; out [ 1 ] = y0 ; out [ 2 ] = z0 ; out [ 3 ] = 0 ; out [ 4 ] = x1 ; out [ 5 ] = y1 ; out [ 6 ] = z1 ; out [ 7 ] = 0 ; out [ 8 ] = x2 ; out [ 9 ] = y2 ; out [ 10 ] = z2 ; out [ 11 ] = 0 ; out [ 12 ] = - ( x0 * eyex + x1 * eyey + x2 * eyez ) ; out [ 13 ] = - ( y0 * eyex + y1 * eyey + y2 * eyez ) ; out [ 14 ] = - ( z0 * eyex + z1 * eyey + z2 * eyez ) ; out [ 15 ] = 1 ; return out ; } param { mat4 } out param { ReadonlyVec3 } eye param { ReadonlyVec3 } center param { ReadonlyVec3 } up returns { mat4 } static targetTo ( out , eye , target , up ) { let eyex = eye . x , eyey = eye . y , eyez = eye . z , upx = up . x , upy = up . y , upz = up . z ; let z0 = eyex - target . x , z1 = eyey - target . y , z2 = eyez - target . z ; let len = z0 * z0 + z1 * z1 + z2 * z2 ; if ( len > 0 ) { len = 1 / Math . sqrt ( len ) ; z0 *= len ; z1 *= len ; z2 *= len ; } let x0 = upy * z2 - upz * z1 , x1 = upz * z0 - upx * z2 , x2 = upx * z1 - upy * z0 ; len = x0 * x0 + x1 * x1 + x2 * x2 ; if ( len > 0 ) { len = 1 / Math . sqrt ( len ) ; x0 *= len ; x1 *= len ; x2 *= len ; } out [ 0 ] = x0 ; out [ 1 ] = x1 ; out [ 2 ] = x2 ; out [ 3 ] = 0 ; out [ 4 ] = z1 * x2 - z2 * x1 ; out [ 5 ] = z2 * x0 - z0 * x2 ; out [ 6 ] = z0 * x1 - z1 * x0 ; out [ 7 ] = 0 ; out [ 8 ] = z0 ; out [ 9 ] = z1 ; out [ 10 ] = z2 ; out [ 11 ] = 0 ; out [ 12 ] = eyex ; out [ 13 ] = eyey ; out [ 14 ] = eyez ; out [ 15 ] = 1 ; return out ; } param { ReadonlyMat4 } a returns { String } statstr ( a ) { return ( "mat4(" + a [ 0 ] + ", " + a [ 1 ] + ", " + a [ 2 ] + ", " + a [ 3 ] + ", " + a [ 4 ] + ", " + a [ 5 ] + ", " + a [ 6 ] + ", " + a [ 7 ] + ", " + a [ 8 ] + ", " + a [ 9 ] + ", " + a [ 10 ] + ", " + a [ 11 ] + ", " + a [ 12 ] + ", " + a [ 13 ] + ", " + a [ 14 ] + ", " + a [ 15 ] + ")" ) ; } param { ReadonlyMat4 } a returns { Number } static frob ( a ) { return Math . hypot ( a [ 0 ] , a [ 1 ] , a [ 2 ] , a [ 3 ] , a [ 4 ] , a [ 5 ] , a [ 6 ] , a [ 7 ] , a [ 8 ] , a [ 9 ] , a [ 10 ] , a [ 11 ] , a [ 12 ] , a [ 13 ] , a [ 14 ] , a [ 15 ] ) ; } param { mat4 } out param { ReadonlyMat4 } a param { ReadonlyMat4 } b returns { mat4 } static add ( out , a , b ) { out [ 0 ] = a [ 0 ] + b [ 0 ] ; out [ 1 ] = a [ 1 ] + b [ 1 ] ; out [ 2 ] = a [ 2 ] + b [ 2 ] ; out [ 3 ] = a [ 3 ] + b [ 3 ] ; out [ 4 ] = a [ 4 ] + b [ 4 ] ; out [ 5 ] = a [ 5 ] + b [ 5 ] ; out [ 6 ] = a [ 6 ] + b [ 6 ] ; out [ 7 ] = a [ 7 ] + b [ 7 ] ; out [ 8 ] = a [ 8 ] + b [ 8 ] ; out [ 9 ] = a [ 9 ] + b [ 9 ] ; out [ 10 ] = a [ 10 ] + b [ 10 ] ; out [ 11 ] = a [ 11 ] + b [ 11 ] ; out [ 12 ] = a [ 12 ] + b [ 12 ] ; out [ 13 ] = a [ 13 ] + b [ 13 ] ; out [ 14 ] = a [ 14 ] + b [ 14 ] ; out [ 15 ] = a [ 15 ] + b [ 15 ] ; return out ; } param { mat4 } out param { ReadonlyMat4 } a param { ReadonlyMat4 } b returns { mat4 } static subtract ( out , a , b ) { out [ 0 ] = a [ 0 ] - b [ 0 ] ; out [ 1 ] = a [ 1 ] - b [ 1 ] ; out [ 2 ] = a [ 2 ] - b [ 2 ] ; out [ 3 ] = a [ 3 ] - b [ 3 ] ; out [ 4 ] = a [ 4 ] - b [ 4 ] ; out [ 5 ] = a [ 5 ] - b [ 5 ] ; out [ 6 ] = a [ 6 ] - b [ 6 ] ; out [ 7 ] = a [ 7 ] - b [ 7 ] ; out [ 8 ] = a [ 8 ] - b [ 8 ] ; out [ 9 ] = a [ 9 ] - b [ 9 ] ; out [ 10 ] = a [ 10 ] - b [ 10 ] ; out [ 11 ] = a [ 11 ] - b [ 11 ] ; out [ 12 ] = a [ 12 ] - b [ 12 ] ; out [ 13 ] = a [ 13 ] - b [ 13 ] ; out [ 14 ] = a [ 14 ] - b [ 14 ] ; out [ 15 ] = a [ 15 ] - b [ 15 ] ; return out ; } param { mat4 } out param { ReadonlyMat4 } a param { Number } b returns { mat4 } static multiplyScalar ( out , a , b ) { out [ 0 ] = a [ 0 ] * b ; out [ 1 ] = a [ 1 ] * b ; out [ 2 ] = a [ 2 ] * b ; out [ 3 ] = a [ 3 ] * b ; out [ 4 ] = a [ 4 ] * b ; out [ 5 ] = a [ 5 ] * b ; out [ 6 ] = a [ 6 ] * b ; out [ 7 ] = a [ 7 ] * b ; out [ 8 ] = a [ 8 ] * b ; out [ 9 ] = a [ 9 ] * b ; out [ 10 ] = a [ 10 ] * b ; out [ 11 ] = a [ 11 ] * b ; out [ 12 ] = a [ 12 ] * b ; out [ 13 ] = a [ 13 ] * b ; out [ 14 ] = a [ 14 ] * b ; out [ 15 ] = a [ 15 ] * b ; return out ; } param { mat4 } out param { ReadonlyMat4 } a param { ReadonlyMat4 } b param { Number } scale returns { mat4 } static multiplyScalarAndAdd ( out , a , b , scale ) { out [ 0 ] = a [ 0 ] + b [ 0 ] * scale ; out [ 1 ] = a [ 1 ] + b [ 1 ] * scale ; out [ 2 ] = a [ 2 ] + b [ 2 ] * scale ; out [ 3 ] = a [ 3 ] + b [ 3 ] * scale ; out [ 4 ] = a [ 4 ] + b [ 4 ] * scale ; out [ 5 ] = a [ 5 ] + b [ 5 ] * scale ; out [ 6 ] = a [ 6 ] + b [ 6 ] * scale ; out [ 7 ] = a [ 7 ] + b [ 7 ] * scale ; out [ 8 ] = a [ 8 ] + b [ 8 ] * scale ; out [ 9 ] = a [ 9 ] + b [ 9 ] * scale ; out [ 10 ] = a [ 10 ] + b [ 10 ] * scale ; out [ 11 ] = a [ 11 ] + b [ 11 ] * scale ; out [ 12 ] = a [ 12 ] + b [ 12 ] * scale ; out [ 13 ] = a [ 13 ] + b [ 13 ] * scale ; out [ 14 ] = a [ 14 ] + b [ 14 ] * scale ; out [ 15 ] = a [ 15 ] + b [ 15 ] * scale ; return out ; } param { ReadonlyMat4 } a param { ReadonlyMat4 } b returns { Boolean } static exactEquals ( a , b ) { return ( a [ 0 ] === b [ 0 ] && a [ 1 ] === b [ 1 ] && a [ 2 ] === b [ 2 ] && a [ 3 ] === b [ 3 ] && a [ 4 ] === b [ 4 ] && a [ 5 ] === b [ 5 ] && a [ 6 ] === b [ 6 ] && a [ 7 ] === b [ 7 ] && a [ 8 ] === b [ 8 ] && a [ 9 ] === b [ 9 ] && a [ 10 ] === b [ 10 ] && a [ 11 ] === b [ 11 ] && a [ 12 ] === b [ 12 ] && a [ 13 ] === b [ 13 ] && a [ 14 ] === b [ 14 ] && a [ 15 ] === b [ 15 ] ) ; } param { ReadonlyMat4 } a param { ReadonlyMat4 } b returns { Boolean } static equals ( a , b ) { let a0 = a [ 0 ] , a1 = a [ 1 ] , a2 = a [ 2 ] , a3 = a [ 3 ] ; let a4 = a [ 4 ] , a5 = a [ 5 ] , a6 = a [ 6 ] , a7 = a [ 7 ] ; let a8 = a [ 8 ] , a9 = a [ 9 ] , a10 = a [ 10 ] , a11 = a [ 11 ] ; let a12 = a [ 12 ] , a13 = a [ 13 ] , a14 = a [ 14 ] , a15 = a [ 15 ] ; let b0 = b [ 0 ] , b1 = b [ 1 ] , b2 = b [ 2 ] , b3 = b [ 3 ] ; let b4 = b [ 4 ] , b5 = b [ 5 ] , b6 = b [ 6 ] , b7 = b [ 7 ] ; let b8 = b [ 8 ] , b9 = b [ 9 ] , b10 = b [ 10 ] , b11 = b [ 11 ] ; let b12 = b [ 12 ] , b13 = b [ 13 ] , b14 = b [ 14 ] , b15 = b [ 15 ] ; return ( Math . abs ( a0 - b0 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a0 ) , Math . abs ( b0 ) ) && Math . abs ( a1 - b1 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a1 ) , Math . abs ( b1 ) ) && Math . abs ( a2 - b2 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a2 ) , Math . abs ( b2 ) ) && Math . abs ( a3 - b3 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a3 ) , Math . abs ( b3 ) ) && Math . abs ( a4 - b4 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a4 ) , Math . abs ( b4 ) ) && Math . abs ( a5 - b5 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a5 ) , Math . abs ( b5 ) ) && Math . abs ( a6 - b6 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a6 ) , Math . abs ( b6 ) ) && Math . abs ( a7 - b7 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a7 ) , Math . abs ( b7 ) ) && Math . abs ( a8 - b8 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a8 ) , Math . abs ( b8 ) ) && Math . abs ( a9 - b9 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a9 ) , Math . abs ( b9 ) ) && Math . abs ( a10 - b10 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a10 ) , Math . abs ( b10 ) ) && Math . abs ( a11 - b11 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a11 ) , Math . abs ( b11 ) ) && Math . abs ( a12 - b12 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a12 ) , Math . abs ( b12 ) ) && Math . abs ( a13 - b13 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a13 ) , Math . abs ( b13 ) ) && Math . abs ( a14 - b14 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a14 ) , Math . abs ( b14 ) ) && Math . abs ( a15 - b15 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a15 ) , Math . abs ( b15 ) ) ) ; } } export class glmatrix_vec4 { module returns { vec4 } static create ( ) { let out = xywh ( 0 , 0 , 0 , 0 ) ; return out ; } param { ReadonlyVec4 } a returns { vec4 } static clone ( a ) { let out = xywh ( a . x , a . y , a . z , a . w ) ; return out ; } param { Number } x param { Number } y param { Number } z param { Number } w returns { vec4 } static fromValues ( x , y , z , w ) { let out = xywh ( x , y , z , w ) ; return out ; } param { vec4 } out param { ReadonlyVec4 } a returns { vec4 } static copy ( out , a ) { out . x = a . x ; out . y = a . y ; out . z = a . z ; out . w = a . w ; return out ; } param { vec4 } out param { Number } x param { Number } y param { Number } z param { Number } w returns { vec4 } static set ( out , x , y , z , w ) { out . x = x ; out . y = y ; out . z = z ; out . w = w ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { vec4 } static add ( out , a , b ) { out . x = a . x + b . x ; out . y = a . y + b . y ; out . z = a . z + b . z ; out . w = a . w + b . w ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { vec4 } static subtract ( out , a , b ) { out . x = a . x - b . x ; out . y = a . y - b . y ; out . z = a . z - b . z ; out . w = a . w - b . w ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { vec4 } static multiply ( out , a , b ) { out . x = a . x * b . x ; out . y = a . y * b . y ; out . z = a . z * b . z ; out . w = a . w * b . w ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { vec4 } static divide ( out , a , b ) { out . x = a . x / b . x ; out . y = a . y / b . y ; out . z = a . z / b . z ; out . w = a . w / b . w ; return out ; } param { vec4 } out param { ReadonlyVec4 } a returns { vec4 } static ceil ( out , a ) { out . x = Math . ceil ( a . x ) ; out . y = Math . ceil ( a . y ) ; out . z = Math . ceil ( a . z ) ; out . w = Math . ceil ( a . w ) ; return out ; } param { vec4 } out param { ReadonlyVec4 } a returns { vec4 } static floor ( out , a ) { out . x = Math . floor ( a . x ) ; out . y = Math . floor ( a . y ) ; out . z = Math . floor ( a . z ) ; out . w = Math . floor ( a . w ) ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { vec4 } static min ( out , a , b ) { out . x = Math . min ( a . x , b . x ) ; out . y = Math . min ( a . y , b . y ) ; out . z = Math . min ( a . z , b . z ) ; out . w = Math . min ( a . w , b . w ) ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { vec4 } static max ( out , a , b ) { out . x = Math . max ( a . x , b . x ) ; out . y = Math . max ( a . y , b . y ) ; out . z = Math . max ( a . z , b . z ) ; out . w = Math . max ( a . w , b . w ) ; return out ; } param { vec4 } out param { ReadonlyVec4 } a returns { vec4 } static round ( out , a ) { out . x = Math . round ( a . x ) ; out . y = Math . round ( a . y ) ; out . z = Math . round ( a . z ) ; out . w = Math . round ( a . w ) ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { Number } b returns { vec4 } static scale ( out , a , b ) { out . x = a . x * b ; out . y = a . y * b ; out . z = a . z * b ; out . w = a . w * b ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyVec4 } b param { Number } scale returns { vec4 } static scaleAndAdd ( out , a , b , scale ) { out . x = a . x + b . x * scale ; out . y = a . y + b . y * scale ; out . z = a . z + b . z * scale ; out . w = a . w + b . w * scale ; return out ; } param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { Number } static distance ( a , b ) { let x = b . x - a . x ; let y = b . y - a . y ; let z = b . z - a . z ; let w = b . w - a . w ; return Math . hypot ( x , y , z , w ) ; } param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { Number } static squaredDistance ( a , b ) { let x = b . x - a . x ; let y = b . y - a . y ; let z = b . z - a . z ; let w = b . w - a . w ; return x * x + y * y + z * z + w * w ; } param { ReadonlyVec4 } a returns { Number } static _length ( a ) { let x = a . x ; let y = a . y ; let z = a . z ; let w = a . w ; return Math . hypot ( x , y , z , w ) ; } param { ReadonlyVec4 } a returns { Number } static squaredLength ( a ) { let x = a . x ; let y = a . y ; let z = a . z ; let w = a . w ; return x * x + y * y + z * z + w * w ; } param { vec4 } out param { ReadonlyVec4 } a returns { vec4 } static negate ( out , a ) { out . x = - a . x ; out . y = - a . y ; out . z = - a . z ; out . w = - a . w ; return out ; } param { vec4 } out param { ReadonlyVec4 } a returns { vec4 } static inverse ( out , a ) { out . x = 1.0 / a . x ; out . y = 1.0 / a . y ; out . z = 1.0 / a . z ; out . w = 1.0 / a . w ; return out ; } param { vec4 } out param { ReadonlyVec4 } a returns { vec4 } static normalize ( out , a ) { let x = a . x ; let y = a . y ; let z = a . z ; let w = a . w ; let len = x * x + y * y + z * z + w * w ; if ( len > 0 ) { len = 1 / Math . sqrt ( len ) ; } out . x = x * len ; out . y = y * len ; out . z = z * len ; out . w = w * len ; return out ; } param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { Number } static dot ( a , b ) { return a . x * b . x + a . y * b . y + a . z * b . z + a . w * b . w ; } param { ReadonlyVec4 } result param { ReadonlyVec4 } U param { ReadonlyVec4 } V param { ReadonlyVec4 } W returns { vec4 } static cross ( out , u , v , w ) { let A = v . x * w . y - v . y * w . x , B = v . x * w . z - v . z * w . x , C = v . x * w . w - v . w * w . x , D = v . y * w . z - v . z * w . y , E = v . x * w . w - v . w * w . y , F = v . z * w . w - v . w * w . z ; let G = u . x ; let H = u . y ; let I = u . z ; let J = u . w ; out . x = H * F - I * E + J * D ; out . y = - ( G * F ) + I * C - J * B ; out . z = G * E - H * C + J * A ; out . w = - ( G * D ) + H * B - I * A ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyVec4 } b param { Number } t returns { vec4 } static lerp ( out , a , b , t ) { let ax = a . x ; let ay = a . y ; let az = a . z ; let aw = a . w ; out . x = ax + t * ( b . x - ax ) ; out . y = ay + t * ( b . y - ay ) ; out . z = az + t * ( b . z - az ) ; out . w = aw + t * ( b . w - aw ) ; return out ; } param { vec4 } out param { Number } scale returns { vec4 } static random ( out , scale ) { scale = scale || 1.0 ; var v1 , v2 , v3 , v4 ; var s1 , s2 ; do { v1 = Math . random ( ) * 2 - 1 ; v2 = Math . random ( ) * 2 - 1 ; s1 = v1 * v1 + v2 * v2 ; } while ( s1 >= 1 ) ; do { v3 = Math . random ( ) * 2 - 1 ; v4 = Math . random ( ) * 2 - 1 ; s2 = v3 * v3 + v4 * v4 ; } while ( s2 >= 1 ) ; var d = Math . sqrt ( ( 1 - s1 ) / s2 ) ; out . x = scale * v1 ; out . y = scale * v2 ; out . z = scale * v3 * d ; out . w = scale * v4 * d ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyMat4 } m returns { vec4 } static transformMat4 ( out , a , m ) { let x = a . x , y = a . y , z = a . z , w = a . w ; out . x = m [ 0 ] * x + m [ 4 ] * y + m [ 8 ] * z + m [ 12 ] * w ; out . y = m [ 1 ] * x + m [ 5 ] * y + m [ 9 ] * z + m [ 13 ] * w ; out . z = m [ 2 ] * x + m [ 6 ] * y + m [ 10 ] * z + m [ 14 ] * w ; out . w = m [ 3 ] * x + m [ 7 ] * y + m [ 11 ] * z + m [ 15 ] * w ; return out ; } param { vec4 } out param { ReadonlyVec4 } a param { ReadonlyQuat } q returns { vec4 } static transformQuat ( out , a , q ) { let x = a . x , y = a . y , z = a . z ; let qx = q . x , qy = q . y , qz = q . z , qw = q . w ; let ix = qw * x + qy * z - qz * y ; let iy = qw * y + qz * x - qx * z ; let iz = qw * z + qx * y - qy * x ; let iw = - qx * x - qy * y - qz * z ; out . x = ix * qw + iw * - qx + iy * - qz - iz * - qy ; out . y = iy * qw + iw * - qy + iz * - qx - ix * - qz ; out . z = iz * qw + iw * - qz + ix * - qy - iy * - qx ; out . w = a . w ; return out ; } param { vec4 } out returns { vec4 } static zero ( out ) { out . x = 0.0 ; out . y = 0.0 ; out . z = 0.0 ; out . w = 0.0 ; return out ; } param { ReadonlyVec4 } a returns { String } static str ( a ) { return "vec4(" + a . x + ", " + a . y + ", " + a . z + ", " + a . w + ")" ; } param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { Boolean } static exactEquals ( a , b ) { return a . x === b . x && a . y === b . y && a . z === b . z && a . w === b . w ; } param { ReadonlyVec4 } a param { ReadonlyVec4 } b returns { Boolean } static equals ( a , b ) { let a0 = a . x , a1 = a . y , a2 = a . z , a3 = a . w ; let b0 = b . x , b1 = b . y , b2 = b . z , b3 = b . w ; return ( Math . abs ( a0 - b0 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a0 ) , Math . abs ( b0 ) ) && Math . abs ( a1 - b1 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a1 ) , Math . abs ( b1 ) ) && Math . abs ( a2 - b2 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a2 ) , Math . abs ( b2 ) ) && Math . abs ( a3 - b3 ) <= GL_EPSILLON * Math . max ( 1.0 , Math . abs ( a3 ) , Math . abs ( b3 ) ) ) ; } }