Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Add friction and restitution arguments to createFixtureFromShape #56

Merged
merged 4 commits into from
Aug 22, 2022
Merged
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: 1 addition & 1 deletion packages/benchmark/web/bench2d.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Bench2d {
final bd = BodyDef()
..type = BodyType.dynamic
..position.setFrom(y);
world.createBody(bd).createFixtureFromShape(shape, 5.0);
world.createBody(bd).createFixtureFromShape(shape, density: 5.0);
y.add(deltaY);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/forge2d/example/web/blob_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class BlobTest extends Demo {
psd.setAsBox(3.0, 1.5, Vector2(cx, cy + 15.0), 0.0);
bd2.position = Vector2(cx, cy + 15.0);
final fallingBox = world.createBody(bd2);
fallingBox.createFixtureFromShape(psd, 1.0);
fallingBox.createFixtureFromShape(psd, density: 1.0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/forge2d/example/web/racer/car.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Car {

final shape = PolygonShape()..set(vertices);

_body.createFixtureFromShape(shape, 0.1);
_body.createFixtureFromShape(shape, density: 0.1);

final jointDef = RevoluteJointDef();
jointDef.bodyA = _body;
Expand Down
2 changes: 1 addition & 1 deletion packages/forge2d/example/web/racer/tire.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Tire {

final polygonShape = PolygonShape();
polygonShape.setAsBoxXY(0.5, 1.25);
final fixture = body.createFixtureFromShape(polygonShape, 1.0);
final fixture = body.createFixtureFromShape(polygonShape, density: 1.0);
fixture.userData = this;

_currentTraction = 1.0;
Expand Down
18 changes: 12 additions & 6 deletions packages/forge2d/lib/src/dynamics/body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,18 @@ class Body {
/// friction, restitution, user data, or filtering.
/// If the density is non-zero, this function automatically updates the mass
/// of the body.
///
/// [shape] the shape to be cloned.
/// [density] is the shape density (set to zero for static bodies).
/// Warning: This function is locked during callbacks.
Fixture createFixtureFromShape(Shape shape, [double density = 0.0]) {
return createFixture(FixtureDef(shape)..density = density);
Fixture createFixtureFromShape(
Shape shape, {
double density = 1.0,
double friction = 0.0,
double restitution = 0.0,
}) {
return createFixture(
FixtureDef(shape)
..density = density
..friction = friction
..restitution = restitution,
);
}

/// Destroy a fixture. This removes the fixture from the broad-phase and
Expand Down
2 changes: 1 addition & 1 deletion packages/forge2d/lib/src/dynamics/fixture_def.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FixtureDef {
this.userData,
this.friction = 0,
this.restitution = 0,
this.density = 0,
this.density = 1,
this.isSensor = false,
Filter? filter,
}) : filter = filter ?? Filter();
Expand Down