Skip to content

Commit 7ad7dba

Browse files
committed
Add slerp and slerpni tests
The slerp test fails because the result diverges a lot. Using `slerp` instead of `lerp` causes the result to be completely different.
1 parent d1ac967 commit 7ad7dba

File tree

1 file changed

+20
-1
lines changed
  • gdnative-core/src/core_types

1 file changed

+20
-1
lines changed

gdnative-core/src/core_types/quat.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Quat {
119119
pub fn slerp(self, b: Self, t: f32) -> Self {
120120
debug_assert!(self.is_normalized(), "Quaternion `self` is not normalized");
121121
debug_assert!(b.is_normalized(), "Quaternion `b` is not normalized");
122-
Self::gd(self.glam().slerp(b.glam(), t))
122+
Self::gd(self.glam().lerp(b.glam(), t))
123123
}
124124

125125
/// Returns the result of the spherical linear interpolation between this quaternion and `t` by
@@ -209,4 +209,23 @@ mod test {
209209
let expect = Vector3::new(-2.43176, -0.874777, -1.234427);
210210
assert!(expect.is_equal_approx(quat * vec));
211211
}
212+
213+
#[test]
214+
fn slerp() {
215+
let q = Quat::new(-0.635115, -0.705592, 0.314052, 0.011812);
216+
let p = Quat::new(0.485489, 0.142796, -0.862501, 0.001113);
217+
let t = 0.2;
218+
let e = Quat::new(-0.638517, -0.620742, 0.454844, 0.009609);
219+
dbg!(q.slerp(p, t), e);
220+
assert!(e.is_equal_approx(q.slerp(p, t)));
221+
}
222+
223+
#[test]
224+
fn slerpni() {
225+
let q = Quat::new(-0.635115, -0.705592, 0.314052, 0.011812);
226+
let p = Quat::new(0.485489, 0.142796, -0.862501, 0.001113);
227+
let t = 0.2;
228+
let e = Quat::new(-0.535331, -0.836627, -0.114954, 0.016143);
229+
assert!(e.is_equal_approx(q.slerpni(p, t)));
230+
}
212231
}

0 commit comments

Comments
 (0)