Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-06-14 11:10:46 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-06-14 11:10:46 +0400
commit94d4b313231cf0d7d94de1e9eaf21037c4929ee6 (patch)
tree3f6057621150d2e806e7bfa736253cde86e6e776 /source/blender/blenlib/intern/math_rotation.c
parent019a8bc23ba8f748c33a1e563ec782f2ff7d672f (diff)
Math Lib: mat3_to_eulo2 & mat3_to_eul2 mixed float/double differently
replace sqrt with hypotf to avoid precision loss instead
Diffstat (limited to 'source/blender/blenlib/intern/math_rotation.c')
-rw-r--r--source/blender/blenlib/intern/math_rotation.c63
1 files changed, 28 insertions, 35 deletions
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index b971b81fba6..dce2e9d54e3 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -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);
}
}