5

我有一个高度为 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;
4

1 回答 1

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;
于 2013-05-28T12:41:48.887 回答