Skip to content

Commit

Permalink
docs: Remove counterclockwise order requirement for PolygonComponent …
Browse files Browse the repository at this point in the history
…vertices (#3352)

The documentation used to require that lists of vertices in
PolygonComponent (and its subclass PolygonHitbox) should be in
counterclockwise order. This is no more necessary because the
implementation is robust:
https://github.com/flame-engine/flame/blob/main/packages/flame/lib/src/geometry/polygon_component.dart#L122-L124

Moreover, the wording was a bit confusing (the example looks clockwise).

The paragraphs mentioning the vertex order were deleted altogether.
  • Loading branch information
maurovanetti authored Oct 24, 2024
1 parent cf5358c commit 14b8801
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
2 changes: 0 additions & 2 deletions doc/flame/collision_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ them so don't doubt to use them even if your use case isn't listed here.
It should be noted that if you want to use collision detection or `containsPoint` on the `Polygon`,
the polygon needs to be convex. So always use convex polygons or you will most likely run into
problems if you don't really know what you are doing.
It should also be noted that you should always define the vertices in your polygon
in a counter-clockwise order.

The other hitbox shapes don't have any mandatory constructor, that is because they can have a
default calculated from the size of the collidable that they are attached to, but since a
Expand Down
7 changes: 2 additions & 5 deletions doc/flame/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,9 @@ For example you could create a diamond shapes polygon like this:
void main() {
PolygonComponent.relative(
[
Vector2(0.0, 1.0), // Middle of top wall
Vector2(0.0, -1.0), // Middle of top wall
Vector2(1.0, 0.0), // Middle of right wall
Vector2(0.0, -1.0), // Middle of bottom wall
Vector2(0.0, 1.0), // Middle of bottom wall
Vector2(-1.0, 0.0), // Middle of left wall
],
size: Vector2.all(100),
Expand All @@ -1090,9 +1090,6 @@ the center of the polygon.
In the image you can see how the polygon shape formed by the purple arrows is defined by the red
arrows.

Remember to define the lists in a counter clockwise manner (if you think in the screen coordinate
system where the y-axis is flipped, otherwise it is clockwise).


### RectangleComponent

Expand Down
Binary file modified doc/images/polygon_shape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 14b8801

Please sign in to comment.