Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 2.3.0-wip

- Add `leftTranslateByVector2` method to `Matrix4`.
Equivalent to the `leftTranslate` set of methods, that multiplies this matrix by a translation matrix from the left.
- Add translateByVector2 method to Matrix4.
- Require `sdk: ^3.7.0`.

Expand Down
7 changes: 7 additions & 0 deletions lib/src/vector_math/matrix4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,13 @@ class Matrix4 {
_m4storage[15] = tw * r4;
}

/// Multiply this by a translation from the left.
@pragma('wasm:prefer-inline')
@pragma('vm:prefer-inline')
@pragma('dart2js:prefer-inline')
void leftTranslateByVector2(Vector2 v2) =>
leftTranslateByDouble(v2.x, v2.y, 0.0, 1.0);

/// Multiply this by a translation from the left.
@pragma('wasm:prefer-inline')
@pragma('vm:prefer-inline')
Expand Down
7 changes: 7 additions & 0 deletions lib/src/vector_math_64/matrix4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,13 @@ class Matrix4 {
_m4storage[15] = tw * r4;
}

/// Multiply this by a translation from the left.
@pragma('wasm:prefer-inline')
@pragma('vm:prefer-inline')
@pragma('dart2js:prefer-inline')
void leftTranslateByVector2(Vector2 v2) =>
leftTranslateByDouble(v2.x, v2.y, 0.0, 1.0);

/// Multiply this by a translation from the left.
@pragma('wasm:prefer-inline')
@pragma('vm:prefer-inline')
Expand Down
14 changes: 14 additions & 0 deletions test/matrix4_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,20 @@ void testLeftTranslate() {
expect(result.x, equals(3.0));
expect(result.y, equals(0.0));
expect(result.z, equals(0.0));

// Matrix4 alternative methods
final m2 = Matrix4.diagonal3Values(2.0, 3.0, 4.0);
final result2 = Matrix4.columns(
Vector4(2.0, 0.0, 0.0, 0.0),
Vector4(0.0, 3.0, 0.0, 0.0),
Vector4(0.0, 0.0, 4.0, 0.0),
Vector4(1.0, 0.0, 0.0, 1.0),
);

expect(m2.clone()..leftTranslateByDouble(1, 0, 0, 1), result2);
expect(m2.clone()..leftTranslateByVector2(Vector2(1, 0)), result2);
expect(m2.clone()..leftTranslateByVector3(Vector3(1, 0, 0)), result2);
expect(m2.clone()..leftTranslateByVector4(Vector4(1, 0, 0, 1)), result2);
}

void testMatrixClassifiers() {
Expand Down