Log in or register to post comments

How i look on a FrameMarker

June 23, 2011 - 3:11am #1


I wanted to ask if i can get information about it how i look on a framemarker. If i rotate the marker for 90 degrees, the letter that is rendered is also rotated for 90 degrees. So it must be possible to get information how the marker is rotated or better, from what direction i look to the marker. Let´s say i put the marker on a table and walk around this table, can i get information that i look from the right side of the table, behind the table and left of the table on the marker. Can i get this information from the pose?

Thanks Stephan

Re: How i look on a FrameMarker

June 27, 2011 - 9:05pm #2

Try something like this:

// Get the trackable:
const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
QCAR::Matrix44F modelViewMatrix =

// take the inverse of the modelview matrix to find the camera orientation in relation to a target at the origin
QCAR::Matrix44F inverseModelView = SampleMath::Matrix44FTranspose(SampleMath::Matrix44FInverse(modelViewMatrix));

// pull the camera position from this matrix
QCAR::Vec3F cameraPosition(inverseModelView.data[12], inverseModelView.data[13], inverseModelView.data[14]);

// project the vector to the X/Y plane
// reverse to get a vector pointing to the target
QCAR::Vec3F projectedDirectionToTarget(-cameraPosition.data[0], -cameraPosition.data[1], 0);

// normalize the projected vector
projectedDirectionToTarget = SampleMath::Vec3FNormalize(projectedDirectionToTarget);

// choose Y up as the forward-facing vector for the marker
QCAR::Vec3F markerForward(0.0f, 1.0f, 0.0f);

// find the dot and cross products of the vectors
float dot = SampleMath::Vec3FDot(projectedDirectionToTarget, markerForward);
QCAR::Vec3F cross = SampleMath::Vec3FCross(projectedDirectionToTarget, markerForward);

// the angle between two vectors is the acos of the dot product
float angle = acos(dot);

// acos returns an angle in radians, convert to degrees
angle *= 180.0f / M_PI;

// our angle is now between 0 and 180, use the cross product to make it between 0 and 360
if (cross.data[2] > 0)
    angle = 360.0f - angle;

LOG("angle: %f", angle);

This should get you an angle between 0 and 360 as you rotate the marker in front of the camera (or as you walk around the marker).

- Kim

Log in or register to post comments