From d50cab136a681d7dd450f14f4c6b846d146182ed Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Mon, 18 Jul 2022 21:32:53 +0200 Subject: [PATCH] fix: Properly use the `getX/YAxis` out vector --- packages/forge2d/lib/src/common/rot.dart | 10 ++++++++-- packages/forge2d/lib/src/dynamics/fixture.dart | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/forge2d/lib/src/common/rot.dart b/packages/forge2d/lib/src/common/rot.dart index 0783def..9ef7a14 100644 --- a/packages/forge2d/lib/src/common/rot.dart +++ b/packages/forge2d/lib/src/common/rot.dart @@ -36,9 +36,15 @@ class Rot { double getAngle() => math.atan2(sin, cos); - Vector2 getXAxis(Vector2 xAxis) => Vector2(cos, sin); + Vector2 getXAxis({Vector2? out}) { + final result = out ?? Vector2.zero(); + return result..setValues(cos, sin); + } - Vector2 getYAxis(Vector2 yAxis) => Vector2(-sin, cos); + Vector2 getYAxis({Vector2? out}) { + final result = out ?? Vector2.zero(); + return result..setValues(-sin, cos); + } Rot clone() => Rot(sin: sin, cos: cos); diff --git a/packages/forge2d/lib/src/dynamics/fixture.dart b/packages/forge2d/lib/src/dynamics/fixture.dart index 2cdd7dd..a1d5410 100644 --- a/packages/forge2d/lib/src/dynamics/fixture.dart +++ b/packages/forge2d/lib/src/dynamics/fixture.dart @@ -4,10 +4,10 @@ import 'package:forge2d/forge2d.dart'; import 'package:forge2d/src/settings.dart' as settings; import 'package:meta/meta.dart'; -/// A fixture is used to attach a shape to a body for collision detection. A +/// A fixture is used to attach a [Shape] to a [Body] for collision detection. A /// fixture inherits its transform from its parent. Fixtures hold additional /// non-geometric data such as friction, collision filters, etc. Fixtures are -/// created via Body::CreateFixture. +/// created via `body.createFixture`. /// /// Do note that you cannot reuse fixtures. class Fixture { @@ -249,7 +249,7 @@ class Fixture { renderCenter.setFrom(Transform.mulVec2(xf, circle.position)); final radius = circle.radius; - xf.q.getXAxis(renderAxis); + xf.q.getXAxis(out: renderAxis); if (userData != null && userData == liquidFlag) { _liquidOffset.setFrom(body.linearVelocity);