Function lookAtMat4v

  • Creates a 4x4 'lookAt' viewing transformation matrix.

    This function generates a look-at matrix that transforms objects from world space to camera space, where the camera is positioned at pos, looks at target, and the up vector defines the camera's up direction. The resulting matrix is commonly used in 3D rendering for setting the camera's view transformation.

    Parameters

    • pos: FloatArrayParam

      The position of the camera in world space (x, y, z).

    • target: FloatArrayParam

      The target position the camera is looking at in world space (x, y, z).

    • up: FloatArrayParam

      The up vector of the camera in world space (x, y, z).

    • Optionaldest: FloatArrayParam

      An optional destination matrix to store the result. If not provided, a new matrix will be created.

    Returns FloatArrayParam

    The resulting 4x4 look-at matrix. If dest is provided, it will be modified; otherwise, a new matrix is returned.

    const cameraPosition = [0, 0, 5];
    const targetPosition = [0, 0, 0];
    const upVector = [0, 1, 0];
    const matrix = lookAtMat4v(cameraPosition, targetPosition, upVector);
    console.log(matrix);