ios - ARKit - 如何将对象位置更改为另一个表面

时间:2018-04-15 05:16:50

标签: ios arkit

我正在使用ARKit,我有一个像这样移动对象的功能:

var currentNode = SCNNode()
@objc func moveNode(_ gesture: UIPanGestureRecognizer) {

    if !isRotating{

        //1. Get The Current Touch Point
        let currentTouchPoint = gesture.location(in: self.sceneView)

        if gesture.state == .began {
            guard let nodeHitTest = self.sceneView.hitTest(currentTouchPoint, options: nil).first else {return}
            let nodeHit = nodeHitTest.node
            currentNode = nodeHit
        }

        if gesture.state == .changed {
            //2. Get The Next Feature Point Etc
            guard let hitTest = self.sceneView.hitTest(currentTouchPoint, types: .existingPlane).first else { return }

            //3. Convert To World Coordinates
            let worldTransform = hitTest.worldTransform

            //4. Set The New Position
            let newPosition = SCNVector3(worldTransform.columns.3.x, worldTransform.columns.3.y, worldTransform.columns.3.z)

            currentNode.simdPosition = float3(newPosition.x, newPosition.y, newPosition.z)
        }
    }
}

如果我的相机检测到两个表面,我该如何将物体从当前表面移动到另一个表面?谢谢大家。

0 个答案:

没有答案