-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 21 February 2003 11:50, Nathanael Noblet wrote:
>       I need a quick way to determine which hot area was clicked on and call
> it's function. So I'm wondering what data structure would I use so that
> once I figure out the location of the click, I can quickly retrieve the
> function call? I mean, if I have an array, how do I index it in such a
> way that I can calculate the location of the mouse click to be an index
> of this array?

i'm assuming these hot areas are polygons and not single points, since you're 
talking about a mouse driven interface. if that assumption is wrong, stop 
reading right here. =)

store an array/list of polygons that define the hotspots. each polygon 
consists of an array of points (obviously). from there you can test if any 
given point on the screen is inside or outside the polygon quite easily...

basically, you construct and array from the point to just off the edge of the 
screen. so if your point is (x, y), your ray could be:
( (x, y), (x, widthOfScreen + 1) )

then you check how many times this ray crosses the boundaries of the polygon. 
if it crosses an odd number of times, it's inside. if it crosses an even 
number of times, it's outside. the only real corner cases one needs to be 
watchful for are when the point is ON a polygon line or the ray crosses a 
vertex. but those are easy to deal with.

things can get annoying if you allow overlapping polygons, but that's easily 
solved by either adding a z-axis ("stacking") or by allowing multiple 
activations with a single interaction. however, since you're doing an 
interface i'd assume you'll either have no overlaps or else deal with a 
z-axis (depending on the type and complexity of the interface)

a quick search on the 'net brought this up, which covers things pretty well  
even has pseudocode to work from (i just skimmed it, didn't really read it, 
so... i hope it doesn't disappoint =):

http://www.ics.uci.edu/~eppstein/161/960307.html#intest

oh, and i'm not a graphics programmer. so this may not be the most efficient 
way of doing things. i dunno. but it works. =)

- -- 
Aaron J. Seigo
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE: The 'K' is for 'kick ass'
http://www.kde.org       http://promo.kde.org/3.1/feature_guide.php
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+VyJp1rcusafx20MRAnhEAJ9iOgdwZXbgyWoq+Hbm6ZMx5HEXIACgmjrc
zcD7CrEyJauz1y5TuYoikcc=
=VC3/
-----END PGP SIGNATURE-----

Reply via email to