【问题标题】:ARKit: Placing Plane Between Two Nodes/VectorsARKit:在两个节点/向量之间放置平面
【发布时间】:2019-03-31 21:33:29
【问题描述】:

我试图在两个向量之间放置一个平面。但是,平面的方向很重要,因为我将箭头从第一个节点“指向”到第二个节点。这是我尝试过的:

private func placeArrows(source: SCNVector3, destination: SCNVector3) {
    let height = source.distance(vector: destination)
    let plane = SCNPlane(width: CGFloat(0.4), height: CGFloat(height))
    plane.firstMaterial?.diffuse.contents = UIImage(named: "Arrow")
    plane.firstMaterial?.isDoubleSided = true
    plane.firstMaterial?.diffuse.contentsTransform = SCNMatrix4MakeScale(1,-height,1)
    plane.firstMaterial?.diffuse.wrapT = SCNWrapMode.repeat
    plane.firstMaterial?.diffuse.wrapS = SCNWrapMode.repeat

    let node = SCNNode(geometry: plane)
    node.position = SCNVector3((source.x + destination.x) / 2, floor_pos_y, (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)
    node.eulerAngles.x = -.pi / 2
    node.eulerAngles.y = yAngle
    route_nodes.append(node)
    ARView.scene.rootNode.addChildNode(node)
}

平面最终指向两个方向,即一些指向第二个节点,一些指向第一个节点。而我一直无法弄清楚这一点。任何帮助将不胜感激。谢谢!

编辑:

Here is a screenshot of the result

如您所见...一个箭头指向左侧,一个指向右侧。期望的结果是两个箭头都指向相同的方向,即向左

【问题讨论】:

  • 你能分享输出截图吗..
  • @PvDev 我添加了一个屏幕截图。谢谢!

标签: swift arkit


【解决方案1】:

在尝试从不同角度解决这个问题后,我终于找到了问题所在。

let yAngle = atan(dirVector.x / dirVector.z)

这一行实际上应该替换为以下行:

let yAngle = atan2(dirVector.x, dirVector.z)

【讨论】:

    猜你喜欢
    • 2018-12-01
    • 2017-12-29
    • 2019-03-29
    • 2018-10-20
    • 2019-06-30
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 2019-10-25
    相关资源
    最近更新 更多