I did a little test with a cube which rotates only around it's x axis. This is a part of the quaternion keyframes I got, and there is indead a flip of signs:

<key t = "5" value = ".7330, -.6801, 0, 0"/>

<key t = "6" value = ".6234, -.7818, 0, 0"/>

<key t = "7" value = "-.4999, .8660, 0, 0"/>

<key t = "8" value = "-.3653, .9308, 0, 0"/>

Is there a way to get the quaternions in a way that those sign flips won't occur?

This is my matrix to quaternion code

Quaternion Matrix4::ToQuaternion() const { float trace = m[0][0] + m[1][1] + m[2][2]; if(trace > 0) { float root = sqrtf(trace + 1); Quaternion ret; ret.w = root * .5f; root = .5f / root; ret.x = (m[2][1] - m[1][2]) * root; ret.y = (m[0][2] - m[2][0]) * root; ret.z = (m[1][0] - m[0][1]) * root; ret.Normalize(); return ret; } else { const int next[] = {1,2,0}; int i = 0; if(m[1][1] > m[0][0]) i = 1; if(m[2][2] > m[i][i]) i = 2; int j = next[i]; int k = next[j]; float root = sqrtf(m[i][i] - m[j][j] - m[k][k] + 1); Quaternion ret; ret.vec[i] = root * .5f; root = .5f / root; ret.w = (m[k][j] - m[j][k]) * root; ret.vec[j] = (m[j][i] + m[i][j]) * root; ret.vec[k] = (m[k][i] + m[i][k]) * root; ret.Normalize(); return ret; } }