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>2010-10-22 07:56:50 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-10-22 07:56:50 +0400
commit2fe940f8df9c4513ad1ad0674f49818417450984 (patch)
tree973e55b1f0ea46b3018c0993efeaa3b22f1173dc /source/blender/blenlib/intern/math_rotation.c
parentbcac1def4c1b459e116ae1957e8ac4e20a7d9192 (diff)
Fix for snapping pose bones with axis-angle rotation.
- armature_mat_pose_to_bone() was missing axis-angle check. - added loc_axisangle_size_to_mat4() for completeness. - use 'const' prefix where possible in math rotation functions.
Diffstat (limited to 'source/blender/blenlib/intern/math_rotation.c')
-rw-r--r--source/blender/blenlib/intern/math_rotation.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 09cb02ce56a..7f615462ab0 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -88,7 +88,7 @@ void conjugate_qt(float *q)
q[3] = -q[3];
}
-float dot_qtqt(float *q1, float *q2)
+float dot_qtqt(const float q1[4], const float q2[4])
{
return q1[0]*q2[0] + q1[1]*q2[1] + q1[2]*q2[2] + q1[3]*q2[3];
}
@@ -119,11 +119,10 @@ void mul_qt_fl(float *q, const float f)
q[3] *= f;
}
-void sub_qt_qtqt(float *q, float *q1, float *q2)
+void sub_qt_qtqt(float q[4], const float q1[4], const float q2[4])
{
- q2[0]= -q2[0];
- mul_qt_qtqt(q, q1, q2);
- q2[0]= -q2[0];
+ const float nq2[4]= {-q2[0], q2[1], q2[2], q2[3]};
+ mul_qt_qtqt(q, q1, nq2);
}
/* angular mult factor */
@@ -138,7 +137,7 @@ void mul_fac_qt_fl(float *q, const float fac)
mul_v3_fl(q+1, si);
}
-void quat_to_mat3(float m[][3], float *q)
+void quat_to_mat3(float m[][3], const float q[4])
{
double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc;
@@ -170,7 +169,7 @@ void quat_to_mat3(float m[][3], float *q)
m[2][2]= (float)(1.0-qaa-qbb);
}
-void quat_to_mat4(float m[][4], float *q)
+void quat_to_mat4(float m[][4], const float q[4])
{
double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc;
@@ -356,7 +355,7 @@ void rotation_between_quats_to_quat(float *q, const float q1[4], const float q2[
}
-void vec_to_quat(float *q,float *vec, short axis, short upflag)
+void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
{
float q2[4], nor[3], *fp, mat[3][3], angle, si, co, x2, y2, z2, len1;
@@ -491,7 +490,7 @@ void QuatInterpolW(float *result, float *quat1, float *quat2, float t)
}
#endif
-void interp_qt_qtqt(float *result, float *quat1, float *quat2, float t)
+void interp_qt_qtqt(float result[4], const float quat1[4], const float quat2[4], const float t)
{
float quat[4], omega, cosom, sinom, sc1, sc2;
@@ -528,7 +527,7 @@ void interp_qt_qtqt(float *result, float *quat1, float *quat2, float t)
result[3] = sc1 * quat[3] + sc2 * quat2[3];
}
-void add_qt_qtqt(float *result, float *quat1, float *quat2, float t)
+void add_qt_qtqt(float result[4], const float quat1[4], const float quat2[4], const float t)
{
result[0]= quat1[0] + t*quat2[0];
result[1]= quat1[1] + t*quat2[1];
@@ -536,7 +535,7 @@ void add_qt_qtqt(float *result, float *quat1, float *quat2, float t)
result[3]= quat1[3] + t*quat2[3];
}
-void tri_to_quat(float *quat, float *v1, float *v2, float *v3)
+void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const float v3[3])
{
/* imaginary x-axis, y-axis triangle is being rotated */
float vec[3], q1[4], q2[4], n[3], si, co, angle, mat[3][3], imat[3][3];
@@ -588,7 +587,7 @@ void print_qt(char *str, float q[4])
/******************************** Axis Angle *********************************/
/* Axis angle to Quaternions */
-void axis_angle_to_quat(float q[4], float axis[3], float angle)
+void axis_angle_to_quat(float q[4], const float axis[3], float angle)
{
float nor[3];
float si;
@@ -604,7 +603,7 @@ void axis_angle_to_quat(float q[4], float axis[3], float angle)
}
/* Quaternions to Axis Angle */
-void quat_to_axis_angle(float axis[3], float *angle,float q[4])
+void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
{
float ha, si;
@@ -625,7 +624,7 @@ void quat_to_axis_angle(float axis[3], float *angle,float q[4])
}
/* Axis Angle to Euler Rotation */
-void axis_angle_to_eulO(float eul[3], short order,float axis[3], float angle)
+void axis_angle_to_eulO(float eul[3], short order, const float axis[3], const float angle)
{
float q[4];
@@ -635,7 +634,7 @@ void axis_angle_to_eulO(float eul[3], short order,float axis[3], float angle)
}
/* Euler Rotation to Axis Angle */
-void eulO_to_axis_angle(float axis[3], float *angle,float eul[3], short order)
+void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], const short order)
{
float q[4];
@@ -645,7 +644,7 @@ void eulO_to_axis_angle(float axis[3], float *angle,float eul[3], short order)
}
/* axis angle to 3x3 matrix - safer version (normalisation of axis performed) */
-void axis_angle_to_mat3(float mat[3][3],float axis[3], float angle)
+void axis_angle_to_mat3(float mat[3][3], const float axis[3], const float angle)
{
float nor[3], nsi[3], co, si, ico;
@@ -673,7 +672,7 @@ void axis_angle_to_mat3(float mat[3][3],float axis[3], float angle)
}
/* axis angle to 4x4 matrix - safer version (normalisation of axis performed) */
-void axis_angle_to_mat4(float mat[4][4],float axis[3], float angle)
+void axis_angle_to_mat4(float mat[4][4], const float axis[3], const float angle)
{
float tmat[3][3];
@@ -730,7 +729,7 @@ void mat4_to_vec_rot(float axis[3], float *angle,float mat[4][4])
}
/* axis angle to 3x3 matrix */
-void vec_rot_to_mat3(float mat[][3],float *vec, float phi)
+void vec_rot_to_mat3(float mat[][3], const float vec[3], const float phi)
{
/* rotation of phi radials around vec */
float vx, vx2, vy, vy2, vz, vz2, co, si;
@@ -756,7 +755,7 @@ void vec_rot_to_mat3(float mat[][3],float *vec, float phi)
}
/* axis angle to 4x4 matrix */
-void vec_rot_to_mat4(float mat[][4],float *vec, float phi)
+void vec_rot_to_mat4(float mat[][4], const float vec[3], const float phi)
{
float tmat[3][3];
@@ -766,7 +765,7 @@ void vec_rot_to_mat4(float mat[][4],float *vec, float phi)
}
/* axis angle to quaternion */
-void vec_rot_to_quat(float *quat,float *vec, float phi)
+void vec_rot_to_quat(float *quat, const float vec[3], const float phi)
{
/* rotation of phi radials around vec */
float si;
@@ -790,7 +789,7 @@ void vec_rot_to_quat(float *quat,float *vec, float phi)
/******************************** XYZ Eulers *********************************/
/* XYZ order */
-void eul_to_mat3(float mat[][3], float *eul)
+void eul_to_mat3(float mat[][3], const float eul[3])
{
double ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
@@ -818,7 +817,7 @@ void eul_to_mat3(float mat[][3], float *eul)
}
/* XYZ order */
-void eul_to_mat4(float mat[][4], float *eul)
+void eul_to_mat4(float mat[][4], const float eul[3])
{
double ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
@@ -850,7 +849,7 @@ void eul_to_mat4(float mat[][4], float *eul)
/* returns two euler calculation methods, so we can pick the best */
/* XYZ order */
-static void mat3_to_eul2(float tmat[][3], float *eul1, float *eul2)
+static void mat3_to_eul2(float tmat[][3], float eul1[3], float eul2[3])
{
float cy, quat[4], mat[3][3];
@@ -907,7 +906,7 @@ void mat4_to_eul(float *eul,float tmat[][4])
}
/* XYZ order */
-void quat_to_eul(float *eul,float *quat)
+void quat_to_eul(float *eul, const float quat[4])
{
float mat[3][3];
@@ -916,7 +915,7 @@ void quat_to_eul(float *eul,float *quat)
}
/* XYZ order */
-void eul_to_quat(float *quat,float *eul)
+void eul_to_quat(float *quat, const float eul[3])
{
float ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
@@ -932,7 +931,7 @@ void eul_to_quat(float *quat,float *eul)
}
/* XYZ order */
-void rotate_eul(float *beul, char axis, float ang)
+void rotate_eul(float *beul, const char axis, const float ang)
{
float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];
@@ -952,7 +951,7 @@ void rotate_eul(float *beul, char axis, float ang)
/* exported to transform.c */
/* order independent! */
-void compatible_eul(float *eul, float *oldrot)
+void compatible_eul(float eul[3], const float oldrot[3])
{
float dx, dy, dz;
@@ -1016,7 +1015,7 @@ void compatible_eul(float *eul, float *oldrot)
/* uses 2 methods to retrieve eulers, and picks the closest */
/* XYZ order */
-void mat3_to_compatible_eul(float *eul, float *oldrot,float mat[][3])
+void mat3_to_compatible_eul(float eul[3], const float oldrot[3], float mat[][3])
{
float eul1[3], eul2[3];
float d1, d2;
@@ -1076,7 +1075,7 @@ static RotOrderInfo rotOrders[]= {
#define GET_ROTATIONORDER_INFO(order) (((order)>=1) ? &rotOrders[(order)-1] : &rotOrders[0])
/* Construct quaternion from Euler angles (in radians). */
-void eulO_to_quat(float q[4],float e[3], short order)
+void eulO_to_quat(float q[4], const float e[3], const short order)
{
RotOrderInfo *R= GET_ROTATIONORDER_INFO(order);
short i=R->axis[0], j=R->axis[1], k=R->axis[2];
@@ -1102,11 +1101,11 @@ void eulO_to_quat(float q[4],float e[3], short order)
q[2] = a[1];
q[3] = a[2];
- if (R->parity) q[j+1] *= -1.0f;
+ if (R->parity) q[j+1] = -q[j+1];
}
/* Convert quaternion to Euler angles (in radians). */
-void quat_to_eulO(float e[3], short order,float q[4])
+void quat_to_eulO(float e[3], short const order, const float q[4])
{
float M[3][3];
@@ -1115,7 +1114,7 @@ void quat_to_eulO(float e[3], short order,float q[4])
}
/* Construct 3x3 matrix from Euler angles (in radians). */
-void eulO_to_mat3(float M[3][3],float e[3], short order)
+void eulO_to_mat3(float M[3][3], const float e[3], const short order)
{
RotOrderInfo *R= GET_ROTATIONORDER_INFO(order);
short i=R->axis[0], j=R->axis[1], k=R->axis[2];
@@ -1140,7 +1139,7 @@ void eulO_to_mat3(float M[3][3],float e[3], short order)
}
/* Construct 4x4 matrix from Euler angles (in radians). */
-void eulO_to_mat4(float M[4][4],float e[3], short order)
+void eulO_to_mat4(float M[4][4], const float e[3], const short order)
{
float m[3][3];
@@ -1281,7 +1280,7 @@ void rotate_eulO(float beul[3], short order, char axis, float ang)
}
/* the matrix is written to as 3 axis vectors */
-void eulO_to_gimbal_axis(float gmat[][3], float *eul, short order)
+void eulO_to_gimbal_axis(float gmat[][3], const float eul[3], const short order)
{
RotOrderInfo *R= GET_ROTATIONORDER_INFO(order);
@@ -1394,7 +1393,7 @@ void mat4_to_dquat(DualQuat *dq,float basemat[][4], float mat[][4])
dq->trans[3]= 0.5f*(t[0]*q[2] - t[1]*q[1] + t[2]*q[0]);
}
-void dquat_to_mat4(float mat[][4],DualQuat *dq)
+void dquat_to_mat4(float mat[][4], DualQuat *dq)
{
float len, *t, q0[4];