SceneKit: understanding the pivot property of SCNNode

前端 未结 3 549
梦如初夏
梦如初夏 2021-01-12 19:05

The goal is to increase the length of a SCNBox such that it only grows in the positive-z direction.

This answer suggests playing with the pivot property

3条回答
  •  再見小時候
    2021-01-12 19:51

    Say you have a box created like this:

    SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)
    

    The pivot point will be in the center of that box, you now want to move it to one of the edges. This can be done by translating the pivot node by 0.5. (This is half the width of the box or the distance between the center and the edge.)

    boxNode.pivot = SCNMatrix4MakeTranslation(0, 0, -0.5)
    

    The pivot point will now be located at center X, center Y, and zero Z of the object. If you now scale the box it will only grow in the positive Z direction.

提交回复
热议问题