如何计算围绕y轴旋转多少ARKit SCNNode

时间:2017-12-22 02:06:49

标签: ios swift 3d arkit

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

我试图从eulerAngles获取pointOfView,但不知道如何翻译它,让我们知道如何从(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)
}

`

0 个答案:

没有答案