简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM