如何使用ARKit iOS swift扩展scncylinder系列?

时间:2019-01-05 05:10:44

标签: ios swift xcode scenekit arkit

我正在从事AR导航。我已经从源到目的地画了一条ar线。现在我正在尝试做淡入淡出线,该线应该显示一定的距离,当我向前移动时,应该显示剩余的线。这是我enter image description here想要enter image description here的输出结果的屏幕截图

此处是从源到目标绘制线的代码:

        private func placeCylinder(source: SCNVector3, destination: SCNVector3) {
    var  height = source.distance(receiver: destination)
    let anchor:ARPlaneAnchor

    height = anchor.extent.x
   //        let anchorValue = anchor.extent.x

    let  cylinder = SCNCylinder(radius: ArkitNodeDimension.cylinderRadius, height: CGFloat(height))
    cylinder.firstMaterial?.diffuse.contents = UIColor.white.withAlphaComponent(0.85)
    let node = SCNNode(geometry: cylinder)
    node.position = SCNVector3((source.x + destination.x) / 2, Float(-(ArkitNodeDimension.nodeYPosition)), (source.z + destination.z) / 2)
    let dirVector = SCNVector3Make(destination.x - source.x, destination.y - source.y, destination.z - source.z)
    let yAngle = atan(dirVector.x / dirVector.z)
    print("yangle::\(yAngle)")
    node.eulerAngles.x = .pi / 2
    node.eulerAngles.y = yAngle

    // scnplane //


    sceneView.scene.rootNode.addChildNode(node)
}

0 个答案:

没有答案