gpt4 book ai didi

swift - ARKit:在两个节点/向量之间放置平面

转载 作者:行者123 更新时间:2023-11-30 10:48:29 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

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

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

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

关于swift - ARKit:在两个节点/向量之间放置平面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55214487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com