"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

display distance in UILabel in ImageTargets Project

Hi all ,

I am getting the good output when I am using the ImageTargets Projects  for detecting my logo . Now I have to display the distance in the UILabel . For calculating the distance I have used the below code in the EAGLView.mm .

 

            QCAR::Matrix34F pose = result->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]);

            NSLog(@"distance: %f", distance);

  

 Kindly tell me in which class I have to add the UILabel code . And what what are the units which I am getting in the distance variable . My Target image size which I have in the database is 247 and the image size on which I have focused the camera is 800 . Please tell me . Thanks in advance .

If you try and add the code for the UI Label directly in RenderFrameQCAR it will not work because it gets called in a background thread.

To make it work you need to wrap the code in a method that can get called onthe main thread by using PerformSelectorOnMainThread.