Camera rotation in SceneKit

I posed a similar question to this question here , but it differs in that it deals with angular angles.

Given the setting I used in another post. A simple board that is on the screen, and a camera that looks at it, I want to rotate the camera. For simplicity, I make the whole camera in code. For the context, in accordance with another question and answer, I found that the board works for a long time on the Z axis, shorter on the X axis, and the height on the Y axis.

Adding this code to the scene, we will see that my board works on the Z axis. I lifted the camera a little on the Y axis to get a better view. My ultimate goal is to get a board running along the camera.

SCNNode *cameraNode = [SCNNode node]; cameraNode.camera = [SCNCamera camera]; cameraNode.camera.zFar = 200; cameraNode.camera.zNear = 0.1; [scene.rootNode addChildNode:cameraNode]; cameraNode.position = SCNVector3Make(0, 5, 0); cameraNode.eulerAngles = SCNVector3Make(0, 0, 0); 

gives Imgur

Great start. Then I try to rotate the camera so that it looks from top to bottom on the board. I understand that I will need to rotate around the X axis in order to accomplish this. I did this by trying the following.

 SCNNode *cameraNode = [SCNNode node]; cameraNode.camera = [SCNCamera camera]; cameraNode.camera.zFar = 200; cameraNode.camera.zNear = 0.1; [scene.rootNode addChildNode:cameraNode]; cameraNode.position = SCNVector3Make(0, 50, 0); cameraNode.eulerAngles = SCNVector3Make(0, 0, -M_PI/2); 

The iOS documentation claims that rotation in eulars is given with (z, y, x). However, this did not work, and he gave a blank screen. Then I started experimenting and found that rotating around the Z axis would lead me in the right direction.

 SCNNode *cameraNode = [SCNNode node]; cameraNode.camera = [SCNCamera camera]; cameraNode.camera.zFar = 200; cameraNode.camera.zNear = 0.1; [scene.rootNode addChildNode:cameraNode]; cameraNode.position = SCNVector3Make(0, 50, 0); cameraNode.eulerAngles = SCNVector3Make(-M_PI/2, 0, 0); 

This screen is displayed. Imgur

It didn’t make sense, but I continued it and eventually found that, rotating around the Y axis, I could get the desired screen.

 SCNNode *cameraNode = [SCNNode node]; cameraNode.camera = [SCNCamera camera]; cameraNode.camera.zFar = 200; cameraNode.camera.zNear = 0.1; [scene.rootNode addChildNode:cameraNode]; cameraNode.position = SCNVector3Make(0, 50, 0); cameraNode.eulerAngles = SCNVector3Make(-M_PI/2, -M_PI/2, 0); 

Rotating y was also a little puzzling because I expected you to have to rotate around the Z axis. Imgur

While this code is working, I have a similar question for my other post. Why do I need to rotate around the Z axis instead of the X axis for my first rotation. I think that I could simply not understand the angular angles. Good.

Thanks in advance

Edit:

as pointed out by @mnuages, the online documentation states that this vector is in (x, y, z). This is contrary to the header documentation that I usually use, as can be seen here. Imgur

It would seem to be just a mistake / typo in Apple code. Thanks for clearing it.

+4
source share
1 answer

[Comment does not fit in the comment]

Note that the documentation states that

The order of the components in this vector corresponds to the axes of rotation:

  • A step (x component) is a rotation around the x axis of node s.
  • Yaw (y component) is a rotation around the y axis of node s.
  • Roll (z component) is the rotation around the z axis of node s.
+3
source

All Articles