Log in or register to post comments

Placing UIView over image target - minor misalignment

November 28, 2012 - 1:35am #1

Hi, I am working on placing an UIView over the image target. Starting from the ImageTarget example and timlai's class (http://pastebin.com/kmeVZ7jy) I use the following code in the render() method to create a CATransform3D structure from the pose matrix that later I can assign to the CALayer of UIView:


    const QCAR::ImageTarget* imageTarget = (const QCAR::ImageTarget*)trackable;
    QCAR::Vec2F size = imageTarget->getSize();

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

    CGFloat ScreenScale = [[UIScreen mainScreen] scale];
    float xscl = qUtils.viewport.sizeX/ScreenScale/2;
    float yscl = qUtils.viewport.sizeY/ScreenScale/2;

    QCAR::Matrix44F projectedTransform = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
    QCAR::Matrix44F qcarTransform = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};

    ShaderUtils::translatePoseMatrix(size.data[0] / 2, size.data[1] / 2, 0, projectedTransform.data);
    ShaderUtils::scalePoseMatrix(xscl, -yscl, 1.0, projectedTransform.data); // flip along y axis
    ShaderUtils::multiplyMatrix(projectedTransform.data, qUtils.projectionMatrix.data, qcarTransform.data);
    ShaderUtils::multiplyMatrix(qcarTransform.data, modelViewMatrix.data, qcarTransform.data);
    CATransform3D transform = *((CATransform3D*)qcarTransform.data); // both are array[16] of float

    // UIView* myView = ...
    myView.frame = CGRectMake(0, 0, size.data[0], size.data[1]);
    myView.layer.transform = transform;


Now this code works almost as I expect, the view is positioned more or less over the image target. But unfortunately the position is inaccurate: if I walk around the image target the UVIew moves around the center of the target in a small circle with a radius of approxiamtely 5-10% of the width of the target and the view. The view seems to be placed somewhat closer to the camera then it should be, however I am unsure whether it is a misalignment in the z coordinate or an error in the transformation matrix calculation. Any hint on what could cause this error?

Placing UIView over image target - minor misalignment

December 7, 2012 - 3:25am #4


Apologies for the delay in replying - are you still encountering this problem?  

Can you post a screenshot?



Placing UIView over image target - minor misalignment

November 29, 2012 - 12:40am #3

Hi Nalin,

thanks for your reply. I use the image targets for the example (stones & chips) and my view is misaligned over both in the same way. I initialize it with the same dimensions as of the image target, currently hard coded:

    float targetWidth = 247; // data comes from StonesAndChips.xml
    float targetHeight = 173;

    CGRect myViewFrame = CGRectMake(0, 0, targetWidth, targetHeight);
    myView = [[UIView alloc] initWithFrame:overlayFrame];
    myView.backgroundColor = [UIColor colorWithRed:0.0 green:1.0 blue:1.0 alpha:0.5];

Enabling the drawing of the teapot in OpenGL works well as expected i.e. it is not misaligned.

Placing UIView over image target - minor misalignment

November 28, 2012 - 9:42am #2

Hi mrtj,

Have you tried a range of different Image Targets?

Also, can I just check the dimensions and whether you set these in mm on the TMS?

Finally, if you place another augmentation (just in OpenGL) does this rotate as well, or is it just the UIView?




Log in or register to post comments