ARKit Place a SCNNode facing the camera

前端 未结 6 2021
挽巷
挽巷 2021-02-02 00:15

I\'m using ARKit to display 3D objects. I managed to place the nodes in the real world in front of the user (aka the camera). But I don\'t manage to make them to fa

6条回答
  •  醉梦人生
    2021-02-02 01:05

    I want the node to face the camera when I place it then keep it here (and be able to move around). – Marie Dm Blockquote

    You can put object facing to camera, using this:

    if let rotate = sceneView.session.currentFrame?.camera.transform {
        node.simdTransform = rotate
    }
    

    This code will save you from gimbal lock and other troubles.

    The four-component rotation vector specifies the direction of the rotation axis in the first three components and the angle of rotation (in radians) in the fourth. The default rotation is the zero vector, specifying no rotation. Rotation is applied relative to the node’s simdPivot property.

    The simdRotation, simdEulerAngles, and simdOrientation properties all affect the rotational aspect of the node’s simdTransform property. Any change to one of these properties is reflected in the others.

    https://developer.apple.com/documentation/scenekit/scnnode/2881845-simdrotation https://developer.apple.com/documentation/scenekit/scnnode/2881843-simdtransform

提交回复
热议问题