Swift SCNAction, rotate to a quaternion

399 Views Asked by At

I have a planeNode in a SceneKit Scene which I want to control. For this I want to constantly update the Orientation. Due to the Singularities of Euler Angles I am using Quaternions. So far I am directly updating planeNode.orientation and it works fine. The only issue is that due to the update rate it slightly jumps between orientations, which does not look very nice. I tried using SCNActions but the problem is I can only rotateTo and rotate by Euler Angles. Is there any way to rotateTo Quaternions?

Any help is very welcome! Thanks!

1

There are 1 best solutions below

0
alexismue On

I solved it by up using sims_slerp and therefore not updating the orientation directly to the new set point orientation but rather to a part of it:

let qSlerp = simd_slerp(simd_quatf(quat: self.planeNode.orientation), self.orientationSP!, 0.1)
// UPDATE ORIENTATION TO CLOSEST INTERPOLATION
self.planeNode.orientation = SCNQuaternion(simd_quat: qSlerp)}