我想知道 SCNNode 围绕 y 轴旋转了多少。每次创建 ARKit 世界时它都有不同的旋转,我的想法是扫描 QRCode,识别它是否旋转了 0,90,180,270 度(已经完成),并且将对象始终放在方向相同的方向上,QRCode 未旋转(0 度)将指向例如到北方。

我试图从pointOfView获取eulerAngles但不知道如何翻译它并让我们知道如何从(0,0,0)旋转。有任何想法吗?

回答:

if let hitTestResult = hitTestResults.first, let camera = self.pointOfView     {

     let yaw = atan2f(camera.simdWorldTransform.columns.0.x, camera.simdWorldTransform.columns.1.x)
     // convert yaw from [-180; 180] to 0; 360
     let yawEuler = ARKitMathNormalizedDegressToCircleDegrees(Double(yaw))

     // calculate angle between qrCode north rotation and current point of view
     let angleToRotateTransform = ARKitMathDistanceAngleBetween(firstAngleInDegrees: yawEuler, secondAngleInDegrees: qrCodeRotation)

     // make rotation matrix and apply to hit results
     let rotationMatrix = self.getRotationAroundY(Float(angleToRotateTransform.degreesToRadians))
     let transform = simd_mul(hitTestResult.worldTransform, rotationMatrix)
}

`