diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-10-22 07:56:50 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-10-22 07:56:50 +0400 |
commit | 2fe940f8df9c4513ad1ad0674f49818417450984 (patch) | |
tree | 973e55b1f0ea46b3018c0993efeaa3b22f1173dc /source/blender/blenlib | |
parent | bcac1def4c1b459e116ae1957e8ac4e20a7d9192 (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')
-rw-r--r-- | source/blender/blenlib/BLI_math_matrix.h | 12 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_rotation.h | 62 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 17 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 69 |
4 files changed, 84 insertions, 76 deletions
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 6b3d8bf9d0b..e4f477238f5 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -135,8 +135,8 @@ void scale_m4_fl(float R[4][4], float scale); float mat3_to_scale(float M[3][3]); float mat4_to_scale(float M[4][4]); -void size_to_mat3(float R[3][3], float size[3]); -void size_to_mat4(float R[4][4], float size[3]); +void size_to_mat3(float R[3][3], const float size[3]); +void size_to_mat4(float R[4][4], const float size[3]); void mat3_to_size(float r[3], float M[3][3]); void mat4_to_size(float r[3], float M[4][4]); @@ -145,11 +145,13 @@ void translate_m4(float mat[4][4], float tx, float ty, float tz); void rotate_m4(float mat[4][4], char axis, float angle); void loc_eul_size_to_mat4(float R[4][4], - float loc[3], float eul[3], float size[3]); + const float loc[3], const float eul[3], const float size[3]); void loc_eulO_size_to_mat4(float R[4][4], - float loc[3], float eul[3], float size[3], short order); + const float loc[3], const float eul[3], const float size[3], const short order); void loc_quat_size_to_mat4(float R[4][4], - float loc[3], float quat[4], float size[3]); + const float loc[3], const float quat[4], const float size[3]); +void loc_axisangle_size_to_mat4(float R[4][4], + const float loc[3], const float axis[4], const float angle, const float size[3]); void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], float t); void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], float t); diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h index 321fd28a62f..a953a01a8a1 100644 --- a/source/blender/blenlib/BLI_math_rotation.h +++ b/source/blender/blenlib/BLI_math_rotation.h @@ -48,29 +48,29 @@ void mul_qt_v3(const float q[4], float r[3]); void mul_qt_fl(float q[4], const float f); void mul_fac_qt_fl(float q[4], const float f); -void sub_qt_qtqt(float q[4], float a[4], float b[4]); +void sub_qt_qtqt(float q[4], const float a[4], const float b[4]); void invert_qt(float q[4]); void invert_qt_qt(float *q1, const float *q2); void conjugate_qt(float q[4]); -float dot_qtqt(float a[4], float b[4]); +float dot_qtqt(const float a[4], const float b[4]); void normalize_qt(float q[4]); /* comparison */ int is_zero_qt(float q[4]); /* interpolation */ -void interp_qt_qtqt(float q[4], float a[4], float b[4], float t); -void add_qt_qtqt(float q[4], float a[4], float b[4], float t); +void interp_qt_qtqt(float q[4], const float a[4], const float b[4], const float t); +void add_qt_qtqt(float q[4], const float a[4], const float b[4], const float t); /* conversion */ -void quat_to_mat3(float mat[3][3], float q[4]); -void quat_to_mat4(float mat[4][4], float q[4]); +void quat_to_mat3(float mat[3][3], const float q[4]); +void quat_to_mat4(float mat[4][4], const float q[4]); void mat3_to_quat(float q[4], float mat[3][3]); void mat4_to_quat(float q[4], float mat[4][4]); -void tri_to_quat(float q[4], float a[3], float b[3], float c[3]); -void vec_to_quat(float q[4], float vec[3], short axis, short upflag); +void tri_to_quat(float q[4], const float a[3], const float b[3], const float c[3]); +void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag); /* note: v1 and v2 must be normalized */ void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3]); void rotation_between_quats_to_quat(float q[4], const float q1[4], const float q2[4]); @@ -84,11 +84,11 @@ void print_qt(char *str, float q[4]); /******************************** Axis Angle *********************************/ /* conversion */ -void axis_angle_to_quat(float r[4], float axis[3], float angle); -void axis_angle_to_mat3(float R[3][3], float axis[3], float angle); -void axis_angle_to_mat4(float R[4][4], float axis[3], float angle); +void axis_angle_to_quat(float r[4], const float axis[3], float angle); +void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle); +void axis_angle_to_mat4(float R[4][4], const float axis[3], const float 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]); void mat3_to_axis_angle(float axis[3], float *angle, float M[3][3]); void mat4_to_axis_angle(float axis[3], float *angle, float M[4][4]); @@ -100,24 +100,24 @@ void mat4_to_axis_angle(float axis[3], float *angle, float M[4][4]); void mat3_to_vec_rot(float vec[3], float *phi, float mat[3][3]); void mat4_to_vec_rot(float vec[3], float *phi, float mat[4][4]); -void vec_rot_to_quat(float quat[4], float vec[3], float phi); -void vec_rot_to_mat3(float mat[3][3], float vec[3], float phi); -void vec_rot_to_mat4(float mat[4][4], float vec[3], float phi); +void vec_rot_to_quat(float quat[4], const float vec[3], const float phi); +void vec_rot_to_mat3(float mat[3][3], const float vec[3], const float phi); +void vec_rot_to_mat4(float mat[4][4], const float vec[3], const float phi); /******************************** XYZ Eulers *********************************/ -void eul_to_quat(float quat[4], float eul[3]); -void eul_to_mat3(float mat[3][3], float eul[3]); -void eul_to_mat4(float mat[4][4], float eul[3]); +void eul_to_quat(float quat[4], const float eul[3]); +void eul_to_mat3(float mat[3][3], const float eul[3]); +void eul_to_mat4(float mat[4][4], const float eul[3]); -void quat_to_eul(float eul[3], float quat[4]); +void quat_to_eul(float eul[3], const float quat[4]); void mat3_to_eul(float eul[3], float mat[3][3]); void mat4_to_eul(float eul[3], float mat[4][4]); -void compatible_eul(float eul[3], float old[3]); -void mat3_to_compatible_eul(float eul[3], float old[3], float mat[3][3]); +void compatible_eul(float eul[3], const float old[3]); +void mat3_to_compatible_eul(float eul[3], const float old[3], float mat[3][3]); -void rotate_eul(float eul[3], char axis, float angle); +void rotate_eul(float eul[3], const char axis, const float angle); /************************** Arbitrary Order Eulers ***************************/ @@ -135,16 +135,16 @@ typedef enum eEulerRotationOrders { /* there are 6 more entries with dulpicate entries included */ } eEulerRotationOrders; -void eulO_to_quat(float quat[4], float eul[3], short order); -void eulO_to_mat3(float mat[3][3], float eul[3], short order); -void eulO_to_mat4(float mat[4][4], float eul[3], short order); -void eulO_to_axis_angle(float axis[3], float *angle, float eul[3], short order); -void eulO_to_gimbal_axis(float gmat[3][3], float eul[3], short order); +void eulO_to_quat(float quat[4], const float eul[3], const short order); +void eulO_to_mat3(float mat[3][3], const float eul[3], const short order); +void eulO_to_mat4(float mat[4][4], const float eul[3], const short order); +void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], const short order); +void eulO_to_gimbal_axis(float gmat[3][3], const float eul[3], const short order); -void quat_to_eulO(float eul[3], short order, float quat[4]); -void mat3_to_eulO(float eul[3], short order, float mat[3][3]); -void mat4_to_eulO(float eul[3], short order, float mat[4][4]); -void axis_angle_to_eulO(float eul[3], short order, float axis[3], float angle); +void quat_to_eulO(float eul[3], const short order, const float quat[4]); +void mat3_to_eulO(float eul[3], const short order, float mat[3][3]); +void mat4_to_eulO(float eul[3], const short order, float mat[4][4]); +void axis_angle_to_eulO(float eul[3], const short order, const float axis[3], const float angle); void mat3_to_compatible_eulO(float eul[3], float old[3], short order, float mat[3][3]); void mat4_to_compatible_eulO(float eul[3], float old[3], short order, float mat[4][4]); diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 9bbd0fc64ac..86eee4c2202 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -898,7 +898,7 @@ float determinant_m4(float m[][4]) /****************************** Transformations ******************************/ -void size_to_mat3(float mat[][3], float *size) +void size_to_mat3(float mat[][3], const float size[3]) { mat[0][0]= size[0]; mat[0][1]= 0.0f; @@ -911,7 +911,7 @@ void size_to_mat3(float mat[][3], float *size) mat[2][0]= 0.0f; } -void size_to_mat4(float mat[][4], float *size) +void size_to_mat4(float mat[][4], const float size[3]) { float tmat[3][3]; @@ -1078,7 +1078,7 @@ int is_negative_m4(float mat[][4]) /* make a 4x4 matrix out of 3 transform components */ /* matrices are made in the order: scale * rot * loc */ // TODO: need to have a version that allows for rotation order... -void loc_eul_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float size[3]) +void loc_eul_size_to_mat4(float mat[4][4], const float loc[3], const float eul[3], const float size[3]) { float rmat[3][3], smat[3][3], tmat[3][3]; @@ -1101,7 +1101,7 @@ void loc_eul_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float siz /* make a 4x4 matrix out of 3 transform components */ /* matrices are made in the order: scale * rot * loc */ -void loc_eulO_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float size[3], short rotOrder) +void loc_eulO_size_to_mat4(float mat[4][4], const float loc[3], const float eul[3], const float size[3], const short rotOrder) { float rmat[3][3], smat[3][3], tmat[3][3]; @@ -1125,7 +1125,7 @@ void loc_eulO_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float si /* make a 4x4 matrix out of 3 transform components */ /* matrices are made in the order: scale * rot * loc */ -void loc_quat_size_to_mat4(float mat[4][4], float loc[3], float quat[4], float size[3]) +void loc_quat_size_to_mat4(float mat[4][4], const float loc[3], const float quat[4], const float size[3]) { float rmat[3][3], smat[3][3], tmat[3][3]; @@ -1146,6 +1146,13 @@ void loc_quat_size_to_mat4(float mat[4][4], float loc[3], float quat[4], float s mat[3][2] = loc[2]; } +void loc_axisangle_size_to_mat4(float mat[4][4], const float loc[3], const float axis[3], const float angle, const float size[3]) +{ + float q[4]; + axis_angle_to_quat(q, axis, angle); + loc_quat_size_to_mat4(mat, loc, q, size); +} + /*********************************** Other ***********************************/ void print_m3(char *str, float m[][3]) 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]; |