I am writing an AR application on iOS and am using CATransform3D transforms on a UIView.
Through OpenCV, I can get a perspective matrix through the call cvGetPerspectiveTransform(). This returns a 3x3 matrix.
I can't remember where I found it, but I had sample code that did the following:
//the opencv transform matrix is put into map_matrix
cvGetPerspectiveTransform (src_pnt, dst_pnt, map_matrix);
CATransform3D t = CATransform3DIdentity;
// map over the CATransform3D 4x4 matrix from the opencv 3x3 matrix
t.m11 = cvmGet(map_matrix,0,0);
t.m12 = cvmGet(map_matrix,1,0);
t.m14 = cvmGet(map_matrix,2,0);
t.m21 = cvmGet(map_matrix,0,1);
t.m22 = cvmGet(map_matrix,1,1);
t.m24 = cvmGet(map_matrix,2,1);
t.m41 = cvmGet(map_matrix,0,2);
t.m42 = cvmGet(map_matrix,1,2);
t.m44 = cvmGet(map_matrix,2,2);
myView.layer.transform = t;
However, applying this form causes my view to go crazy and jump all over the place. With a little experimenting, I found that only these three mappings work somewhat:
t.m14 = cvmGet(map_matrix,2,0); //left and right transform
t.m24 = cvmGet(map_matrix,2,1); //up and down transform
t.m21 = cvmGet(map_matrix,0,1); //some kind of skew?
I've been reading up on 3d graphics and the transform math, but it's quite a daunting task.
What would be the correct mapping of the 4x4 matrix from the 3x3 matrix?
Thank you!