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

查看:273
本文介绍了将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对象,请使用其constraints属性.

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评估外观约束时,它将更新受约束节点的transform属性,以便该节点的负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天全站免登陆