Use btAsin in setHPR

The following quaternion calculated by shortestArcQuat in
rescue animation leads to nan in asinf:

0.710828841, -0.00974362344, -0.703500867, 0.00481829932
-2.0f * (X * Z - Y * W) equals 1.00004351 with above figures

With btAsin it will:
if (x<btScalar(-1)) x=btScalar(-1);
if (x>btScalar(1)) x=btScalar(1);
return asin(x);
This commit is contained in:
Benau 2016-09-13 07:43:19 +08:00
parent b699018879
commit f5d43aaa2e

View File

@ -30,7 +30,7 @@ void Vec3::setHPR(const btQuaternion& q)
float ZSquared = Z * Z; float ZSquared = Z * Z;
setX(atan2f(2.0f * (Y * Z + X * W), -XSquared - YSquared + ZSquared + WSquared)); setX(atan2f(2.0f * (Y * Z + X * W), -XSquared - YSquared + ZSquared + WSquared));
setY(asinf(-2.0f * (X * Z - Y * W))); setY(btAsin(-2.0f * (X * Z - Y * W)));
setZ(atan2f(2.0f * (X * Y + Z * W), XSquared - YSquared - ZSquared + WSquared)); setZ(atan2f(2.0f * (X * Y + Z * W), XSquared - YSquared - ZSquared + WSquared));
} // setHPR(btQuaternion) } // setHPR(btQuaternion)