We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Determining which PShape is under your mouse
Page Index Toggle Pages: 1
Determining which PShape is under your mouse (Read 924 times)
Determining which PShape is under your mouse
Mar 30th, 2010, 9:25am
 
Suppose I have loaded an SVG that is made up of several "path" objects.

When the mouse is clicked, I know I can get the current position (x/y) of the mouse. I want to use that information to figure out which "path" PShape is beneath my mouse at that very instant.

Any guidance for how this can be done with the Processing API?
Re: Determining which PShape is under your mouse
Reply #1 - Mar 30th, 2010, 1:08pm
 
Two possible solutions :

1) checking the distance between the mouse and each segment.

2) using picking (a quick search will give you many results)
Re: Determining which PShape is under your mouse
Reply #2 - Mar 30th, 2010, 1:09pm
 
This Topic was moved here from Syntax Questions by antiplastik.
Re: Determining which PShape is under your mouse
Reply #3 - Mar 30th, 2010, 2:10pm
 
Just a precision about picking: it consists in drawing each shape on an off-screen buffer with different colors (one per shape).
Thus, if you check pixel color at mouse coordinates, you know which shape is hovered.
Page Index Toggle Pages: 1