forked from bartvdbraak/blender
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:
parent
019a8bc23b
commit
94d4b31323
@ -1088,25 +1088,24 @@ static void mat3_to_eul2(float tmat[3][3], float eul1[3], float eul2[3])
|
|||||||
|
|
||||||
mat3_to_quat(quat, tmat);
|
mat3_to_quat(quat, tmat);
|
||||||
quat_to_mat3(mat, quat);
|
quat_to_mat3(mat, quat);
|
||||||
copy_m3_m3(mat, tmat);
|
normalize_m3_m3(mat, tmat);
|
||||||
normalize_m3(mat);
|
|
||||||
|
|
||||||
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) {
|
if (cy > 16.0f * FLT_EPSILON) {
|
||||||
|
|
||||||
eul1[0] = (float)atan2(mat[1][2], mat[2][2]);
|
eul1[0] = atan2f(mat[1][2], mat[2][2]);
|
||||||
eul1[1] = (float)atan2(-mat[0][2], cy);
|
eul1[1] = atan2f(-mat[0][2], cy);
|
||||||
eul1[2] = (float)atan2(mat[0][1], mat[0][0]);
|
eul1[2] = atan2f(mat[0][1], mat[0][0]);
|
||||||
|
|
||||||
eul2[0] = (float)atan2(-mat[1][2], -mat[2][2]);
|
eul2[0] = atan2f(-mat[1][2], -mat[2][2]);
|
||||||
eul2[1] = (float)atan2(-mat[0][2], -cy);
|
eul2[1] = atan2f(-mat[0][2], -cy);
|
||||||
eul2[2] = (float)atan2(-mat[0][1], -mat[0][0]);
|
eul2[2] = atan2f(-mat[0][1], -mat[0][0]);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
eul1[0] = (float)atan2(-mat[2][1], mat[1][1]);
|
eul1[0] = atan2f(-mat[2][1], mat[1][1]);
|
||||||
eul1[1] = (float)atan2(-mat[0][2], cy);
|
eul1[1] = atan2f(-mat[0][2], cy);
|
||||||
eul1[2] = 0.0f;
|
eul1[2] = 0.0f;
|
||||||
|
|
||||||
copy_v3_v3(eul2, eul1);
|
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 */
|
/* 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);
|
const RotOrderInfo *R = GET_ROTATIONORDER_INFO(order);
|
||||||
short i = R->axis[0], j = R->axis[1], k = R->axis[2];
|
short i = R->axis[0], j = R->axis[1], k = R->axis[2];
|
||||||
float m[3][3];
|
float mat[3][3];
|
||||||
double cy;
|
float cy;
|
||||||
|
|
||||||
/* process the matrix first */
|
/* process the matrix first */
|
||||||
copy_m3_m3(m, M);
|
normalize_m3_m3(mat, M);
|
||||||
normalize_m3(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) {
|
if (cy > 16.0f * FLT_EPSILON) {
|
||||||
e1[i] = atan2f(m[j][k], m[k][k]);
|
eul1[i] = atan2f(mat[j][k], mat[k][k]);
|
||||||
e1[j] = atan2f(-m[i][k], (float)cy);
|
eul1[j] = atan2f(-mat[i][k], cy);
|
||||||
e1[k] = atan2f(m[i][j], m[i][i]);
|
eul1[k] = atan2f(mat[i][j], mat[i][i]);
|
||||||
|
|
||||||
e2[i] = atan2f(-m[j][k], -m[k][k]);
|
eul2[i] = atan2f(-mat[j][k], -mat[k][k]);
|
||||||
e2[j] = atan2f(-m[i][k], (float)-cy);
|
eul2[j] = atan2f(-mat[i][k], -cy);
|
||||||
e2[k] = atan2f(-m[i][j], -m[i][i]);
|
eul2[k] = atan2f(-mat[i][j], -mat[i][i]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
e1[i] = atan2f(-m[k][j], m[j][j]);
|
eul1[i] = atan2f(-mat[k][j], mat[j][j]);
|
||||||
e1[j] = atan2f(-m[i][k], (float)cy);
|
eul1[j] = atan2f(-mat[i][k], cy);
|
||||||
e1[k] = 0;
|
eul1[k] = 0;
|
||||||
|
|
||||||
copy_v3_v3(e2, e1);
|
copy_v3_v3(eul2, eul1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R->parity) {
|
if (R->parity) {
|
||||||
e1[0] = -e1[0];
|
negate_v3(eul1);
|
||||||
e1[1] = -e1[1];
|
negate_v3(eul2);
|
||||||
e1[2] = -e1[2];
|
|
||||||
|
|
||||||
e2[0] = -e2[0];
|
|
||||||
e2[1] = -e2[1];
|
|
||||||
e2[2] = -e2[2];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user