Hello,
I am beginner in Vuforia, I’m trying to calculate the real distance between the AR camera and an image target as cm via Vuforia on Android, I found this code on the vuforia forums but when I try it, I don't get the good results.
rackableResult result = state.getTrackableResult(tIdx);
Trackable trackable = result.getTrackable();
Matrix44F modelViewMatrix_Vuforia = Tool.convertPose2GLMatrix(result.getPose());
Matrix44F inversMV = SampleMath.Matrix44FInverse(modelViewMatrix_Vuforia);
Matrix44F invTranspMV = SampleMath.Matrix44FTranspose(inversMV);
float cam_x = invTranspMV.getData()[12];
float cam_y = invTranspMV.getData()[13];
float cam_z = invTranspMV.getData()[14];
Log.v("QCV", "Posx=" + cam_x + ",posy=" + cam_y + ",posz=" + cam_z);
float distance = new Float(Math.sqrt(cam_x * cam_x + cam_y * cam_y + cam_z * cam_z));
Log.v("distance ",""+distance);
Can you help me please ? is there another function or code to calculate the distance?
Thanks
Thank you Jobigoud, it's work correctly for me when i try with this code:
Vuforia::Matrix34F pose = trackable->getPose();
Vuforia::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);
Replacing modelViewMatrix_Vuforia with getPose matrix and get the values of 3rd,7th and 11th elements fo getPos matrix.
Good luck.