Ah, go on then.
I'd like to create a SCNTransformConstraint
orientation constraint so that a SCNNode
is always oriented to the world's x, y & z axes, no matter how the node's parents are oriented / move about.
I can create an orientation constraint working in world space like this:
let orientationConstraint =
SCNTransformConstraint.orientationConstraint(inWorldSpace: true) {
(node, orientation) -> SCNQuaternion in
return <<<need quaternion identity here>>>
}
node.constraints = [orientationConstraint]
But I need by constraint callback to provide the multiplicative identity quaternion. When using quaternions to describe orientation and rotation as scene kit does, the quaternion identity represents no rotation. Or an orientation in world coordinates that is aligned to the world.
This is analogous to the way that scaling by 1 gives the same scale. And setting a scale to 1 resets something to have no scaling.
For scene kit matrices there is SCNMatrix4Identity
. Or, the additive identity for scene kit vectors: SCNVector3Zero
.
How can I get the quaternion identity for multiplication?
There does not appear to be a SCNQuaternionIdentity
.
The identity quaternion can be constructed with SCNQuaternion(0, 0, 0, 1)
.
Be careful not to use the default constructor SCNQuaternion()
. It is equivalent to SCNQuaternion(0, 0, 0, 0)
, which doesn't represent a valid orientation.