Collision with arbitrary shape

Monkey Forums/Monkey Beginners/Collision with arbitrary shape

GfK(Posted 2014) [#1]
Is there a method of detecting whether the mouse is over a non-rectangular graphic? Say, a round GUI button?

I can see no method of doing this. But being a total n00b I'm possibly missing something.

[edit] Maybe the round GUI button wasn't a very good example as I could just use circular collision for that. Let's say a star-shaped GUI button instead.


GfK(Posted 2014) [#2]
Also I cannot see any method of retrieving pixel data directly from an image... and even if I could I'd probably hit a minefield of problems trying to do the same with rotated images.

My first dip back into Monkey is not going well - first [supposedly simple] thing I've attempted, just to find my feet a little, and there's no apparent way of doing it.


Gerry Quinn(Posted 2014) [#3]
Search the 'Code' forum and you'll find code for a PointInPoly() function.


therevills(Posted 2014) [#4]
http://www.monkey-x.com/Community/posts.php?topic=3488

Doesn't deal with scale. Nor rotation.


Gerry Quinn(Posted 2014) [#5]
You can get pixel data from an image by drawing it and using ReadPixels()


GfK(Posted 2014) [#6]
Isn't that a bit... you know.... long-winded/slow? Plus you can wave TTFN to any alpha data you might have needed.


Jesse(Posted 2014) [#7]
you can use the old nPoly library:
http://www.monkey-x.com/Community/posts.php?topic=2571&post=25462
you need to create the polygon vectors in a clock wise direction
and must have a center origin for the polygon(0,0).


programmer(Posted 2014) [#8]
Try SAT?
http://www.monkey-x.com/Community/posts.php?topic=8160


Gerry Quinn(Posted 2014) [#9]
GfK - yes, it IS rather slow and long-winded, and probably should have had its day in the 1990s - but it seems to be a methodology that some people use, especially coming from Blitz.

So if you really don't want to get involved in geometry, you can paint all your buttons in different colours on the back-buffer, load them into an array, and detect clicks by checking the colour of the RGB value corresponding to the mouse position.


slenkar(Posted 2014) [#10]
I have some simple rotated polygon collision code
http://www.monkey-x.com/Community/posts.php?topic=6036

I called the triangle 'square1' in the code oops