Behaviour of *= seems different for Quaternions

Quaternions require an application order of q_existing = q_target * q_existing, I'm confused as to why q_existing *= q_target works as well...

Since a *= b is a = a * b yet for quaternions it seems to be a = b * a.

This is handy for me, because, for quaternions, that's the correct order but... I just wonder why.
My only conclusion is that
*= must be implemented differently based on the type...

Can anyone confirm this?

1 Like

Works fine for me:

var a = simd_quatf(angle: 10, axis: simd_float3(0,1,0))
var b = simd_quatf(angle: 20, axis: simd_float3(1,0,0))
let c = a * b
let d = b * a
a *= b
precondition(a == c)
precondition(a != d)
2 Likes

@tera You're right it seems it does do a = a * b after all. I was testing some silly edge case where a *= b worked for my case as well, but in most other cases only a = b * a works for me.

That's why I got confused. :sweat_smile: