CATransform3D:透视变换后计算高度

时间:2013-05-28 11:23:30

标签: ios objective-c core-animation catransform3d catransform3drotate

我有一个高度为50的图层,我围绕x轴旋转它。 。 。如何在旋转进行时计算高度?

CATransform3D subLayerTransform = CATransform3DMakeTranslation(0, 0, 0);
subLayerTransform.m34 = -1 / 1800; //How does height relate to perspective and angle?
subLayerTransform = CATransform3DTranslate(subLayerTransform, 0, 0, 0);
subLayerTransform = CATransform3DRotate(subLayerTransform, 45 * (M_PI / 180), 1, 0, 0);
_transitionLayer.sublayerTransform = subLayerTransform;

1 个答案:

答案 0 :(得分:3)

围绕y轴旋转

  • y'= y * cos q - z * sin q
  • z'= y * sin q + z * cos q
  • x'= x

高度为y1 - y0。因此,计算新的y1和y0:

CGFloat y0 = 0;
CGFloat y1 = 50;
CGFloat z = -1800; //This relates to the m34 perspective matrix.

y0 = y0 * cos(radians(45)) - z * sin(radians(45));
y1 = y1 * cos(radians(45)) - z * sin(radians(45));

CGFloat newHeight = y1 - y0;