Fix roation snap failing with zero angle
Due to precision issues, the cosine value calculated with `dot_v3v3(start, end)` can be outside the -1, 1 range causing `acosf` to return `nan(ind)`. Use `angle_signed_on_axis_v3v3_v3` instead. It returns more accurate values, deduplicates code, and avoids these `nan` issues.
This commit is contained in:
parent
17768b3df1
commit
dcb37959d4
|
@ -171,27 +171,11 @@ static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3])
|
|||
|
||||
/* Angle around a constraint axis (error prone, will need debug). */
|
||||
if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) {
|
||||
float axis[3], tmp[3];
|
||||
float axis[3];
|
||||
|
||||
t->con.applyRot(t, NULL, NULL, axis, NULL);
|
||||
|
||||
project_v3_v3v3(tmp, end, axis);
|
||||
sub_v3_v3v3(end, end, tmp);
|
||||
|
||||
project_v3_v3v3(tmp, start, axis);
|
||||
sub_v3_v3v3(start, start, tmp);
|
||||
|
||||
normalize_v3(end);
|
||||
normalize_v3(start);
|
||||
|
||||
cross_v3_v3v3(tmp, start, end);
|
||||
|
||||
if (dot_v3v3(tmp, axis) < 0.0f) {
|
||||
angle = -acosf(dot_v3v3(start, end));
|
||||
}
|
||||
else {
|
||||
angle = acosf(dot_v3v3(start, end));
|
||||
}
|
||||
angle = -angle_signed_on_axis_v3v3_v3(start, end, axis);
|
||||
}
|
||||
else {
|
||||
float mtx[3][3];
|
||||
|
|
Loading…
Reference in New Issue