diff options
Diffstat (limited to 'source/blender/blenlib/intern/math_rotation.c')
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index b8cef511293..3b58fe88bf5 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -1530,6 +1530,73 @@ void copy_dq_dq(DualQuat *dq1, DualQuat *dq2) memcpy(dq1, dq2, sizeof(DualQuat)); } +/* axis matches eTrackToAxis_Modes */ +void quat_apply_track(float quat[4], short axis, short upflag) +{ + /* rotations are hard coded to match vec_to_quat */ + const float quat_track[][4]= {{0.70710676908493, 0.0, -0.70710676908493, 0.0}, /* pos-y90 */ + {0.5, 0.5, 0.5, 0.5}, /* Quaternion((1,0,0), radians(90)) * Quaternion((0,1,0), radians(90)) */ + {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)) */ + {-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; + + /* 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]; + + copy_v3_v3(tvec, vec); + + switch(axis) { + case 0: /* pos-x */ + /* vec[0]= 0.0; */ + vec[1]= tvec[2]; + vec[2]= -tvec[1]; + break; + case 1: /* pos-y */ + /* vec[0]= tvec[0]; */ + /* vec[1]= 0.0; */ + /* vec[2]= tvec[2]; */ + break; + case 2: /* pos-z */ + /* vec[0]= tvec[0]; */ + /* vec[1]= tvec[1]; */ + // vec[2]= 0.0; */ + break; + case 3: /* neg-x */ + /* vec[0]= 0.0; */ + vec[1]= tvec[2]; + vec[2]= -tvec[1]; + break; + case 4: /* neg-y */ + vec[0]= -tvec[2]; + /* vec[1]= 0.0; */ + vec[2]= tvec[0]; + break; + case 5: /* neg-z */ + vec[0]= -tvec[0]; + vec[1]= -tvec[1]; + /* vec[2]= 0.0; */ + break; + } +} + /* lense/angle conversion (radians) */ float lens_to_angle(float lens) { |