Love 2D Awkward Polygon Problem

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
XOdysseusX
Prole
Posts: 11
Joined: Fri Apr 26, 2013 3:32 pm

Love 2D Awkward Polygon Problem

Post 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?
Attachments
Space Walk.love
(322.67 KiB) Downloaded 186 times
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Love 2D Awkward Polygon Problem

Post 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 5257 times
Wolfram Mathworld on convex polygons
Google image search for convex polygon
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Love 2D Awkward Polygon Problem

Post by qaisjp »

Why don't we support concave polygons? Isn't it just a sequence of lines attached?
Lua is not an acronym.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Love 2D Awkward Polygon Problem

Post 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. ;)
Shallow indentations.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Love 2D Awkward Polygon Problem

Post 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.
Attachments
Simple example og triangulation using Love 0.9
Simple example og triangulation using Love 0.9
tri_poly_91.jpg (11.38 KiB) Viewed 5196 times
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: Love 2D Awkward Polygon Problem

Post 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.
User avatar
slime
Solid Snayke
Posts: 3134
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Love 2D Awkward Polygon Problem

Post 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.
User avatar
sanjiv
Citizen
Posts: 88
Joined: Mon Feb 27, 2012 5:11 am

Re: Love 2D Awkward Polygon Problem

Post 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.
Attachments
polyTrouble.love
(792 Bytes) Downloaded 138 times
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Love 2D Awkward Polygon Problem

Post 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?
Attachments
ConcaveFill.love
Polygon fill using HardonCollider
(18.14 KiB) Downloaded 187 times
With a few more vertices
With a few more vertices
tri_poly_92.jpg (29.24 KiB) Viewed 5120 times
User avatar
slime
Solid Snayke
Posts: 3134
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Love 2D Awkward Polygon Problem

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 47 guests