gpt4 book ai didi

ios - 将 ARCamera 旋转变换应用于节点 (ARKit)

转载 作者:行者123 更新时间:2023-11-29 00:02:19 26 4
gpt4 key购买 nike

我想将 ARCamera 的旋转应用于 3D 节点,以便该节点始终面向相机。我怎样才能在 Objective-C 中实现这段代码?

最佳答案

您可以使用 SCNBillboardConstraint 使 SCNNode 面向 ARCamera:

An SCNBillboardConstraint object automatically adjusts a node’s orientation so that its local z-axis always points toward the pointOfView node currently being used to render the scene. For example, you can use a billboard constraint to efficiently render parts of a scene using two-dimensional sprite images instead of three-dimensional geometry—by mapping sprites onto planes affected by a billboard constraint, the sprites maintain their orientation with respect to the viewer. To attach constraints to an SCNNode object, use its constraints property.

Objective-C :

SCNBillboardConstraint *lookAtConstraint = [SCNBillboardConstraint billboardConstraint];

node.constraints = @[lookAtConstraint];

swift :

let lookAtConstraint = SCNBillboardConstraint()
node.constraints = [lookAtConstraint]

如果你想让一个 SCNNode 面向另一个节点,那么你可以使用一个 SCNLookAtConstraint:

For example, you can use a look-at constraint to ensure that a camera or spotlight always follows the movement of a game character. To attach constraints to an SCNNode object, use its constraints property. A node points in the direction of the negative z-axis of its local coordinate system. This axis defines the view direction for nodes containing cameras and the lighting direction for nodes containing spotlights or directional lights, as well as the orientation of the node’s geometry and child nodes. When Scene Kit evaluates a look-at constraint, it updates the constrained node’s transform property so that the node’s negative z-axis points toward the constraint’s target node.

Objective-C :

SCNLookAtConstraint * lookAtNode = [SCNLookAtConstraint lookAtConstraintWithTarget:secondNode];
fistNode.constraints = @[lookAtNode];

swift :

 let lookAtConstraint = SCNLookAtConstraint(target: secondNode)
firstNode.constraints = [lookAtConstraint]

关于ios - 将 ARCamera 旋转变换应用于节点 (ARKit),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49151332/

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