How can I calculate a multi-axis SCNVector4 rotation for a SCNNode?

后端 未结 4 462
栀梦
栀梦 2021-01-14 10:18

The SCNNode take a rotation using a SCNVector4, which has an angle (w) and a magnitude how that angle applies to each axis (x, y, z). For example, to rotate 45

相关标签:
4条回答
  • 2021-01-14 10:45

    Do you ask for rotation matrix or how to simply rotate in general? If the second is correct then for example:

    [node runAction:[SCNAction rotateByX:0 y:M_PI z:0 duration:0]];
    
    0 讨论(0)
  • 2021-01-14 10:46

    You'll need to generate an SCNVector4 for each of the rotations, and then multiply them. Note that the order of operations matters!

    http://www.cprogramming.com/tutorial/3d/rotationMatrices.html has a pretty good writeup of the math. Any OpenGL reference that deals with rotation matrices is worth a look too.

    0 讨论(0)
  • 2021-01-14 10:48

    Instead of rotation property, use eulerAngles and specify angle for each axis

    0 讨论(0)
  • 2021-01-14 10:51

    If you're not animating the rotation, it might be cleaner to just set the transform matrix directly, like:

    node.transform = CATransform3DRotate(CATransform3DRotate(CATransform3DRotate(node.transform, xAngle, 1, 0, 0), yAngle, 0, 1, 0), zAngle, 0, 0, 1);
    
    0 讨论(0)
提交回复
热议问题