Node Rotation In SceneKit SceneKitRotation

佐手、 提交于 2019-12-12 00:33:01

问题


I have just jumped in to using scene kit for iOS for the first time. What I am trying to do is import a .dae file, and rotate the object in code. What is happening is that when I import my file, I see that it is oriented the way I would expect.

This is great, now I want to rotate it so that the longer end goes horizontally. With my coordinate system this should be a 90 degree rotation around the Z axis. Doing that in the graphical part of xcode shows this.

The problem comes in when I start to manipulate this in code. If I undo the rotation in the graphical interface and try to perform it in code I get unexpected behavior.

If I start with no code changes, the simulator shows this

If I perform a code rotation around the Z axis with this code

// create a new scene
SCNScene *scene = [SCNScene sceneNamed:@"art.scnassets/board.dae"];
SCNNode *board = [scene.rootNode childNodeWithName:@"board" recursively:NO];
board.rotation = SCNVector4Make(0, 0, 1, M_PI/2);

I do not see the expected behavior in the simulator, I get this

Which does not show much detail but the board has been rotated around the Vertical axis, which I thought would be the Y axis. This led me to try and rotate around the Y axis for kicks and grins. Here is the code for that.
// create a new scene
SCNScene *scene = [SCNScene sceneNamed:@"art.scnassets/board.dae"];
SCNNode *board = [scene.rootNode childNodeWithName:@"board" recursively:NO];
board.rotation = SCNVector4Make(0, 1, 0, M_PI/2);

This yields the following, which is what I want.

Now for the real question, why do I have to rotate around a different axis in code? In this instance I was able to make it work, but in others like my camera, I can not. I think there must be some sort of coordinate shift that I am missing once something goes to code.

Thanks in advance.

来源:https://stackoverflow.com/questions/31859597/node-rotation-in-scenekit-scenekitrotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!