将 ARCamera 旋转变换应用到节点 (ARKit) [英] Apply ARCamera rotation transform to node (ARKit)

查看:22
本文介绍了将 ARCamera 旋转变换应用到节点 (ARKit)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 ARCamera 的旋转应用于 3D 节点,以便该节点始终面向相机.如何在 Objective-C 中实现此代码?

I want to apply the rotation of the ARCamera to a 3D node so that the node will always face the camera. How can I implement this code in Objective-C?

推荐答案

您可以使用 SCNBillboardConstraint 获得一个 SCNNode 来面对 ARCamera:

You can get an SCNNode to face the ARCamera by using an SCNBillboardConstraint:

SCNBillboardConstraint 对象会自动调整节点的方向,使其局部 z 轴始终指向当前用于渲染场景的 pointOfView 节点.例如,您可以使用广告牌约束来使用二维精灵图像而不是三维几何图形有效地渲染场景的一部分——通过将精灵映射到受广告牌约束影响的平面上,精灵保持它们相对于观察者的方向.要将约束附加到 SCNNode 对象,请使用其约束属性.

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.

目标 C:

SCNBillboardConstraint *lookAtConstraint = [SCNBillboardConstraint billboardConstraint];

node.constraints = @[lookAtConstraint];

斯威夫特:

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

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

If you want an SCNNode to face another node then you can use an SCNLookAtConstraint:

例如,您可以使用注视约束来确保摄像机或聚光灯始终跟随游戏角色的移动.要将约束附加到 SCNNode 对象,请使用其约束属性.节点指向其局部坐标系的负 z 轴方向.该轴定义了包含摄像机的节点的视图方向和包含聚光灯或平行光的节点的照明方向,以及节点几何体和子节点的方向.当 Scene Kit 评估观察约束时,它会更新受约束节点的变换属性,以便节点的负 z 轴指向约束的目标节点.

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.

目标 C:

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

斯威夫特:

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

这篇关于将 ARCamera 旋转变换应用到节点 (ARKit)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