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:
Diffstat (limited to 'source/blender/blenlib/intern/math_rotation.c')
-rw-r--r--source/blender/blenlib/intern/math_rotation.c74
1 files changed, 38 insertions, 36 deletions
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 41535cf32b6..536b4d79385 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -27,11 +27,11 @@
* \ingroup bli
*/
-
-
#include <assert.h>
#include "BLI_math.h"
+#include "BLI_strict_flags.h"
+
/******************************** Quaternions ********************************/
/* used to test is a quat is not normalized (only used for debug prints) */
@@ -444,7 +444,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
/* rotate to axis */
if (axis > 2) {
copy_v3_v3(tvec, vec);
- axis -= 3;
+ axis = (short)(axis - 3);
}
else {
negate_v3_v3(tvec, vec);
@@ -1183,10 +1183,10 @@ void eulO_to_quat(float q[4], const float e[3], const short order)
a[j] = cj * ss + sj * cc;
a[k] = cj * cs - sj * sc;
- q[0] = cj * cc + sj * ss;
- q[1] = a[0];
- q[2] = a[1];
- q[3] = a[2];
+ q[0] = (float)(cj * cc + sj * ss);
+ q[1] = (float)(a[0]);
+ q[2] = (float)(a[1]);
+ q[3] = (float)(a[2]);
if (R->parity) q[j + 1] = -q[j + 1];
}
@@ -1230,15 +1230,15 @@ void eulO_to_mat3(float M[3][3], const float e[3], const short order)
sc = si * ch;
ss = si * sh;
- M[i][i] = cj * ch;
- M[j][i] = sj * sc - cs;
- M[k][i] = sj * cc + ss;
- M[i][j] = cj * sh;
- M[j][j] = sj * ss + cc;
- M[k][j] = sj * cs - sc;
- M[i][k] = -sj;
- M[j][k] = cj * si;
- M[k][k] = cj * ci;
+ M[i][i] = (float)(cj * ch);
+ M[j][i] = (float)(sj * sc - cs);
+ M[k][i] = (float)(sj * cc + ss);
+ M[i][j] = (float)(cj * sh);
+ M[j][j] = (float)(sj * ss + cc);
+ M[k][j] = (float)(sj * cs - sc);
+ M[i][k] = (float)(-sj);
+ M[j][k] = (float)(cj * si);
+ M[k][k] = (float)(cj * ci);
}
/* returns two euler calculation methods, so we can pick the best */
@@ -1256,17 +1256,17 @@ static void mat3_to_eulo2(float M[3][3], float e1[3], float e2[3], const short o
cy = sqrt(m[i][i] * m[i][i] + m[i][j] * m[i][j]);
if (cy > 16.0 * (double)FLT_EPSILON) {
- e1[i] = atan2(m[j][k], m[k][k]);
- e1[j] = atan2(-m[i][k], cy);
- e1[k] = atan2(m[i][j], m[i][i]);
+ 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]);
- e2[i] = atan2(-m[j][k], -m[k][k]);
- e2[j] = atan2(-m[i][k], -cy);
- e2[k] = atan2(-m[i][j], -m[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]);
}
else {
- e1[i] = atan2(-m[k][j], m[j][j]);
- e1[j] = atan2(-m[i][k], cy);
+ e1[i] = atan2f(-m[k][j], m[j][j]);
+ e1[j] = atan2f(-m[i][k], (float)cy);
e1[k] = 0;
copy_v3_v3(e2, e1);
@@ -1632,13 +1632,14 @@ void copy_dq_dq(DualQuat *dq1, const DualQuat *dq2)
void quat_apply_track(float quat[4], short axis, short upflag)
{
/* rotations are hard coded to match vec_to_quat */
+ const float sqrt_1_2 = (float)M_SQRT1_2;
const float quat_track[][4] = {
- {M_SQRT1_2, 0.0, -M_SQRT1_2, 0.0}, /* pos-y90 */
+ {sqrt_1_2, 0.0, -sqrt_1_2, 0.0}, /* pos-y90 */
{0.5, 0.5, 0.5, 0.5}, /* Quaternion((1,0,0), radians(90)) * Quaternion((0,1,0), radians(90)) */
- {M_SQRT1_2, 0.0, 0.0, M_SQRT1_2}, /* pos-z90 */
- {M_SQRT1_2, 0.0, M_SQRT1_2, 0.0}, /* neg-y90 */
+ {sqrt_1_2, 0.0, 0.0, sqrt_1_2}, /* pos-z90 */
+ {sqrt_1_2, 0.0, sqrt_1_2, 0.0}, /* neg-y90 */
{0.5, -0.5, -0.5, 0.5}, /* Quaternion((1,0,0), radians(-90)) * Quaternion((0,1,0), radians(-90)) */
- {0.0, M_SQRT1_2, M_SQRT1_2, 0.0} /* no rotation */
+ {0.0, sqrt_1_2, sqrt_1_2, 0.0} /* no rotation */
};
assert(axis >= 0 && axis <= 5);
@@ -1646,15 +1647,16 @@ void quat_apply_track(float quat[4], short axis, short upflag)
mul_qt_qtqt(quat, quat, quat_track[axis]);
- if (axis > 2)
- axis = axis - 3;
+ if (axis > 2) {
+ axis = (short)(axis - 3);
+ }
/* there are 2 possible up-axis for each axis used, the 'quat_track' applies so the first
* up axis is used X->Y, Y->X, Z->X, if this first up axis isn't used then rotate 90d
* the strange bit shift below just find the low axis {X:Y, Y:X, Z:X} */
if (upflag != (2 - axis) >> 1) {
- float q[4] = {M_SQRT1_2, 0.0, 0.0, 0.0}; /* assign 90d rotation axis */
- q[axis + 1] = ((axis == 1)) ? M_SQRT1_2 : -M_SQRT1_2; /* flip non Y axis */
+ float q[4] = {sqrt_1_2, 0.0, 0.0, 0.0}; /* assign 90d rotation axis */
+ q[axis + 1] = ((axis == 1)) ? sqrt_1_2 : -sqrt_1_2; /* flip non Y axis */
mul_qt_qtqt(quat, quat, q);
}
}
@@ -1835,7 +1837,7 @@ static int _axis_convert_lut[23][24] = {
// _axis_convert_num = {'X': 0, 'Y': 1, 'Z': 2, '-X': 3, '-Y': 4, '-Z': 5}
-MINLINE int _axis_signed(const int axis)
+BLI_INLINE int _axis_signed(const int axis)
{
return (axis < 3) ? axis : axis - 3;
}
@@ -1849,7 +1851,7 @@ int mat3_from_axis_conversion(int from_forward, int from_up, int to_forward, int
{
// from functools import reduce
int value;
- int i;
+ unsigned int i;
if (from_forward == to_forward && from_up == to_up) {
unit_m3(r_mat);
@@ -1870,8 +1872,8 @@ int mat3_from_axis_conversion(int from_forward, int from_up, int to_forward, int
(to_up << (3 * 3)));
for (i = 0; i < (sizeof(_axis_convert_matrix) / sizeof(*_axis_convert_matrix)); i++) {
- int j;
- for (j = 0; j < sizeof(*_axis_convert_lut) / sizeof(*_axis_convert_lut[0]); j++) {
+ unsigned int j;
+ for (j = 0; j < (sizeof(*_axis_convert_lut) / sizeof(*_axis_convert_lut[0])); j++) {
if (_axis_convert_lut[i][j] == value) {
copy_m3_m3(r_mat, _axis_convert_matrix[i]);
return true;