Function setDefaultType

  • Sets the type this library creates for a Vec3

    Parameters

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

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

        • new (n): Vec3
        • Parameters

          • n: number

          Returns Vec3

    Returns (new (n) => Vec3)

    previous constructor for Vec3

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

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

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

        or

        const v = vec3.create();
        vec3.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

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

        Parameters

        • n: number

        Returns Vec3