|
|
@ -53,16 +53,6 @@ class SlingShot extends BodyComponent {
|
|
|
|
return fixtures;
|
|
|
|
return fixtures;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// https://en.wikipedia.org/wiki/Centroid
|
|
|
|
|
|
|
|
// TODO(alestiago): use from geometry package.
|
|
|
|
|
|
|
|
static Vector2 centroid(List<Vector2> vertices) {
|
|
|
|
|
|
|
|
final centroid = Vector2.zero();
|
|
|
|
|
|
|
|
for (final vertex in vertices) {
|
|
|
|
|
|
|
|
centroid.add(vertex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return centroid / vertices.length.toDouble();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Body createBody() {
|
|
|
|
Body createBody() {
|
|
|
|
final bodyDef = BodyDef()..position = _position;
|
|
|
|
final bodyDef = BodyDef()..position = _position;
|
|
|
@ -72,3 +62,13 @@ class SlingShot extends BodyComponent {
|
|
|
|
return body;
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// For more information: https://en.wikipedia.org/wiki/Centroid
|
|
|
|
|
|
|
|
// TODO(alestiago): move to geometry package.
|
|
|
|
|
|
|
|
Vector2 centroid(List<Vector2> vertices) {
|
|
|
|
|
|
|
|
final centroid = Vector2.zero();
|
|
|
|
|
|
|
|
for (final vertex in vertices) {
|
|
|
|
|
|
|
|
centroid.add(vertex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return centroid / vertices.length.toDouble();
|
|
|
|
|
|
|
|
}
|
|
|
|