Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 048777a

Browse files
authoredJul 19, 2023
Fix rotation around Y axis (#262)
Current implementation rotates clockwise which is not the norm and not consistent to the other implemented rotations.
1 parent 47a08ea commit 048777a

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed
 

‎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);

0 commit comments

Comments
 (0)
Please sign in to comment.