Skip to content

Commit

Permalink
Merge pull request #4 from ismailbozk/master
Browse files Browse the repository at this point in the history
Vector4, Matrix4 multiplication bug fix.
  • Loading branch information
nicklockwood committed Aug 1, 2015
2 parents 97619b7 + ac0f412 commit 4489ea8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions Tests/VectorMathTests/VectorMathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,42 @@ class Matrix4Tests: XCTestCase {

XCTAssertTrue(matrix ~= compare)
}

func testRotationAndTranslation() {
let point = Vector4(0.0, -1.0, 0.0, 1.0);
let euclideanTransformation = Matrix4(0.0, 1.0, 0.0, 0.0,
-1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
-1.0, 0.0, 0.0, 1.0);

let result = euclideanTransformation * point;
let expectedResult = Vector4(0.0, 0.0, 0.0, 1.0);

XCTAssertTrue(result ~= expectedResult);
}


func testTransformationMatrixMultiplication() {
let somePoint = Vector4(2.0, 2.0, 2.0, 1.0);
let zAxisTransformationMaxtrix90Positive = Matrix4(0.0, 1.0, 0.0, 0.0,
-1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0);
let yAxisTransformationMaxtrix90Positive = Matrix4(0.0, 0.0, 1.0, 0.0,
0.0, 1.0, 0.0, 0.0,
-1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0);
let xAxisTransformationMaxtrix90Positive = Matrix4(1.0, 0.0, 0.0, 0.0,
0.0, 0.0, -1.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0);

let resultPoint = (xAxisTransformationMaxtrix90Positive * (yAxisTransformationMaxtrix90Positive * (zAxisTransformationMaxtrix90Positive * somePoint)));

let comparePoint = (xAxisTransformationMaxtrix90Positive * yAxisTransformationMaxtrix90Positive * zAxisTransformationMaxtrix90Positive) * somePoint;

XCTAssertTrue(resultPoint ~= comparePoint);
}
}

class QuaternionTests: XCTestCase {
Expand Down
2 changes: 1 addition & 1 deletion VectorMath/VectorMath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func *(lhs: Vector4, rhs: Matrix4) -> Vector4 {
lhs.x * rhs.m11 + lhs.y * rhs.m21 + lhs.z * rhs.m31 + lhs.w * rhs.m41,
lhs.x * rhs.m12 + lhs.y * rhs.m22 + lhs.z * rhs.m32 + lhs.w * rhs.m42,
lhs.x * rhs.m13 + lhs.y * rhs.m23 + lhs.z * rhs.m33 + lhs.w * rhs.m43,
lhs.x * rhs.m14 + lhs.y * rhs.m24 + lhs.z * rhs.m34 + lhs.w * rhs.m43
lhs.x * rhs.m14 + lhs.y * rhs.m24 + lhs.z * rhs.m34 + lhs.w * rhs.m44
)
}

Expand Down

0 comments on commit 4489ea8

Please sign in to comment.