Log in or register to post comments

Distance Markers

May 2, 2011 - 1:19am #1

Hi!
Are there any methods available for calculating the distance between the marker an the Smartphone? The ARToolKit provide many methods like calculating size of a marker or number of pixels in the labeled region who helps calculating the distance.
Perhaps anybody knows how to get the distance easily?

Thanks Steph

Re: Distance Markers

May 2, 2011 - 6:08am #2

You can grab position values from the modelview matrix and get the distance from the magnitude. The modelview matrix represents the orientation of the trackable with the camera at the origin. The inverse of the modelview matrix represents the orientation of the camera with the trackable at the origin. Since we're just doing distance, we won't bother taking the inverse.

Here's a code snippet:

#include <math.h>

QCAR::Matrix44F modelViewMatrix =
    QCAR::Tool::convertPose2GLMatrix(trackable->getPose());        

QCAR::Vec3F position(modelViewMatrix.data[12], modelViewMatrix.data[13], modelViewMatrix.data[14]);
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);

- Kim

Log in or register to post comments