Ios 何时在ARKit中使用worldTransform()以及何时使用transform()

Ios 何时在ARKit中使用worldTransform()以及何时使用transform(),ios,swift,matrix,augmented-reality,arkit,Ios,Swift,Matrix,Augmented Reality,Arkit,我一直在学习ARKit有两个基本的方法来变换一个物体相对于它的相对位置。想知道何时使用transform()方法和worldTransform()方法,与示例的明显区别将非常有用 let transform = result.worldTransform let isOnPlane = result.anchor is ARPlaneAnchor object.setTransform(transform, relativeTo: cameraTransform,

我一直在学习ARKit有两个基本的方法来变换一个物体相对于它的相对位置。想知道何时使用
transform()
方法和
worldTransform()
方法,与示例的明显区别将非常有用

let transform = result.worldTransform
let isOnPlane = result.anchor is ARPlaneAnchor
object.setTransform(transform, relativeTo: cameraTransform,
                           smoothMovement: !isOnPlane,
                                alignment: planeAlignment,
                           allowAnimation: allowAnimation)

1。对于
ARAnchor
ARCamera
使用
local
实例属性

transform
是一个矩阵,用于编码锚定相对于放置锚定的AR会话的世界坐标空间的位置、方向和比例

例如,您可以很容易地获得由4x4矩阵表示的ARAnchor变换或ARCamera变换

var transform: simd_float4x4 { get }
应以这种方式使用此变换属性(对于本地定位和定向对象):

2。对于
hitTestResults
ARAnchors
使用
global
实例属性

worldTransform
是命中测试结果相对于世界坐标系的位置和方向

您可以这样使用它:

if !hitTestResult.isEmpty {
    guard let hitResult = hitTestResult.first else {
        return
    }
    addPlane(hitTestResult: hitResult)
    print(hitResult.worldTransform.columns.3)
}

// OR

let anchor = ARAnchor(name: "PANTHER", transform: hitTestResult.worldTransform)
sceneView.session.add(anchor: anchor)

希望这有帮助。

非常感谢您的解释,现在我明白了。
var worldTransform: simd_float4x4 { get }
if !hitTestResult.isEmpty {
    guard let hitResult = hitTestResult.first else {
        return
    }
    addPlane(hitTestResult: hitResult)
    print(hitResult.worldTransform.columns.3)
}

// OR

let anchor = ARAnchor(name: "PANTHER", transform: hitTestResult.worldTransform)
sceneView.session.add(anchor: anchor)