Transform: snapping: normal-align: Cleanup!
Use BLI's `rotation_between_vecs_to_mat3` helper instead of own custom code, both simplifies the code and fixes wrong handling when snapped normal was exactly opposed to org one (i.e. 180° rot case).
This commit is contained in:
parent
c2dc51d827
commit
d8094b62e2
|
@ -4187,29 +4187,21 @@ static void applyTranslationValue(TransInfo *t, float vec[3])
|
|||
|
||||
if (td->flag & TD_SKIP)
|
||||
continue;
|
||||
|
||||
|
||||
/* handle snapping rotation before doing the translation */
|
||||
if (usingSnappingNormal(t)) {
|
||||
if (validSnappingNormal(t)) {
|
||||
const float *original_normal;
|
||||
float axis[3];
|
||||
float quat[4];
|
||||
float mat[3][3];
|
||||
float angle;
|
||||
|
||||
/* In pose mode, we want to align normals with Y axis of bones... */
|
||||
if (t->flag & T_POSE)
|
||||
original_normal = td->axismtx[1];
|
||||
else
|
||||
original_normal = td->axismtx[2];
|
||||
|
||||
cross_v3_v3v3(axis, original_normal, t->tsnap.snapNormal);
|
||||
angle = saacos(dot_v3v3(original_normal, t->tsnap.snapNormal));
|
||||
|
||||
axis_angle_to_quat(quat, axis, angle);
|
||||
|
||||
quat_to_mat3(mat, quat);
|
||||
|
||||
|
||||
rotation_between_vecs_to_mat3(mat, original_normal, t->tsnap.snapNormal);
|
||||
|
||||
ElementRotation(t, td, mat, V3D_LOCAL);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -341,22 +341,15 @@ void applyProject(TransInfo *t)
|
|||
if (t->tsnap.align && (t->flag & T_OBJECT)) {
|
||||
/* handle alignment as well */
|
||||
const float *original_normal;
|
||||
float axis[3];
|
||||
float mat[3][3];
|
||||
float angle;
|
||||
float totmat[3][3], smat[3][3];
|
||||
float eul[3], fmat[3][3], quat[4];
|
||||
float eul[3], fmat[3][3];
|
||||
float obmat[3][3];
|
||||
|
||||
/* In pose mode, we want to align normals with Y axis of bones... */
|
||||
original_normal = td->axismtx[2];
|
||||
|
||||
cross_v3_v3v3(axis, original_normal, no);
|
||||
angle = saacos(dot_v3v3(original_normal, no));
|
||||
|
||||
axis_angle_to_quat(quat, axis, angle);
|
||||
|
||||
quat_to_mat3(mat, quat);
|
||||
rotation_between_vecs_to_mat3(mat, original_normal, no);
|
||||
|
||||
mul_m3_m3m3(totmat, mat, td->mtx);
|
||||
mul_m3_m3m3(smat, td->smtx, totmat);
|
||||
|
|
Loading…
Reference in New Issue