From: eihrul Date: Mon, 1 Feb 2010 08:02:27 +0000 (+0000) Subject: make Matrix_ToBonePose6s check the podality of quaternions rather than assuming they... X-Git-Tag: xonotic-v0.1.0preview~230^2~553 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=496e272607d62182e3ab552ba67667fa752d1548;p=xonotic%2Fdarkplaces.git make Matrix_ToBonePose6s check the podality of quaternions rather than assuming they are always positive from Matrix4x4_ToOrigin3Quat4Float git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9916 d7cf8633-e32d-0410-b094-e92efae38249 --- 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)