Skip to content

Commit a22b094

Browse files
Bromeonjo32
andcommitted
Fix Basis * Vector3
Fixes also Vector3::rotated(). Add unit test. Co-authored-by: jo32 <j.jolam@gmail.com>
1 parent b6dcf6e commit a22b094

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

gdnative-core/src/core_types/geom/basis.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,9 @@ impl Basis {
571571
}
572572
}
573573

574-
impl core::ops::Mul<Basis> for Basis {
574+
impl Mul<Basis> for Basis {
575575
type Output = Self;
576+
576577
#[inline]
577578
fn mul(self, rhs: Self) -> Self {
578579
Basis::from_elements([
@@ -600,7 +601,7 @@ impl Mul<Vector3> for Basis {
600601

601602
#[inline]
602603
fn mul(self, rhs: Self::Output) -> Self::Output {
603-
Self::Output::new(self.tdotx(rhs), self.tdoty(rhs), self.tdotz(rhs))
604+
self.xform(rhs)
604605
}
605606
}
606607

gdnative-core/src/core_types/vector3.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,23 @@ godot_test!(
534534
mod tests {
535535
use crate::core_types::Vector3;
536536

537+
/*
538+
* Test introduced due to bug in Basis * Vector3 operator
539+
*
540+
* matching result in GDScript:
541+
* var v1 = Vector3(37.51756, 20.39467, 49.96816)
542+
* var phi = -0.4927880786382844
543+
* var v2 = v1.rotated(Vector3.UP, r)
544+
* print(c)
545+
*/
546+
#[test]
547+
fn rotated() {
548+
let v = Vector3::new(37.51756, 20.39467, 49.96816);
549+
let phi = -0.4927880786382844;
550+
let r = v.rotated(Vector3::UP, phi);
551+
assert!(r.is_equal_approx(Vector3::new(9.414476, 20.39467, 61.77177)));
552+
}
553+
537554
#[test]
538555
fn it_is_copy() {
539556
fn copy<T: Copy>() {}

0 commit comments

Comments
 (0)