【发布时间】:2018-03-19 14:22:25
【问题描述】:
我在场景中添加了SCNNode。我想在空间中提供适当的旋转,因为这个节点是一个金字塔。我希望Z axis指向V2点,X axis指向V1点(这些V2和V1点是动态计算的,当然在这种情况下轴之间的角度将为90度,因为我计算正确)。
问题:我不能指向X轴,因为SCNLookAtConstraint(target: nodeWithV2)只指向Z轴,我看到的是Z轴是可以的,但是X轴总是随机的,这就是为什么我的金字塔方向总是错误的。如何指向 X 轴?
这是我的代码:
let pyramidGeometry = SCNPyramid(width: 0.1, height: 0.2, length: 0.001)
pyramidGeometry.firstMaterial?.diffuse.contents = UIColor.white
pyramidGeometry.firstMaterial?.lightingModel = .constant
pyramidGeometry.firstMaterial?.isDoubleSided = true
let nodePyramid = SCNNode(geometry: pyramidGeometry)
nodePyramid.position = SCNVector3(2, 1, 2)
parent.addChildNode(nodePyramid)
let nodeZToLookAt = SCNNode()
nodeZToLookAt.position = v2
parent.addChildNode(nodeZToLookAt)
let constraint = SCNLookAtConstraint(target: nodeZToLookAt)
nodePyramid.constraints = [constraint]
但这只是设置Z轴的方向,这就是为什么X轴总是随机的,所以旋转总是随机的。如何将 X 轴方向设置为我的点 V1?
【问题讨论】:
标签: ios swift scenekit ios11 scnnode