代码之家  ›  专栏  ›  技术社区  ›  Paul T.

SCNNode方向问题

  •  0
  • Paul T.  · 技术社区  · 7 年前

    我放了一个 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?

    1 回复  |  直到 7 年前
        1
  •  2
  •   mnuages    7 年前

    启动iOS 11 SCNLookAtConstraint 有一个 localFront 属性,该属性允许您更改用于确定受约束节点方向的轴。