My concave polygon trick VS other platforms...

Monkey Forums/Monkey Programming/My concave polygon trick VS other platforms...

BlitzProg(Posted 2012) [#1]
In my portal engine ( http://www.monkeycoder.co.nz/Community/topics.php?forum=1168&app_id=168 ) I achieve the "line of sight view" by covering everything you don't see with a massive concave polygon.

[monkeycode]
Function updateview(x#,y#,angle#)
Local i
For i=0 To accuracy
l[i].update(x,y,(Float(i)*360/accuracy))
coordinates[(i*2)+12] = l[i].endx
coordinates[(i*2)+13] = l[i].endy
Next

coordinates[0]=x ;coordinates[1]=y-10
coordinates[2]=x-10;coordinates[3]=y-10
coordinates[4]=x-10;coordinates[5]=y+10
coordinates[6]=x+10;coordinates[7]=y+10
coordinates[8]=x+10;coordinates[9]=y-10
coordinates[10]=x ;coordinates[11]=y-10
End Function
[/monkeycode]

I simplified the above function to show the essentials.
- The program fires lasers around the player and spread them evenly around 360°
- It notes down where each lasers end. It forms some of the coordinates for a nice polygon.
- the first coordinates of the polygons are then defined and I end up with the inverse shape (a massive square far bigger than the screen that has a hole, this is what you see)

============

This is the solution I came up with to create this app.
It works well, smooth and fast in Flash and HTML5, but for Android (and possibly some other platforms, since I've been searching around already) That polygon will just create a big mess, usually making your whole screen black.

I tried using Triangulate Poly, it just freeze the app. I haven't found any other option. But I quite want this thing to work on my android tablet :( Anyone have an alternative implementation idea?


NoOdle(Posted 2012) [#2]
I wrote an app in monkey that projects shadows from concave polygons which works on all platforms. I first determined forward facing edges, I then projected these vertices onto axis perpendicular to light ray to to find min and max. These are the vertices the shadow volume will extend from. Works nicely and is very quick. It sounds like it could work with your portal engine...


muddy_shoes(Posted 2012) [#3]
If triangulating is freezing the app then the algorithm is probably stuck in a while loop. I'd guess it's a loop like "while verts.Length > 3" and it's just failing to find ears to clip. If that's the case then you've probably got an issue with the vertex ordering.

I'm doing something similar to you where I fill the outside of a level. The fill is done by creating a polygon from the level boundary out beyond the rendered area and triangulating that using ear-clipping code ported from libgdx. It works fine.