"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

Android - How can I calculate the distance to the target?

The fourth column of the pose matrix is a translation vector. This describes the position of the target in relation to a camera sitting at the origin. See the Pose Matrix Explained article for more info: [Pose Matrix Article] Given this, finding the distance from the camera to the trackable in scene units is trivial. Simply find the magnitude of this translation vector:

#include <math.h>QCAR::Matrix34F pose = trackable->getPose();        QCAR::Vec3F position(pose.data[3], pose.data[7], pose.data[11]);float distance = sqrt(position.data[0] * position.data[0] +                      position.data[1] * position.data[1] +                      position.data[2] * position.data[2]);LOG("distance: %f", distance);

 

This returns the distance in scene units, which are defined by the size of the target. For more discussion on target size see this article: Positioning3DContent.xml To get the real-world distance of the device from the target you would need to know the printed size of the target. Then you could find the ratio between the defined width of the target and the printed width of the target and use this as a multiplier for the distance. Note that Vuforia has no way of determining the real-world size of the target it is tracking. A 10 inch-wide target and a 5 inch-wide target might track equally well, and look identical to the tracker when the device is moved so the target fills the screen.