Options
All
  • Public
  • Public/Protected
  • All
Menu

Module gl_matrix_extensions

Namespace that comprises various gl-matrix extensions (also cleans up documentation).

Index

Variables

Const one256ths

one256ths: number = 1.0 / 256.0

Functions

abs2

  • abs2(out: vec2, x: vec2): vec2
  • Derive the absolute values of each of the two vector components.

    let a: vec2 = vec2.fromValues(-2, 2);
    abs2(a, a); // should result in [2,2]

    Parameters

    • out: vec2

      The receiving vector.

    • x: vec2

      The vector to apply abs to.

    Returns vec2

    • Vector with each component as absolute value.

abs3

  • abs3(out: vec3, x: vec3): vec3
  • Derive the absolute values of each of the three vector components.

    let a: vec3 = vec3.fromValues(-2, 2, -1);
    abs3(a, a); // should result in [2,2,1]

    Parameters

    • out: vec3

      The receiving vector.

    • x: vec3

      The vector to apply abs to.

    Returns vec3

    • Vector with each component as absolute value.

abs4

  • abs4(out: vec4, x: vec4): vec4
  • Derive the absolute values of each of the four vector components.

    let a: vec4 = vec4.fromValues(-2, 2, -1, 1);
    abs4(a, a); // should result in [2,2,1,1]

    Parameters

    • out: vec4

      The receiving vector.

    • x: vec4

      The vector to apply abs to.

    Returns vec4

    • Vector with each component as absolute value.

clamp

  • clamp(x: number, min: number, max: number): number
  • Constrain a value to lie between two further values.

    clamp(+3, +0, +2); // results in +2;

    Parameters

    • x: number

      The number to clamp.

    • min: number

      Minimum number operand.

    • max: number

      Maximum number operand.

    Returns number

    • Number constrained to [min,max].

clamp2

  • clamp2(out: vec2, x: vec2 | number[], min: vec2 | number[], max: vec2 | number[]): vec2
  • Constrain a two-component vector to lie between two further two-component vectors.

    let a: vec2 = vec2.fromValues(2, 2);
    clamp2(a, a, [0, 0], [1, 1]);

    Parameters

    • out: vec2

      The receiving vector.

    • x: vec2 | number[]

      The vector to clamp.

    • min: vec2 | number[]

      Minimum vector operand.

    • max: vec2 | number[]

      Maximum vector operand.

    Returns vec2

    • Vector constrained to [min,max].

clamp3

  • clamp3(out: vec3, x: vec3 | number[], min: vec3 | number[], max: vec3 | number[]): vec3
  • Constrain a three-component vector to lie between two further three-component vectors.

    let a: vec3 = vec3.fromValues(2, 2, 2);
    clamp3(a, a, [0, 0, 0], [1, 1, 1]);

    Parameters

    • out: vec3

      -The receiving vector.

    • x: vec3 | number[]

      The vector to clamp.

    • min: vec3 | number[]

      Minimum vector operand.

    • max: vec3 | number[]

      Maximum vector operand.

    Returns vec3

    • Vector constrained to [min,max].

clamp4

  • clamp4(out: vec4, x: vec4 | number[], min: vec4 | number[], max: vec4 | number[]): vec4
  • Constrain a four-component vector to lie between two further four-component vectors.

    let a: vec4 = vec4.fromValues(2, 2, 2, 2);
    clamp4(a, a, [0, 0, 0, 0], [1, 1, 1, 1]);

    Parameters

    • out: vec4

      The receiving vector.

    • x: vec4 | number[]

      The vector to clamp.

    • min: vec4 | number[]

      Minimum vector operand.

    • max: vec4 | number[]

      Maximum vector operand.

    Returns vec4

    • Vector constrained to [min,max].

decode_float24x1_from_uint8x3

  • decode_float24x1_from_uint8x3(x: vec3): number
  • Decodes three 8bit components of a vec3 to a 24bit floating point number.

    Parameters

    • x: vec3

      Vector with three 8bit unsigned int components (uint8x3).

    Returns number

    • Encoded 24bit floating point number.

decode_uint24_from_rgb8

  • decode_uint24_from_rgb8(x: vec3): number
  • Unpacks a 24bit unsigned int from a three component byte vector.

    let uint8x3: vec3 = vec3.fromValues(173, 209, 3);
    decode_uint24_from_rgb8(uint8x3); // should return 250285

    Parameters

    • x: vec3

      byte (uint8) vector with packed uint24 data

    Returns number

    • Unpacked 24bit unsigned int.

