Skip to content

Commit 1ed8ac6

Browse files
authored
Resolve Inconsistency in Matrix3 and Matrix4 rotateY Implementations (#317)
* Fix rotation around Y axis * Update CHANGELOG.md
1 parent 3706feb commit 1ed8ac6

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 2.1.5-wip
22

3+
- Fixed `Matrix3.rotationY` direction (Contributed by tlserver, moritzblume)
34
- Added an operator== to Quaternion so that two instances of quaternions can
45
be evaluated for equality.
56
- Require Dart 3.0

lib/src/vector_math/matrix3.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,11 @@ class Matrix3 {
556556
final s = math.sin(radians);
557557
_m3storage[0] = c;
558558
_m3storage[1] = 0.0;
559-
_m3storage[2] = s;
559+
_m3storage[2] = -s;
560560
_m3storage[3] = 0.0;
561561
_m3storage[4] = 1.0;
562562
_m3storage[5] = 0.0;
563-
_m3storage[6] = -s;
563+
_m3storage[6] = s;
564564
_m3storage[7] = 0.0;
565565
_m3storage[8] = c;
566566
}

lib/src/vector_math_64/matrix3.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,11 @@ class Matrix3 {
556556
final s = math.sin(radians);
557557
_m3storage[0] = c;
558558
_m3storage[1] = 0.0;
559-
_m3storage[2] = s;
559+
_m3storage[2] = -s;
560560
_m3storage[3] = 0.0;
561561
_m3storage[4] = 1.0;
562562
_m3storage[5] = 0.0;
563-
_m3storage[6] = -s;
563+
_m3storage[6] = s;
564564
_m3storage[7] = 0.0;
565565
_m3storage[8] = c;
566566
}

test/matrix3_test.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,32 @@ void testMatrix3Transform() {
194194

195195
relativeTest(rotX.transformed(input), input);
196196
relativeTest(rotY.transformed(input),
197-
Vector3(1.0 / math.sqrt(2.0), 0.0, 1.0 / math.sqrt(2.0)));
197+
Vector3(1.0 / math.sqrt(2.0), 0.0, -1.0 / math.sqrt(2.0)));
198198
relativeTest(rotZ.transformed(input),
199199
Vector3(1.0 / math.sqrt(2.0), 1.0 / math.sqrt(2.0), 0.0));
200200
}
201201

202+
void testMatrix3RotationX() {
203+
final rotX = Matrix3.rotationX(math.pi / 2);
204+
final input = Vector3(0.0, 1.0, 0.0);
205+
206+
relativeTest(rotX.transformed(input), Vector3(0.0, 0.0, 1.0));
207+
}
208+
209+
void testMatrix3RotationY() {
210+
final rotY = Matrix3.rotationY(math.pi / 2);
211+
final input = Vector3(0.0, 0.0, 1.0);
212+
213+
relativeTest(rotY.transformed(input), Vector3(1.0, 0.0, 0.0));
214+
}
215+
216+
void testMatrix3RotationZ() {
217+
final rotZ = Matrix3.rotationZ(math.pi / 2);
218+
final input = Vector3(1.0, 0.0, 0.0);
219+
220+
relativeTest(rotZ.transformed(input), Vector3(0.0, 1.0, 0.0));
221+
}
222+
202223
void testMatrix3Transform2() {
203224
final rotZ = Matrix3.rotationZ(math.pi / 4);
204225
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() {
334355
test('transform 2D', testMatrix3Transform2);
335356
test('rotation 2D', testMatrix3AbsoluteRotate2);
336357
test('transform', testMatrix3Transform);
358+
test('rotation 3D x', testMatrix3RotationX);
359+
test('rotation 3D y', testMatrix3RotationY);
360+
test('rotation 3D z', testMatrix3RotationZ);
337361
test('constructor', testMatrix3ConstructorCopy);
338362
test('inversion', testMatrix3Inversion);
339363
test('dot product', testMatrix3Dot);

test/obb3_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void testRotate() {
7979
..center.setValues(0.0, 0.0, 0.0)
8080
..halfExtents.setValues(5.0, 5.0, 5.0);
8181
final corner = Vector3.zero();
82-
final matrix = Matrix3.rotationY(radians(45.0));
82+
final matrix = Matrix3.rotationY(radians(-45.0));
8383

8484
a.rotate(matrix);
8585

0 commit comments

Comments
 (0)