Function setDefaultType

  • Sets the type this library creates for a Vec4

    Parameters

    • ctor: (new (n) => Vec4)

      the constructor for the type. Either Float32Array, Float64Array, or Array

        • new (n): Vec4
        • Parameters

          • n: number

          Returns Vec4

    Returns (new (n) => Vec4)

    previous constructor for Vec4

      • new (n): Vec4
      • Vec4 math functions.

        Almost all functions take an optional dst argument. If it is not passed in the functions will create a new Vec4. In other words you can do this

        const v = vec4.cross(v1, v2);  // Creates a new Vec4 with the cross product of v1 x v2.
        

        or

        const v = vec4.create();
        vec4.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v

        The first style is often easier but depending on where it's used it generates garbage where as there is almost never allocation with the second style.

        It is always safe to pass any vector as the destination. So for example

        vec4.cross(v1, v2, v1);  // Puts the cross product of v1 x v2 in v1
        

        Parameters

        • n: number

        Returns Vec4