style: Avoid getting zero normalized vector of rotate3d for animations.

If we have a rotate axis whose length is extremely large, we will get an
infinite value, and its normalized vector is a zero vector, instead of an
unit vector, i.e. (x/inf, y/inf, z/inf) == (0, 0, 0).

The solution is: we scale the vector, so the length becomes a finite value, and
we could get a valid unit vector.

Therefore, we use a different normalization method, robust_normalize().

Bug: 1467277
Reviewed-by: hiro
This commit is contained in:
Emilio Cobos Álvarez 2018-07-24 03:21:15 +02:00
parent 0c0ffef1a5
commit 3a0c8fc760
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -569,7 +569,7 @@ pub fn get_normalized_vector_and_angle<T: Zero>(
// rotation to not be applied, so we use identity matrix (i.e. rotate3d(0, 0, 1, 0)).
(0., 0., 1., T::zero())
} else {
let vector = vector.normalize();
let vector = vector.robust_normalize();
(vector.x, vector.y, vector.z, angle)
}
}