hey guys... important question... please see the grafic i explained...
if i need to know if a particular part in any panel/activity etc etc is touched then... its not difficult when the part i need is in rectangular shape..
Now what if i wana detect which part of the circular menu has been touched??
do we have any routines? libraries? or any collision detection similar functions that i could use to know if that point exists in a particularly shaped boundry.. eg.. a round button..?
or else i would just have to use my own ideas from coordinate geometry...
The best approach is to calculate whether the touch point is inside one of the polygons of your wheel. But there are two possible tricks:
- color each slice of the wheel with a different color then test the color of the pixel under the finger.
- stack panels containing the slices (a slice per panel). If the click is on a transparent part of the panel, the event is ignored (in Gesture Detector, you return false for the touch event). So the event is dispatched to the next panel. And so on.
The stevel05's class is probably a better choice. Anyway, to get the color of a pixel, you just have to call the GetPixel function of the Bitmap class.
Hey guys thanx a lot... been a great help.. but heres the problem
Steve... its dam smart... i got all the concepts... still sorting out the polygon one...
However... Informatix's get Pixel color.. is so cheeky and quick...
i have a button... i've attached its look...
the Get Pixel is a problem cz i have lots of them with vignettes...
the Hotspot... doesnt have these mix type shapes... or do you think i will have to use the polygon for the red type buttons i have shown??
It depends how accurate you want the touch to be, and it depends how big the buttons will be. You may get away with approximating each button with three circles. If not, it'll have to be polygons. But again an approximation will probably be good enough.
If really approximate is good enough you could put a rectangle around each button providing you add the large middle circle last, that will be returned when it overlaps.
yea steve.. thats right... i did realize that for a button an approximation is good enough : )
however. .. when still on this topic. ...
i was really wondering that how do game programmers pull off the coding for collision detection? .. when accuracy is needed?..
could it just be a higher number of polygon points?
something like squaring a circle?
Yes, they use polygons (with as many points as needed) and they detect whether the visible polygons overlap. To avoid complex computations, they always use convex polygons. A concave shape is splitted in many convex polygons. Look at this:
You can see the polygon summits and how the vehicle is sliced in 9 convex polygons.
Wow.. thats some thinking.. thanx Informatix... and yeah... concave polygons do pose a lill more calculating...
thanx for sharing...
ok... so for now... i am going to work out the theory behind "Whats the logic used for Point in Polygon(pip)"!
... the reason behind that code in HOTSPOT
lets see should come up with something... will let you and Steve know...
OK guys... i finally Cracked the Logic behind PIP in the HOTSPOT coding..
read up a little from the net... and derived the final equation through coordinate geometry!
check it out...
steve .. informatix ... lemme know what you think... its brilliant.. who ever originally thought of this .. was a genius ;-)
Yes!, thanks for that. I understood the concept but the maths eluded me. I can follow that example, you learn something new every day . As you say, genius.
I've stored the diagrams with my source code so I can refer to it if I need to.
I recently wrapped the libGDX library and the Math classes are full of algorithms like this. Some of them are really really impressive. If you read Java a bit, take a look at the Intersector class for example: https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/math/Intersector.java
I saw these functions changing many times so I suppose that their current form is the most optimized.