Exactly how reliable is World for a real game? (Big levels)

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.
Jpfed
Prole
Posts: 4
Joined: Tue Jun 02, 2009 10:54 pm

Re: Exactly how reliable is World for a real game? (Big levels)

Post by Jpfed »

kikito- in general, the union of two convex shapes is not necessarily convex. In fact, it's fairly rare that such a union would be convex. Unfortunately, if you try to make a polygonShape that is not convex, LOVE may crash (appears to happen consistently on OS X, but on Windows LOVE 0.5 lets it slide).

That said, if you're interested in doing polygon unions (where you only care about the exterior), here is a way to do it (I think):

Assume that each polygon is a list of vertices. Initialize an empty "result" polygon.

Find the leftmost vertex out of both polygons (break ties by selecting the uppermost). Consider this vertex to be the "current" vertex. "Select" the polygon that has this vertex.

Loop: If the current vertex is not in the result, add the current vertex to the result; else you're done.
Find all intersections (if any) between the edge going from the current point to the next point in the selected polygon, and all edges from the other polygon.
If no such intersection exists, make the next point in the selected polygon the current point and loop.
If at least one intersection exists, find the edge whose point of intersection is closest to the current point. Consider the point of intersection to be the "current" point, and "select" whichever polygon is not currently selected. Loop.

I have some source that does this if you'd like it; it's not quite as simple as outlined here, but it's close. http://github.com/jpfed/Adrift/blob/mas ... l/poly.lua , specifically the "union_with" function.

tl;dr: select a point that you know is on the perimeter of the figure. March along the perimeter; when you encounter an intersection as you march along one polygon, you know you need to start marching along the other polygon. Keep tracing like this until you get back to the point you started with.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Exactly how reliable is World for a real game? (Big levels)

Post by kikito »

Hmmm this is very interesting! I'll sure give it a look, thanks for sharing it.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests