X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=matrixlib.c;h=e15fb995f3248de63a8d35b7985ee533d4b09125;hb=819764171ec0f979dd6ab46a5d53e7b5221725db;hp=266ec14173b6d094fec45efc47bf66b8ae24a678;hpb=2c0539f6be0b8edddae93416c0beb38baf4a57ac;p=xonotic%2Fdarkplaces.git diff --git a/matrixlib.c b/matrixlib.c index 266ec141..e15fb995 100644 --- a/matrixlib.c +++ b/matrixlib.c @@ -1569,26 +1569,20 @@ void Matrix4x4_ToBonePose6s(const matrix4x4_t *m, float origininvscale, short *p { float origin[3]; float quat[4]; - float s; + float quatscale; Matrix4x4_ToOrigin3Quat4Float(m, origin, quat); // normalize quaternion so that it is unit length - s = quat[0]*quat[0]+quat[1]*quat[1]+quat[2]*quat[2]+quat[3]*quat[3]; - if (s) - { - s = 1.0f / sqrt(s); - quat[0] *= s; - quat[1] *= s; - quat[2] *= s; - quat[3] *= s; - } + quatscale = quat[0]*quat[0]+quat[1]*quat[1]+quat[2]*quat[2]+quat[3]*quat[3]; + if (quatscale) + quatscale = (quat[3] >= 0 ? -32767.0f : 32767.0f) / sqrt(quatscale); // use a negative scale on the quat because the above function produces a // positive quat[3] and canonical quaternions have negative quat[3] pose6s[0] = origin[0] * origininvscale; pose6s[1] = origin[1] * origininvscale; pose6s[2] = origin[2] * origininvscale; - pose6s[3] = quat[0] * -32767.0f; - pose6s[4] = quat[1] * -32767.0f; - pose6s[5] = quat[2] * -32767.0f; + pose6s[3] = quat[0] * quatscale; + pose6s[4] = quat[1] * quatscale; + pose6s[5] = quat[2] * quatscale; } void Matrix4x4_Blend (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2, double blend)