Skip to content

Commit e82c56d

Browse files
committed
Fix Qua4f multiplication
1 parent e9e4058 commit e82c56d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Sources/FirebladeMath/Quat/Quaternion+Multiplication.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ public func multiply(_ lhs: Quat4f, _ rhs: Quat4f) -> Quat4f {
3333
#if FRB_MATH_USE_SIMD
3434
return Quat4f(storage: simd.simd_mul(lhs.storage, rhs.storage))
3535
#else
36-
#warning("not implemented yet")
37-
return Quat4f.identity
36+
let n0 = rhs.x * lhs.x - rhs.y * lhs.y - rhs.z * lhs.z - rhs.w * lhs.w
37+
let n1 = rhs.x * lhs.y + rhs.y * lhs.x - rhs.z * lhs.w + rhs.w * lhs.z
38+
let n2 = rhs.x * lhs.z + rhs.y * lhs.w + rhs.z * lhs.x - rhs.w * lhs.y
39+
let n3 = rhs.x * lhs.w - rhs.y * lhs.z + rhs.z * lhs.y + rhs.w * lhs.x
40+
return Quat4f(n3, n2, n1, n0)
3841
#endif
3942
}
4043

Tests/FirebladeMathTests/Mat4x4fTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@ class Mat4x4fTests: XCTestCase {
374374
let m1 = Mat4x4f(translation: [1, 2, 3])
375375
let mat00 = m0 * m1
376376

377-
var mat = multiply(mat00, Vec4f(78.0, 3.02, -32, 0.093))
378-
XCTAssertEqualElements(mat.elements, [55.978_317, 62.363_155, -9.606_318, 0.093_000], accuracy: 1e-5) // FIXME: would like to have 1e-6
377+
var mat = multiply(mat00, Vec4f(78.0, 3.02, -32, 1.0))
378+
XCTAssertEqualElements(mat.elements, [56.224686, 62.507904, -6.2246857, 1.0], accuracy: 1e-5)
379379

380-
mat = mat00 * Vec4f(78.0, 3.02, -32, 0.093)
381-
XCTAssertEqualElements(mat.elements, [55.978_317, 62.363_155, -9.606_318, 0.093_000], accuracy: 1e-5) // FIXME: would like to have 1e-6
380+
mat = mat00 * Vec4f(78.0, 3.02, -32, 1.0)
381+
XCTAssertEqualElements(mat.elements, [56.224686, 62.507904, -6.2246857, 1.0], accuracy: 1e-5)
382382
}
383383

384384
func testInverse() {

0 commit comments

Comments
 (0)