polygon coords "x1,y1,x2,y2,..." suggestions [RESOLVED]

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
houston
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 17
Joined: Sat Nov 27, 2010 7:44 pm
Current Project: SDL_xhtml engine
Favorite Gaming Platforms: PC, MacOS, Linux, iPhone
Programming Language of Choice: Assembly, C, C++
Location: Belfast N/Ireland
Contact:

polygon coords "x1,y1,x2,y2,..." suggestions [RESOLVED]

Post by houston »

hi; I want to have an image on the screen and have relative regions within the image that are clickable hot-spots, with the following region types:

circle coords = "x,y,r"
rect coords = "x1,y1, x2,y2"
polygon coords = "x1,y1, ... "

how would I work out the polygon regions efficiently for mouse coords, the polygons can have many coords where do you start? I just can't get my head around this lol
If you need to understand better what I'm talking about it has to work the same way as HTML Image Maps..

I guess if anybody has done anything similar with flood filling a polygon shape then they could give pointers!!

Sorry if none of this seems worded properly, lack of sleep!

houston.
found a good method here if anybody is interested..

http://www.faqs.org/faqs/graphics/algorithms-faq/

houston
Last edited by houston on Fri Dec 03, 2010 6:45 am, edited 1 time in total.
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: polygon coords "x1,y1,x2,y2,..." suggestions

Post by RyanPridgeon »

So are you talking about testing the mouse position against those clickable areas? Or drawing the shapes to the screen? For drawing it depends on your API, for example, some will have built in methods for drawing those shapes.
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
houston
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 17
Joined: Sat Nov 27, 2010 7:44 pm
Current Project: SDL_xhtml engine
Favorite Gaming Platforms: PC, MacOS, Linux, iPhone
Programming Language of Choice: Assembly, C, C++
Location: Belfast N/Ireland
Contact:

Re: polygon coords "x1,y1,x2,y2,..." suggestions

Post by houston »

RyanPridgeon wrote:So are you talking about testing the mouse position against those clickable areas? Or drawing the shapes to the screen? For drawing it depends on your API, for example, some will have built in methods for drawing those shapes.
I knew I'd worded that badly lol.. Yes testing mouse position within the polygon!


houston
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: polygon coords "x1,y1,x2,y2,..." suggestions [RESOLVED]

Post by RyanPridgeon »

For the n polygon test, you may find this helpful;

http://erich.realtimerendering.com/ptinpoly/

For the rectangle test, you can just do something like

if (point.x >= rect.x1 && point.x =< rect.x2
&& point.y >= rect.y1 && point.y <= rect.y2)
{
collision();
}

For the circle test, just check the distance between the point and the center of the circle.

distance = Math.sqrt( Math.pow(point.x - circle.x, 2) + Math.pow(point.y - circle.y, 2) ) // use pythag to find the distance
if ( distance < circle.radius )
{
collision();
}
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
Post Reply