i am trying to know how much SCNNode is rotated around the y axis. Everytime ARKit world is created it has different rotation, my idea is to scan QRCode, recognize if it rotated 0,90,180,270 degrees (already done), and place object always on exacly same direction, QRCode not rotated (0 degree) will point for example to North.
I was trying to get eulerAngles
from pointOfView
but don't know how to translate it and let to know how is rotated from (0,0,0). Any ideas?
ANSWER:
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)
}
`