Fix T42444: Neg scale rotated object flips 2x axis

This is a very old bug and a few attempts have been made to fix it before,
Old code was checking worldspace axis flipping, instead of axis flipping WRT the axis-alignment of the object.
This commit is contained in:
Campbell Barton 2014-10-30 10:15:43 +01:00
parent 3ea11c1ac8
commit 88cc1a786b
Notes: blender-bot 2024-01-16 18:05:25 +01:00
Referenced by issue #44592, Object scale constrained to axis affects all axii
Referenced by issue #42834, Scaling in global axis does not work correctly if the object has rotation
Referenced by issue #42444, Negative scale objects with rotation flips 2x axis.
1 changed files with 13 additions and 28 deletions

View File

@ -3159,37 +3159,22 @@ static void headerResize(TransInfo *t, float vec[3], char str[MAX_INFO_LEN])
}
}
/* FLT_EPSILON is too small [#29633], 0.0000001f starts to flip */
#define TX_FLIP_EPS 0.00001f
BLI_INLINE int tx_sign(const float a)
{
return (a < -TX_FLIP_EPS ? 1 : a > TX_FLIP_EPS ? 2 : 3);
}
BLI_INLINE int tx_vec_sign_flip(const float a[3], const float b[3])
{
return ((tx_sign(a[0]) & tx_sign(b[0])) == 0 ||
(tx_sign(a[1]) & tx_sign(b[1])) == 0 ||
(tx_sign(a[2]) & tx_sign(b[2])) == 0);
}
/* smat is reference matrix, only scaled */
/**
* \a smat is reference matrix only.
*
* \note this is a tricky area, before making changes see: T29633, T42444
*/
static void TransMat3ToSize(float mat[3][3], float smat[3][3], float size[3])
{
float vec[3];
copy_v3_v3(vec, mat[0]);
size[0] = normalize_v3(vec);
copy_v3_v3(vec, mat[1]);
size[1] = normalize_v3(vec);
copy_v3_v3(vec, mat[2]);
size[2] = normalize_v3(vec);
/* first tried with dotproduct... but the sign flip is crucial */
if (tx_vec_sign_flip(mat[0], smat[0]) ) size[0] = -size[0];
if (tx_vec_sign_flip(mat[1], smat[1]) ) size[1] = -size[1];
if (tx_vec_sign_flip(mat[2], smat[2]) ) size[2] = -size[2];
}
float rmat[3][3];
mat3_to_rot_size(rmat, size, mat);
/* first tried with dotproduct... but the sign flip is crucial */
if (dot_v3v3(rmat[0], smat[0]) < 0.0f) size[0] = -size[0];
if (dot_v3v3(rmat[1], smat[1]) < 0.0f) size[1] = -size[1];
if (dot_v3v3(rmat[2], smat[2]) < 0.0f) size[2] = -size[2];
}
static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
{