impression7vx
impression7vx

Reputation: 1863

SCNNode Rotation Multiple Axes

This Question was posted, but never answered.

Similar to This Question, I am trying to understand SCNNode.rotation as a 4D vector. The prior question utilizes an example that only manipulates 1 axis, i.e.,

SCNNode.rotation = (0, 0, 1, degToRad(45)) //Rotate about z-axis by 45 degrees

which makes sense; however, what if I wanted to rotate the X axis by 20 degrees, Y axis by 45 degrees and then Z axis by 78 degrees?

SCNNode.rotation = ??

I would provide code I've tried, but I don't understand conceptually the notion of a 4D rotation vector.

Upvotes: 0

Views: 302

Answers (1)

E.Coms
E.Coms

Reputation: 11531

Every node just has a transform with 4x4 matrix. So all the rotation operations are reflecting in the changing the transform.

In this case, if you change either of rotation, eulerAngles and orientation, you are supposed to get same value.

If rotating about three axises, I suggested using eulerAngles.

node.eulerAnges = SCNVector3(x:degToRad(20),y:degToRad(45), z:degToRad(78))

After you set this, go back and check to value of rotation:

SCNVector4(x: -0.16975601, y: 0.5943193, z: 0.786109, w: 1.448788)

This means there is an axis going through point(-0.16975601, 0.5943193, 0.786109) and origin (0,0,0), and node is rotating around it for 1.448788 (82 degree).

Upvotes: 1

Related Questions