ios - Why does a CALayer's transform3D's m34 need to be modified before applying the rotate transform? -
the following code can make perspective rotation transform layer:
catransform3d transform3dfoo = catransform3didentity; transform3dfoo.m34 = -1.0 / 1000; transform3dfoo = catransform3drotate(transform3dfoo, m_pi / 4, 1, 0, 0);
however, if 2 lines reversed:
catransform3d transform3dfoo = catransform3didentity; transform3dfoo = catransform3drotate(transform3dfoo, m_pi / 4, 1, 0, 0); transform3dfoo.m34 = -1.0 / 1000;
then perspective gone. orthographic (no perspective). familiar perspective know why reason?
update:
// first identity , transform3dfoo.m34 = -1.0 / 1000; done 1.00000 0.00000 0.00000 0.00000 0.00000 1.00000 0.00000 0.00000 0.00000 0.00000 1.00000 -0.00100 0.00000 0.00000 0.00000 1.00000 // , catransform3drotate(transform3dfoo, m_pi / 4, 1, 0, 0); 1.00000 0.00000 0.00000 0.00000 0.00000 0.70711 0.70711 -0.00071 0.00000 -0.70711 0.70711 -0.00071 0.00000 0.00000 0.00000 1.00000 // start identity , rotate statement done: 1.00000 0.00000 0.00000 0.00000 0.00000 0.70711 0.70711 0.00000 0.00000 -0.70711 0.70711 0.00000 0.00000 0.00000 0.00000 1.00000 // , transform3dfoo.m34 = -1.0 / 1000; done 1.00000 0.00000 0.00000 0.00000 0.00000 0.70711 0.70711 0.00000 0.00000 -0.70711 0.70711 -0.00100 0.00000 0.00000 0.00000 1.00000
(the tag of "opengl" added because same principle in opengl)
setting m34
first equivalent rotating first , projecting. setting m34
last equivalent projecting first , rotating. input coordinates have z=0, projecting first won't anything.
to see why is, need understand little how transform matrices work.
i believe in ca positions transformed transform matrix m
doing:
[x y z w] = [x y z w] * m
(see http://en.wikipedia.org/wiki/matrix_multiplication)
multiplying 2 transform matrices equivalent concatenating transforms. transform/matrix on left happens first. it's pretty easy see why is:
[x y z w] * (left * right) = ([x y z w] * left) * right
most (all?) of ca transform functions (eg catransform3drotate
) premultiply transform matrix aptly constructed matrix, eg:
m = rotate * m
setting m34
equivalent premultiplying projection matrix, is:
m = proj * m
(where proj
projection matrix -- identity matrix m34
set)
this isn't entirely true (which why keep saying roughly) -- works if m
has 0s , 1s in right places. basically, in general case, setting m34
nonsense thing -- right thing multiply projection matrix.
anyway, if put should able see why said in first paragraph true (assuming haven't made mistakes :)
Comments
Post a Comment