iosarraysunity-game-enginevuforia

How can I use a Vuforia 4x4 matrix to retrieve the position of an area target?


I am currently working on an application utilizing Vuforia and i need to extract position coordinates (x, y, z) from a 4x4 transformation matrix of an area target.

Here is the method VuMatrix44F i use to access the position values, which I obtain as follows from an AreaTargetObservation:

VuMatrix44F poseMatrix = poseInfo.pose;
   float x = poseMatrix.data[12];
   float y = poseMatrix.data[13];
   float z = poseMatrix.data[14];

However, the coordinates (x, y, z) extracted from the matrix do not seem to align well with the size and position of the area target

My questions are:

  1. Is this method correct for accurately determining the position of an area target using a 4x4 matrix in Vuforia ?
  2. Are there any other methods or suggestions I should consider to ensure the coordinates more accurately reflect the physical location and size of the area target ?

Thank you.


Solution

  • The Vuforia target observation pose is equivalent to the model matrix in OpenGL (see here https://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#the-model-matrix).

    The coordinates (x, y, z) you are using are the position of the origin of the Area Target in the Vuforia world coordinate system.

    If you want to compute the position of the device in the AreaTarget coordinate system you have to combine that pose with the device tracker pose which one can get with

    VuRenderState renderState;
    vuStateGetRenderState(state, &renderState);
    // combine the view matrix with the model matrix
    auto modelView = vuMatrix44FMultiplyMatrix(renderState.viewMatrix, poseInfo.pose);
    

    this matrix now contains the position of the AreaTarget origin in the device coordinate system. To get the position of the device in the AreaTarget you have to invert this matrix with:

    auto deviceMatrix = vuMatrix44FInverse(modelView);
    

    and then as you did

    float x = deviceMatrix.data[12];
    float y = deviceMatrix.data[13];
    float z = deviceMatrix.data[14];