Get “up” side of SCNNode from Orientation

前端 未结 2 1357
庸人自扰
庸人自扰 2021-02-10 18:14

I have an SCNBox in an SCNScene. Once the scene animates the SCNBox changes is orientation which can be seen by checking its presentationNode.ori

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-10 18:31

    node.orientation will give you a quaternion. You can also use node.eulerAngles or node.rotation (axis angle) if that makes your maths easier.

    In all cases I think you need to apply the inverse rotation to the vector [0, 1, 0] (up vector). The result vector (V) will give you the direction of the up face. To then find the up face, compare the dot products of the box faces and V. The highest dot product is the one of the face that is facing up.

    (An alternative way is to rotate the box's faces instead and do the dot products with [0,1,0].)

提交回复
热议问题