Rotate around the X, Y, and Z axis

enter image description here

First, I rotate the 3D shape in 3D 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 the UILabel placed on top of the image to synchronize them visually.

I figured out how to rotate 2 axes at the same time using CATransform3DConcat, but then I'm not sure how to apply the third one.

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; 

EDIT

Trying it now, but still no good. I 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); 
+5
source share
1 answer

I'm not quite sure, but I think it is possible.

For designers, thinking of angles from 3D rotation in Illustrator / Photoshop will work with CATransform3D, it's almost true, but you may have to change one tiny thing.

Say you have x: -18, y: -26 and z: 8 in your design tool. Switching y and z to a positive / negative solution to 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 exactly why, but it really rotates.

+1
source

Source: https://habr.com/ru/post/1247764/


All Articles