2

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)
}

`

Michal Zaborowski
  • 5,039
  • 36
  • 35
  • Hello, can you explain it in detail. like do you tap at QR code or get the positions automatically. I am working on similar thing but using three points to tap at. here is what i got till now: [link](https://stackoverflow.com/a/47835388/5567142). And if possible can i get the code please. – Alok Subedi Dec 25 '17 at 04:33
  • I cannot post a full solution because i was written this for my client, but you have comment what function does, and getRotationAroundY is some public function from some open source project – Michal Zaborowski Jan 02 '18 at 14:00

0 Answers0