Skip to content

Resolve Inconsistency in Matrix3 and Matrix4 rotateY Implementations #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/src/vector_math/matrix3.dart
Original file line number Diff line number Diff line change
@@ -556,11 +556,11 @@ class Matrix3 {
final s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = 0.0;
_m3storage[2] = s;
_m3storage[2] = -s;
_m3storage[3] = 0.0;
_m3storage[4] = 1.0;
_m3storage[5] = 0.0;
_m3storage[6] = -s;
_m3storage[6] = s;
_m3storage[7] = 0.0;
_m3storage[8] = c;
}
4 changes: 2 additions & 2 deletions lib/src/vector_math_64/matrix3.dart
Original file line number Diff line number Diff line change
@@ -556,11 +556,11 @@ class Matrix3 {
final s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = 0.0;
_m3storage[2] = s;
_m3storage[2] = -s;
_m3storage[3] = 0.0;
_m3storage[4] = 1.0;
_m3storage[5] = 0.0;
_m3storage[6] = -s;
_m3storage[6] = s;
_m3storage[7] = 0.0;
_m3storage[8] = c;
}
26 changes: 25 additions & 1 deletion test/matrix3_test.dart
Original file line number Diff line number Diff line change
@@ -194,11 +194,32 @@ void testMatrix3Transform() {

relativeTest(rotX.transformed(input), input);
relativeTest(rotY.transformed(input),
Vector3(1.0 / math.sqrt(2.0), 0.0, 1.0 / math.sqrt(2.0)));
Vector3(1.0 / math.sqrt(2.0), 0.0, -1.0 / math.sqrt(2.0)));
relativeTest(rotZ.transformed(input),
Vector3(1.0 / math.sqrt(2.0), 1.0 / math.sqrt(2.0), 0.0));
}

void testMatrix3RotationX() {
final rotX = Matrix3.rotationX(math.pi / 2);
final input = Vector3(0.0, 1.0, 0.0);

relativeTest(rotX.transformed(input), Vector3(0.0, 0.0, 1.0));
}

void testMatrix3RotationY() {
final rotY = Matrix3.rotationY(math.pi / 2);
final input = Vector3(0.0, 0.0, 1.0);

relativeTest(rotY.transformed(input), Vector3(1.0, 0.0, 0.0));
}

void testMatrix3RotationZ() {
final rotZ = Matrix3.rotationZ(math.pi / 2);
final input = Vector3(1.0, 0.0, 0.0);

relativeTest(rotZ.transformed(input), Vector3(0.0, 1.0, 0.0));
}

void testMatrix3Transform2() {
final rotZ = Matrix3.rotationZ(math.pi / 4);
final trans = Matrix3(1.0, 0.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0);
@@ -334,6 +355,9 @@ void main() {
test('transform 2D', testMatrix3Transform2);
test('rotation 2D', testMatrix3AbsoluteRotate2);
test('transform', testMatrix3Transform);
test('rotation 3D x', testMatrix3RotationX);
test('rotation 3D y', testMatrix3RotationY);
test('rotation 3D z', testMatrix3RotationZ);
test('constructor', testMatrix3ConstructorCopy);
test('inversion', testMatrix3Inversion);
test('dot product', testMatrix3Dot);
2 changes: 1 addition & 1 deletion test/obb3_test.dart
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ void testRotate() {
..center.setValues(0.0, 0.0, 0.0)
..halfExtents.setValues(5.0, 5.0, 5.0);
final corner = Vector3.zero();
final matrix = Matrix3.rotationY(radians(45.0));
final matrix = Matrix3.rotationY(radians(-45.0));

a.rotate(matrix);