X-Git-Url: https://git.blender.org/gitweb/gitweb.cgi/blender-staging.git/blobdiff_plain/f399481251a4d375a494517925c64b3b3c6db7e8..757f75b76889e7864027f8d996083c54aeb306e6:/source/blender/blenlib/intern/math_rotation.c diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index ad6ce5c4448..a825935045f 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -36,7 +36,7 @@ void unit_qt(float *q) q[1]= q[2]= q[3]= 0.0f; } -void copy_qt_qt(float *q1, float *q2) +void copy_qt_qt(float *q1, const float *q2) { q1[0]= q2[0]; q1[1]= q2[1]; @@ -49,7 +49,7 @@ int is_zero_qt(float *q) return (q[0] == 0 && q[1] == 0 && q[2] == 0 && q[3] == 0); } -void mul_qt_qtqt(float *q, float *q1, float *q2) +void mul_qt_qtqt(float *q, const float *q1, const float *q2) { float t0,t1,t2; @@ -63,7 +63,7 @@ void mul_qt_qtqt(float *q, float *q1, float *q2) } /* Assumes a unit quaternion */ -void mul_qt_v3(float *q, float *v) +void mul_qt_v3(const float *q, float *v) { float t0, t1, t2; @@ -104,8 +104,14 @@ void invert_qt(float *q) mul_qt_fl(q, 1.0f/f); } +void invert_qt_qt(float *q1, const float *q2) +{ + copy_qt_qt(q1, q2); + invert_qt(q1); +} + /* simple mult */ -void mul_qt_fl(float *q, float f) +void mul_qt_fl(float *q, const float f) { q[0] *= f; q[1] *= f; @@ -121,7 +127,7 @@ void sub_qt_qtqt(float *q, float *q1, float *q2) } /* angular mult factor */ -void mul_fac_qt_fl(float *q, float fac) +void mul_fac_qt_fl(float *q, const float fac) { float angle= fac*saacos(q[0]); /* quat[0]= cos(0.5*angle), but now the 0.5 and 2.0 rule out */ @@ -334,6 +340,23 @@ void rotation_between_vecs_to_quat(float *q, const float v1[3], const float v2[3 axis_angle_to_quat(q, axis, angle); } +void rotation_between_quats_to_quat(float *q, const float q1[4], const float q2[4]) +{ + float tquat[4]; + double dot = 0.0f; + int x; + + copy_qt_qt(tquat, q1); + conjugate_qt(tquat); + dot = 1.0f / dot_qtqt(tquat, tquat); + + for(x = 0; x < 4; x++) + tquat[x] *= dot; + + mul_qt_qtqt(q, tquat, q2); +} + + void vec_to_quat(float *q,float *vec, short axis, short upflag) { float q2[4], nor[3], *fp, mat[3][3], angle, si, co, x2, y2, z2, len1;