以下代码可以对图层进行透视旋转变换:
CATransform3D transform3DFoo = CATransform3DIdentity;
transform3DFoo.m34 = -1.0 / 1000;
transform3DFoo = CATransform3DRotate(transform3DFoo, M_PI / 4, 1, 0, 0);
但是,如果两行颠倒:
CATransform3D transform3DFoo = CATransform3DIdentity;
transform3DFoo = CATransform3DRotate(transform3DFoo, M_PI / 4, 1, 0, 0);
transform3DFoo.m34 = -1.0 / 1000;
然后视角消失了。现在它是正交的(没有透视)。熟悉透视的人知道原因吗?
更新:
// First Identity and then transform3DFoo.m34 = -1.0 / 1000; is 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
// and then 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
// Now start with Identity and only the Rotate statement is 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
// and then transform3DFoo.m34 = -1.0 / 1000; is 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
(加上“OpenGL”的标签是因为在OpenGL中应该是一样的原理)