Is it normal for an SCNNode pivot to change the nodes position?

不问归期 提交于 2020-01-25 14:24:07

问题


I'm trying to rotate a block by setting its pivot point to any of the corners, but it seems as though setting the pivot point actually repositions the node, keeping the point exactly where it was...

for example

SCNBox *box = [SCNBox boxWithWidth:1 height:2 length:1 chamferRadius:0];
SCNNode *node = [SCNNode nodeWithGeometry:box];

node.position = SCNVector3Make(0, 0, 0);
[self.scene.rootNode addChildNode:node];

node.pivot = SCNMatrix4MakeTranslation(0.5, -1, 0.5);

[node runAction:[SCNAction rotateByAngle:GLKMathDegreesToRadians(90) 
                              aroundAxis:SCNVector3Make(0, 0, 1) 
                                duration:2]];

With a node.position of 0,0,0 and a box geometry of 1, 2, 1, I would have imagined this block to be sitting 1 unit above the floor... which it does if you don't set the pivot.

The real question is, how would you set the pivot position of this node, without it affecting it's position, so if I for example pushed the right key, it would pivot on the z-axis around the bottom right most point, and if I pushed the left key, it would pivot around the bottom left most point, and same for up and down but on the x-axis.


回答1:


the pivot property of an SCNNode is similar to the anchorPoint of a CALayer (see Anchor Points Affect Geometric Manipulations). If you want a change to the pivot property not to have any visual effect, you'll also have to change its transform (or position) property.



来源:https://stackoverflow.com/questions/28552004/is-it-normal-for-an-scnnode-pivot-to-change-the-nodes-position

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