我已经发布了类似的问题,这在这里,但是这是因为它与EULAR角度涉及不同。
鉴于我在另一篇文章中所做的设置。屏幕上有一个简单的板子,还有一个看着它的相机,我想旋转相机。为简单起见,我将用代码编写整个摄像机。就上下文而言,根据其他问答,我确定板子在Z轴上运行的时间较长,在X轴上运行的时间较短,而高度在Y轴上。
将此代码添加到场景中,我们可以看到我的电路板在Z轴上运行。我将相机在Y轴上稍微抬起,以获得更好的视野。我的最终目标是使电路板在摄像机上长期运行。
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);
给
很好的开始。然后,我尝试旋转相机,使其从顶部向下看向木板。我的理解是,我需要绕X轴旋转才能完成此操作。我通过尝试以下方法来做到这一点。
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);
iOS文档指出以(z,y,x)设置欧拉的旋转。但是,这没有用,只能显示空白屏幕。然后,我开始进行实验,发现绕Z轴旋转将使我朝正确的方向前进。
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);
这呈现了此屏幕。
这没有任何意义,但我继续进行下去,最终发现通过围绕Y轴旋转,我可以获得所需的屏幕。
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);
The y rotation was also a little baffling because I would have expected to have to rotate around the Z axis.
While this code works I have a similar question to my other post. Why do I have to rotate around the Z axis instead of the X axis for my first rotation. I think I might just not understand eular angles that well.
Thanks in advance
Edit:
as @mnuages pointed out, the documentation online states that this vector is in (x,y,z). This is contrary to the header documentation which I would normally use as can be seen here
It would appear that this is just a bug/typo in Apple's code. Thanks for clearing it up.
[Comment does not fit in a comment]
Please note that the documentation states that
The order of components in this vector matches the axes of rotation:
- 间距(x分量)是围绕节点x轴的旋转。
- 偏航角(y分量)是围绕节点y轴的旋转。
- Roll(z分量)是绕节点z轴的旋转。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句