Spatial framework, Rotation3D eye target up (look at), Quaternion flip

Hi, I want to begin by saying thank you Apple for making the Spatial framework! Please add a million more features ;-)

I'm using the following code to make an object "look at" another point, but at a particular rotation the object "flips" its rotations.

See a video here: https://www.dropbox.com/s/5irxt0gxou4c2j6/QuaternionFlip.mov?dl=0

I shake the mouse cursor when it happens to make it obvious to you.

import Spatial

let lookAtRotation = Rotation3D(eye: Point3D(position), target: Point3D(x: 0, y: 0, z: 0), up: Vector3D(x: 0, y: 1, z: 0))

myObj.quaternion = lookAtRotation.quaternion

So my question is why is this happening, and how can I fix it?

thx

This is because the look-at rotation takes an up vector, and the green cone is up. If your could peek at the ‘next’ rotation, and if dot(new, previous) < 0, then use up: Vector3D(y: -1) instead of +1 (or, really, negate it from whatever was used on the last frame. That would ensure that the object doesn’t flip wildly.

Spatial framework, Rotation3D eye target up (look at), Quaternion flip
 
 
Q