mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'imbris/opt-character-behavior' into 'master'
NaNs!!! See merge request veloren/veloren!2930
This commit is contained in:
commit
045621993a
@ -204,7 +204,7 @@ impl Ori {
|
||||
// NOTE: acos is very sensitive to errors at small angles
|
||||
// - https://www.researchgate.net/post/How_do_I_calculate_the_smallest_angle_between_two_quaternions
|
||||
// - see angle_between unit test epislons
|
||||
let angle = 2.0 * between.w.min(1.0).acos();
|
||||
let angle = 2.0 * between.w.min(1.0).max(-1.0).acos();
|
||||
if angle < PI { angle } else { TAU - angle }
|
||||
}
|
||||
|
||||
@ -300,6 +300,10 @@ fn rotation_2d(Vec2 { x, y }: Vec2<f32>, axis: Vec3<f32>) -> Quaternion<f32> {
|
||||
// vector = vec3(0, 0, 1) * +/- sqrt((1 - cos(a)) / 2)
|
||||
//
|
||||
// cos(a) = x / |xy| => x (when normalized)
|
||||
|
||||
// Prevent NaNs from negative sqrt (float errors can put this slightly over 1.0)
|
||||
let x = x.min(1.0).max(-1.0);
|
||||
|
||||
let scalar = ((1.0 + x) / 2.0).sqrt() * y.signum();
|
||||
let vector = axis * ((1.0 - x) / 2.0).sqrt();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user