Math Lib: mat3_to_eulo2 & mat3_to_eul2 mixed float/double differently

replace sqrt with hypotf to avoid precision loss instead
This commit is contained in:
Campbell Barton 2014-06-14 17:10:46 +10:00
parent 019a8bc23b
commit 94d4b31323
1 changed files with 28 additions and 35 deletions

View File

@ -1088,25 +1088,24 @@ static void mat3_to_eul2(float tmat[3][3], float eul1[3], float eul2[3])
mat3_to_quat(quat, tmat);
quat_to_mat3(mat, quat);
copy_m3_m3(mat, tmat);
normalize_m3(mat);
normalize_m3_m3(mat, tmat);
cy = sqrtf(mat[0][0] * mat[0][0] + mat[0][1] * mat[0][1]);
cy = hypotf(mat[0][0], mat[0][1]);
if (cy > 16.0f * FLT_EPSILON) {
eul1[0] = (float)atan2(mat[1][2], mat[2][2]);
eul1[1] = (float)atan2(-mat[0][2], cy);
eul1[2] = (float)atan2(mat[0][1], mat[0][0]);
eul1[0] = atan2f(mat[1][2], mat[2][2]);
eul1[1] = atan2f(-mat[0][2], cy);
eul1[2] = atan2f(mat[0][1], mat[0][0]);
eul2[0] = (float)atan2(-mat[1][2], -mat[2][2]);
eul2[1] = (float)atan2(-mat[0][2], -cy);
eul2[2] = (float)atan2(-mat[0][1], -mat[0][0]);
eul2[0] = atan2f(-mat[1][2], -mat[2][2]);
eul2[1] = atan2f(-mat[0][2], -cy);
eul2[2] = atan2f(-mat[0][1], -mat[0][0]);
}
else {
eul1[0] = (float)atan2(-mat[2][1], mat[1][1]);
eul1[1] = (float)atan2(-mat[0][2], cy);
eul1[0] = atan2f(-mat[2][1], mat[1][1]);
eul1[1] = atan2f(-mat[0][2], cy);
eul1[2] = 0.0f;
copy_v3_v3(eul2, eul1);
@ -1380,44 +1379,38 @@ void eulO_to_mat3(float M[3][3], const float e[3], const short order)
}
/* returns two euler calculation methods, so we can pick the best */
static void mat3_to_eulo2(float M[3][3], float e1[3], float e2[3], const short order)
static void mat3_to_eulo2(float M[3][3], float eul1[3], float eul2[3], const short order)
{
const RotOrderInfo *R = GET_ROTATIONORDER_INFO(order);
short i = R->axis[0], j = R->axis[1], k = R->axis[2];
float m[3][3];
double cy;
float mat[3][3];
float cy;
/* process the matrix first */
copy_m3_m3(m, M);
normalize_m3(m);
normalize_m3_m3(mat, M);
cy = sqrt(m[i][i] * m[i][i] + m[i][j] * m[i][j]);
cy = hypotf(mat[i][i], mat[i][j]);
if (cy > 16.0 * (double)FLT_EPSILON) {
e1[i] = atan2f(m[j][k], m[k][k]);
e1[j] = atan2f(-m[i][k], (float)cy);
e1[k] = atan2f(m[i][j], m[i][i]);
if (cy > 16.0f * FLT_EPSILON) {
eul1[i] = atan2f(mat[j][k], mat[k][k]);
eul1[j] = atan2f(-mat[i][k], cy);
eul1[k] = atan2f(mat[i][j], mat[i][i]);
e2[i] = atan2f(-m[j][k], -m[k][k]);
e2[j] = atan2f(-m[i][k], (float)-cy);
e2[k] = atan2f(-m[i][j], -m[i][i]);
eul2[i] = atan2f(-mat[j][k], -mat[k][k]);
eul2[j] = atan2f(-mat[i][k], -cy);
eul2[k] = atan2f(-mat[i][j], -mat[i][i]);
}
else {
e1[i] = atan2f(-m[k][j], m[j][j]);
e1[j] = atan2f(-m[i][k], (float)cy);
e1[k] = 0;
eul1[i] = atan2f(-mat[k][j], mat[j][j]);
eul1[j] = atan2f(-mat[i][k], cy);
eul1[k] = 0;
copy_v3_v3(e2, e1);
copy_v3_v3(eul2, eul1);
}
if (R->parity) {
e1[0] = -e1[0];
e1[1] = -e1[1];
e1[2] = -e1[2];
e2[0] = -e2[0];
e2[1] = -e2[1];
e2[2] = -e2[2];
negate_v3(eul1);
negate_v3(eul2);
}
}