一起旋转X,Y和Z轴 [英] Rotate X, Y and Z axis all together
问题描述
我首先在Illustrator或Photoshop中3D旋转平面图形,获得精确的角度(x,y和z)在设计工具中应用于它,然后将相同的角度应用于放置在图像顶部的UILabel,以实现视觉上的同步。
I first 3D rotate a flat figure in Illustrator or Photoshop, get the exact angles(x, y and z) applied to it in the design tool and then apply the same angles to a UILabel placed on top of the image to synchronize them visually.
如何使用CATransform3DConcat同时旋转2轴,但是我不确定如何应用第三个轴。
I've figured out how to rotate 2 axis at the same time by using CATransform3DConcat but then I'm not sure how to apply the third.
float angleX = -18 * M_PI / 180;
CATransform3D t1 = CATransform3DMakeRotation(angleX, 1, 0, 0);
float angleY = -26 * M_PI / 180;
CATransform3D t2 = CATransform3DMakeRotation(angleY, 0, 1, 0);
CATransform3D combo1 = CATransform3DConcat(t1, t2);
self.labelPlay.layer.transform = combo1;
编辑
现在尝试这个,但是还是不好。
Trying this now but still no good. Tried all combinations of different orders but nothing.
float angleX = -18 * M_PI / 180;
CATransform3D t1 = CATransform3DMakeRotation(angleX, 1, 0, 0);
float angleY = -26 * M_PI / 180;
CATransform3D t2 = CATransform3DMakeRotation(angleY, 0, 1, 0);
float angleZ = 8 * M_PI / 180;
CATransform3D t3 = CATransform3DMakeRotation(angleZ, 0, 0, 1);
self.label.layer.transform = CATransform3DConcat(CATransform3DConcat(t3, t2), t1);
推荐答案
我不确定,但我认为这可能
I'm not entirely sure but I think this might be it.
对于设计人员而言,Illustrator / Photoshop中3D旋转角度将只适用于CATransform3D,这几乎是正确的,但您可能必须更改一件小事。
For designers thinking angles from 3D rotation in Illustrator/Photoshop would just work with CATransform3D, it's almost true but you might have to change one tiny thing.
假设您的设计工具中有x:-18,y:-26和z:8。将y和z切换为正/负可解决我的问题。所以现在我有了-
Let's say you have x : -18, y : -26 and z : 8 in your design tool. Switching y and z to positive/negative solved my problem. So now I have -
float angleX = -18 * M_PI / 180;
CATransform3D t1 = CATransform3DMakeRotation(angleX, 1, 0, 0);
float angleY = 26 * M_PI / 180;
CATransform3D t2 = CATransform3DMakeRotation(angleY, 0, 1, 0);
float angleZ = -8 * M_PI / 180;
CATransform3D t3 = CATransform3DMakeRotation(angleZ, 0, 0, 1);
self.label.layer.transform = CATransform3DConcat(CATransform3DConcat(t1, t2), t3);
我无法告诉您确切的原因,但是旋转正确。
I can't tell you why exactly but this rotates properly.
这篇关于一起旋转X,Y和Z轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!