From 6acb091610ffce40afc9c434f3d8e3a272114142 Mon Sep 17 00:00:00 2001 From: alestiago Date: Thu, 21 Jul 2022 11:10:29 +0100 Subject: [PATCH 1/2] docs: improved gravity documentation --- packages/forge2d/lib/src/dynamics/world.dart | 25 ++++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/forge2d/lib/src/dynamics/world.dart b/packages/forge2d/lib/src/dynamics/world.dart index 14882458..f7ced3d9 100644 --- a/packages/forge2d/lib/src/dynamics/world.dart +++ b/packages/forge2d/lib/src/dynamics/world.dart @@ -22,7 +22,27 @@ class World { final List joints = []; final Vector2 _gravity; + + /// The current [World]'s [gravity]. + /// + /// {@template World.gravity} + /// All [bodies] are affected by [gravity]; unless the [Body] has a specified + /// [Body.gravityOverride]. If so, [Body.gravityOverride] is used instead of + /// [gravity]. + /// + /// See also: + /// + /// * [Body.gravityScale], to multipy [gravity] for a [Body]. + /// * [Body.gravityOverride], to change how the world treats the gravity for + /// a [Body]. + /// {@endtemplate} Vector2 get gravity => _gravity; + + /// Changes the [World]'s gravity. + /// + /// {@macro World.gravity} + set gravity(Vector2 gravity) => this.gravity.setFrom(gravity); + bool _allowSleep = false; DestroyListener? destroyListener; @@ -486,11 +506,6 @@ class World { /// Gets the quality of the dynamic tree double getTreeQuality() => contactManager.broadPhase.getTreeQuality(); - /// Change the global gravity vector. - void setGravity(Vector2 gravity) { - _gravity.setFrom(gravity); - } - /// Is the world locked (in the middle of a time step). bool get isLocked => (flags & locked) == locked; From 000227aa018cd47e72ab2940ee44ff97908cc740 Mon Sep 17 00:00:00 2001 From: alestiago Date: Thu, 21 Jul 2022 11:10:43 +0100 Subject: [PATCH 2/2] test: include World.gravity tests --- packages/forge2d/test/dynamics/world_test.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/forge2d/test/dynamics/world_test.dart b/packages/forge2d/test/dynamics/world_test.dart index 6e1fd3dd..ff7241d7 100644 --- a/packages/forge2d/test/dynamics/world_test.dart +++ b/packages/forge2d/test/dynamics/world_test.dart @@ -7,6 +7,17 @@ class AnotherRevoluteJoint extends RevoluteJoint { } void main() { + group('gravity', () { + test('can change', () { + final world = World(); + + final newGravity = world.gravity.clone()..x += 1; + world.gravity = newGravity; + + expect(world.gravity, equals(newGravity)); + }); + }); + group( 'createJoint', () {