Math lib: add axis_angle_normalized_to_quat, use when length is known
This commit is contained in:
parent
a9e7c7b848
commit
5fce3457b7
|
@ -95,6 +95,7 @@ void print_qt(const char *str, const float q[4]);
|
|||
/******************************** Axis Angle *********************************/
|
||||
|
||||
/* conversion */
|
||||
void axis_angle_normalized_to_quat(float r[4], const float axis[3], const float angle);
|
||||
void axis_angle_to_quat(float r[4], const float axis[3], const float angle);
|
||||
void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle);
|
||||
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], const float angle);
|
||||
|
|
|
@ -677,19 +677,22 @@ void print_qt(const char *str, const float q[4])
|
|||
|
||||
/******************************** Axis Angle *********************************/
|
||||
|
||||
/* Axis angle to Quaternions */
|
||||
void axis_angle_normalized_to_quat(float q[4], const float axis[3], const float angle)
|
||||
{
|
||||
const float phi = 0.5f * angle;
|
||||
const float si = sinf(phi);
|
||||
const float co = cosf(phi);
|
||||
BLI_ASSERT_UNIT_V3(axis);
|
||||
q[0] = co;
|
||||
mul_v3_v3fl(q + 1, axis, si);
|
||||
}
|
||||
|
||||
void axis_angle_to_quat(float q[4], const float axis[3], const float angle)
|
||||
{
|
||||
float nor[3];
|
||||
|
||||
if (LIKELY(normalize_v3_v3(nor, axis) != 0.0f)) {
|
||||
const float phi = angle / 2.0f;
|
||||
float si;
|
||||
si = sinf(phi);
|
||||
q[0] = cosf(phi);
|
||||
q[1] = nor[0] * si;
|
||||
q[2] = nor[1] * si;
|
||||
q[3] = nor[2] * si;
|
||||
axis_angle_normalized_to_quat(q, nor, angle);
|
||||
}
|
||||
else {
|
||||
unit_qt(q);
|
||||
|
|
|
@ -834,7 +834,7 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y)
|
|||
}
|
||||
|
||||
/* Perform the orbital rotation */
|
||||
axis_angle_to_quat(q1, zvec_global, sensitivity * vod->reverse * (x - vod->oldx));
|
||||
axis_angle_normalized_to_quat(q1, zvec_global, sensitivity * vod->reverse * (x - vod->oldx));
|
||||
mul_qt_qtqt(vod->viewquat, vod->viewquat, q1);
|
||||
|
||||
if (vod->use_dyn_ofs) {
|
||||
|
@ -3562,7 +3562,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
|
|||
}
|
||||
|
||||
/* z-axis */
|
||||
axis_angle_to_quat(quat_mul, zvec, angle);
|
||||
axis_angle_normalized_to_quat(quat_mul, zvec, angle);
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -3615,7 +3615,7 @@ static void view_roll_angle(ARegion *ar, float quat[4], const float orig_quat[4]
|
|||
float quat_mul[4];
|
||||
|
||||
/* camera axis */
|
||||
axis_angle_to_quat(quat_mul, dvec, angle);
|
||||
axis_angle_normalized_to_quat(quat_mul, dvec, angle);
|
||||
|
||||
mul_qt_qtqt(quat, orig_quat, quat_mul);
|
||||
rv3d->view = RV3D_VIEW_USER;
|
||||
|
|
|
@ -973,7 +973,7 @@ static int walkApply(bContext *C, WalkInfo *walk)
|
|||
copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
/* Rotate about the relative up vec */
|
||||
axis_angle_to_quat(tmp_quat, upvec, x);
|
||||
axis_angle_normalized_to_quat(tmp_quat, upvec, x);
|
||||
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ static void stats_editbone(RegionView3D *rv3d, EditBone *ebo)
|
|||
}
|
||||
|
||||
/* could move into BLI_math however this is only useful for display/editing purposes */
|
||||
static void axis_angle_to_gimbal_axis(float gmat[3][3], float axis[3], float angle)
|
||||
static void axis_angle_to_gimbal_axis(float gmat[3][3], const float axis[3], const float angle)
|
||||
{
|
||||
/* X/Y are arbitrary axies, most importantly Z is the axis of rotation */
|
||||
|
||||
|
|
Loading…
Reference in New Issue