decode_uint32_from_rgba8

  • decode_uint32_from_rgba8(x: vec4): number
  • Unpacks a 32bit unsigned int from a four component byte vector.

    let uint8x4: vec4 = vec4.fromValues(173, 209, 3, 23);
    decode_uint24_from_rgba8(uint8x4); // should return xxx

    Parameters

    • x: vec4

      byte (uint8) vector with packed uint32 data

    Returns number

    • Unpacked 32bit unsigned int.

encode_float24x1_to_uint8x3

  • encode_float24x1_to_uint8x3(out: vec3, x: number): vec3
  • Encodes a 24bit floating point in [0,1] into three 8bit components (vec3 of uint8).

    Parameters

    • out: vec3

      The vector to encode into.

    • x: number

      24bit floating point number to encode.

    Returns vec3

    • Vector with the float encoded.

encode_uint24_to_rgb8

  • encode_uint24_to_rgb8(out: vec3, x: number): vec3
  • Packs a 24bit unsigned int into a three component byte vector.

    let uint8x3: vec3 = vec3.create();
    encode_uint24_in_rgb8(uint8x3, 250285); // should result in [ 173, 209, 3 ]

    Parameters

    • out: vec3

      byte (uint8) vector with packed uint24 data

    • x: number

      uint24 number

    Returns vec3

    • Three component byte vector with x packed.

encode_uint32_to_rgba8

  • encode_uint32_to_rgba8(out: vec4, x: number): vec4
  • Packs a 32bit unsigned int into a four component byte vector.

    let uint8x4: vec3 = vec4.create();
    encode_uint24_in_rgb8(uint8x4, 250285); // should result in [ 173, 209, 3, 0 ]

    Parameters

    • out: vec4

      byte (uint8) vector with packed uint32 data

    • x: number

      uint32 number

    Returns vec4

    • Three component byte vector with x packed.

fract

  • fract(x: number): number
  • Compute the fractional part of the argument.

    fract(+1.23); // results in +0.23
    fract(-1.23); // results in -0.23

    Parameters

    • x: number

      The number to compute the fractional part of.

    Returns number

    • The fractional part of x. This is calculated as x - floor(x).

fromVec3

  • fromVec3(x: vec3): vec4
  • Constructs a vec4 from a vec3 by appending 1.0 as the w component.

    const v3: vec3 = vec3.fromValues(2, 4, 6);
    const v4: vec4 = fromVec3(v3); // v3 is [2, 4, 6, 1]

    Parameters

    • x: vec3

      The vector to be transformed to a vec4.

    Returns vec4

    • Four component vector based on x.

fromVec4

  • fromVec4(x: vec4): vec3
  • Constructs a vec3 from a vec4 with division by the w component applied. If the w component is zero, division skipped.

    const v4: vec4 = vec4.fromValues(2, 4, 6, 2);
    const v3: vec3 = fromVec4(v4); // v3 is [1, 2, 3]

    Parameters

    • x: vec4

      The vector to be transformed to a vec3.

    Returns vec3

    • Three component vector based on x.

m2

  • m2(): mat2

m3

  • m3(): mat3

m4

  • m4(): mat4

mix

  • mix(value1: number, value2: number, interpolation: number): number
  • Performs a mix as specified in GLSL.

    Parameters

    • value1: number

      The first value.

    • value2: number

      The second value.

    • interpolation: number

      The interpolation value (usually between 0 and 1).

    Returns number

    • The interpolated value between value1 and value2.

parseVec2

  • parseVec2(v2str: string | undefined): vec2 | undefined
  • Parses a vec2 from a string.

    Parameters

    • v2str: string | undefined

      String in the format ', ', e.g., '1.0, 0.0'.

    Returns vec2 | undefined

    • Vec2 if string was parsed successfully, undefined else.

parseVec3

  • parseVec3(v3str: string | undefined): vec3 | undefined
  • Parses a vec3 from a string.

    Parameters

    • v3str: string | undefined

      String in the format ', , ', e.g., '1.0, 0.0, 1.0'.

    Returns vec3 | undefined

    • Vec3 if string was parsed successfully, undefined else.

parseVec4

  • parseVec4(v4str: string | undefined): vec4 | undefined
  • Parses a vec4 from a string.

    Parameters

    • v4str: string | undefined

      String in the format ', , , ', e.g., '1.0, 0.0, 0.0, 0.0'.

    Returns vec4 | undefined

    • Vec4 if string was parsed successfully, undefined else.

sign

  • sign(x: number): number
  • Extract the sign of the parameter as specified in GLSL.

    Parameters

    • x: number

      Value from which to extract the sign.

    Returns number

    • -1.0 if x is less than 0.0, 0.0 if x is equal to 0.0, and +1.0 if x is greater than 0.0.

v2

  • v2(): vec2

v3

  • v3(): vec3

v4

  • v4(): vec4