Page 1 of 1

Love 2D Awkward Polygon Problem

Posted: Mon May 27, 2013 4:45 pm
by XOdysseusX
I never liked polygons with Love 2D because they always give me trouble, and here is yet another example. :x

Code: Select all

self.shape = love.physics.newPolygonShape(-2, -2, 2, -2, 2, 0, 1, 0, 1, 4, -1, 4, -1, 0, -2, 0)
Now that's pretty straight forward to me, 8 vertices centered around 0,0 going clockwise, but when you launch the game... well, you'll see.

Can somebody please explain to me what I'm doing wrong, or if I should just use two rectangles with the physics body to accomplish this task instead?

Re: Love 2D Awkward Polygon Problem

Posted: Mon May 27, 2013 7:50 pm
by vrld
love.pysics.newPolygonShape wrote:This shape can have 8 vertices at most, and must form a convex shape.
Your polygon:
concave-polygon.png
concave-polygon.png (295 Bytes) Viewed 5550 times
Wolfram Mathworld on convex polygons
Google image search for convex polygon

Re: Love 2D Awkward Polygon Problem

Posted: Wed May 29, 2013 11:48 pm
by qaisjp
Why don't we support concave polygons? Isn't it just a sequence of lines attached?

Re: Love 2D Awkward Polygon Problem

Posted: Thu May 30, 2013 1:21 am
by Boolsheet
It is Box2D that expects convex polygons. The math gets a lot easier if everything can be assumed convex.

There are several reasons why LÖVE does not automatically chop the lovers polygon up and return multiple shapes. However, the next version of LÖVE will have a triangulate function that allows everyone to do this themselves. ;)

Re: Love 2D Awkward Polygon Problem

Posted: Thu May 30, 2013 2:26 pm
by Ref
Love 0.9 does the triangulation but if you want to do more with the polygon than just 'fill', you will have to do the triangulation on your own.

Re: Love 2D Awkward Polygon Problem

Posted: Thu May 30, 2013 6:24 pm
by Zeliarden
love.pysics.newPolygonShape wrote:
This shape can have 8 vertices at most, and must form a convex shape.
Why only 8 vertices? Box2d have support for more.

Re: Love 2D Awkward Polygon Problem

Posted: Thu May 30, 2013 6:30 pm
by slime
Zeliarden wrote:
love.pysics.newPolygonShape wrote:
This shape can have 8 vertices at most, and must form a convex shape.
Why only 8 vertices? Box2d have support for more.
Only if you explicitly compile it for more. You should create multiple shapes and attach them to a single body, if you want complex or concave shapes.

Re: Love 2D Awkward Polygon Problem

Posted: Sat Jun 01, 2013 7:28 am
by sanjiv
So I take it this is the reason why polygon('line') and polygon('fill') draw different shapes? Does anyone know of a custom love function that can draw filled polygons successfully? Or alternately, have people found out if it is futile to try this?

If not, I'm ok just doing a brute force method.

Re: Love 2D Awkward Polygon Problem

Posted: Sat Jun 01, 2013 10:52 pm
by Ref
HardonCollider, home brew or wait for Love 0.9
Edit: Is this what you want (see demo) - not triangles, just fill a concave polygon?

Re: Love 2D Awkward Polygon Problem

Posted: Sun Jun 02, 2013 9:19 am
by slime
Ref wrote:Love 0.9 does the triangulation but if you want to do more with the polygon than just 'fill', you will have to do the triangulation on your own.
Yeah, 0.9's triangulation technique is optimized for performance rather than minimum triangle count or intuitive triangle positions. Whether that's preferable or not depends on how people want to use it, I guess.