| 629 | } |
| 630 | |
| 631 | fn quat_slerp(a: &[f32; 4], b: &[f32; 4], t: f32) -> [f32; 4] { |
| 632 | let mut dot = a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3]; |
| 633 | let mut b2 = *b; |
| 634 | if dot < 0.0 { |
| 635 | dot = -dot; |
| 636 | b2 = [-b[0], -b[1], -b[2], -b[3]]; |
| 637 | } |
| 638 | if dot > 0.9995 { |
| 639 | let mut out = [ |
| 640 | a[0] + t * (b2[0] - a[0]), |
| 641 | a[1] + t * (b2[1] - a[1]), |
| 642 | a[2] + t * (b2[2] - a[2]), |
| 643 | a[3] + t * (b2[3] - a[3]), |
| 644 | ]; |
| 645 | let len = (out[0]*out[0] + out[1]*out[1] + out[2]*out[2] + out[3]*out[3]).sqrt(); |
| 646 | if len > 0.0 { for v in &mut out { *v /= len; } } |
| 647 | return out; |
| 648 | } |
| 649 | let theta = dot.acos(); |
| 650 | let sin_theta = theta.sin(); |
| 651 | let wa = ((1.0 - t) * theta).sin() / sin_theta; |
| 652 | let wb = (t * theta).sin() / sin_theta; |
| 653 | [ |
| 654 | wa * a[0] + wb * b2[0], |
| 655 | wa * a[1] + wb * b2[1], |
| 656 | wa * a[2] + wb * b2[2], |
| 657 | wa * a[3] + wb * b2[3], |
| 658 | ] |
| 659 | } |
| 660 | |
| 661 | fn lerp_vec3(a: &[f32; 3], b: &[f32; 3], t: f32) -> [f32; 3] { |
| 662 | [ |