Search code examples
c++matrixandroid-ndkaugmented-realityarcore

Which is the Matrix4x4 format from ARCore NDK Pose?


When using this function in NDK:

void ArPose_getMatrix(
    const ArSession *session,
    const ArPose *pose,
    float *out_matrix_col_major_4x4
)

I get a Pointer to an array of 16 floats, to be filled with a column-major homogenous transformation matrix, as used by OpenGL.

But I don't know if this matrix is:

x.x, x.y, x.z, 0
y.x, y.y, y.z, 0
z.x, z.y, z.z, 0
t.x, t.y, t.z, 1

or

x.x, x.y, x.z, x.t
y.x, y.y, y.z, y.t
z.x, z.y, z.z, z.t
  0,   0,   0,   1

I only know the order to read: x.x, y.x, z.x ... since is column-major.

How do I know the right format?


Solution

  • The order of components in ARCore *out_matrix_col_major_4x4 is the same as in OpenGL Matrices:

    ARCore documentation says about it obviously:

    out_matrix_col_major_4x4 is a Pointer to an array of 16 floats, to be filled with a column-major homogenous transformation matrix, as used by OpenGL.

    enter image description here

    The first three elements in the rightmost column [0,0,0,1] are for translation along x,y,z axis:

    enter image description here

    The first three elements in the lowest row [0,0,0,1] in this 4x4 matrix are for affine mapping. So, the last row of the 4x4 matrix has to be respected when you're applying transformations after a projection.

    Term Column-Major means: the elements of this matrix are gettable and settable using columns' order. Thus, translate x, y, z elements are located in the rightmost fourth column.