From c79e054538074d5149296994214397641124d76e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 8 Oct 2010 07:36:33 +0000 Subject: quat_apply_track had incomplete comments --- source/blender/blenlib/intern/math_rotation.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to '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 c4f12a5efc1..3b58fe88bf5 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -1539,21 +1539,24 @@ void quat_apply_track(float quat[4], short axis, short upflag) {0.70710676908493, 0.0, 0.0, 0.70710676908493}, /* pos-z90 */ {0.70710676908493, 0.0, 0.70710676908493, 0.0}, /* neg-y90 */ {0.5, -0.5, -0.5, 0.5}, /* Quaternion((1,0,0), radians(-90)) * Quaternion((0,1,0), radians(-90)) */ - {1, 0, 0, 0}};/* no rotation */ + {-3.0908619663705394e-08, 0.70710676908493, 0.70710676908493, 3.0908619663705394e-08}}; /* no rotation */ mul_qt_qtqt(quat, quat, quat_track[axis]); if(axis>2) axis= axis-3; - /* 90d rotation when the second */ - if(upflag != (2-axis)>>1) { // [0->1, 1->0, 2->0] - float q[4]= {0.70710676908493, 0, 0, 0}; + /* 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 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]= {0.70710676908493, 0.0, 0.0, 0.0}; /* assign 90d rotation axis */ q[axis+1] = ((axis==1)) ? 0.70710676908493 : -0.70710676908493; /* flip non Y axis */ mul_qt_qtqt(quat, quat, q); } } + void vec_apply_track(float vec[3], short axis) { float tvec[3]; @@ -1572,14 +1575,14 @@ void vec_apply_track(float vec[3], short axis) /* vec[2]= tvec[2]; */ break; case 2: /* pos-z */ - vec[0]= tvec[1]; - vec[1]= -tvec[0]; + /* vec[0]= tvec[0]; */ + /* vec[1]= tvec[1]; */ // vec[2]= 0.0; */ break; case 3: /* neg-x */ /* vec[0]= 0.0; */ - vec[1]= -tvec[1]; - vec[2]= -tvec[2]; + vec[1]= tvec[2]; + vec[2]= -tvec[1]; break; case 4: /* neg-y */ vec[0]= -tvec[2]; -- cgit v1.2.3