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 › help refining bounce mechanism
Page Index Toggle Pages: 1
help refining bounce mechanism (Read 1302 times)
help refining bounce mechanism
May 19th, 2010, 5:14pm
 
Hi all,

I have been working on a project in which I am harvesting questions people type into Google. A cronjob collects the results from Google's "suggest" list into several XML files.

The current state of the project is here: http://www.oracloud.net
Here is the full code: http://www.oracloud.net/sketch12.pde

The problem I'm having is with the words bouncing off one another. I have tried just about everything and this is the best result I could get. But I'd really like to eliminate the issue where some of the words get "caught" and sort of jitter near the mouse until I move the mouse to release them. I want it to be possible to hover over one word, while other words get pushed away. When the mouse is still and not hovering over a word, I want to make sure words heading that direction don't get caught. For the most part, this is happening.

Here is the conditional that is essentially causing words to bounce back when the mouse is still.

Code:
if (dist(posX[i]+(qWidth/2), posY[i]-(fontsize/2), mouseX, mouseY) < (qWidth/2+25) && abs(mouseX-pmouseX) < 1 && abs(mouseY-pmouseY) < 1) {
   dirX[i] *= -1;
   dirY[i] *= -1;
 }


The main problem is that this is all within a loop that alters each position (posX, posY) array (one per shape). Before I was setting a boolean called hover to true upon hover, and this would cause any subsequently drawn words to bounce back, but then at the end of draw() hover had to be reset to false (so it will be false when a user is not hovering).

I know this is fairly complex territory as it requires understanding my entire program, but if anyone has suggestions how I can improve this mechanism they would be greatly appreciated.
Re: help refining bounce mechanism
Reply #1 - May 19th, 2010, 7:52pm
 
Instead of "bouncing" words away to avoid multiple mouseovers, I would  make sure that the text popup only happens to the first mouseover hit found.  The way I usually do this is to run through my array of objects in reverse order from the order in which they render (int i=objects.length-1, i>=0), checking for mouseOver.  On the first hit, I would trigger the mouseOver event for that object, and then call break;, exiting the check loop.

The sketch is awesome, by the way.  But network connection aspects seem to fail online -- I had to download the .pde.
Re: help refining bounce mechanism
Reply #2 - May 25th, 2010, 3:54pm
 
Ok, I restructured the program so that they objects are in arrays, and the hover check and mouseOver event functions are now seperated from the main drawShape() function. Now the problem is if I'm hovering over the object shapeState1[0] and shapeState1[1] moves where my mouse is, it switches the mouseOver state to the higher object. I actually had achieved the same thing before, but this is also less than ideal.

Did you have something different in mind?

Code:
// check hover
for(int i = 7; i >= 0; i--) {
int whichHover = shapeState1[i].hover(100);
if (whichHover < 100) {
shapeState1[i].mouseOver(whichHover);
break;
}
}

// generate shapes/question
// float in: scale (irrelevant), positionX, positionY, small or no?, opacity
for(int i = 0; i < 8; i++) {
shapeState1[i].drawShape(0, 0, 0, false, opacity[i]);
}


http://oracloud.net/sketch13.pde
http://oracloud.net/

PS. Thanks! It didn't render in Firefox before -- I don't know if that's why you couldn't view online, but that's fixed now.
Re: help refining bounce mechanism
Reply #3 - May 27th, 2010, 3:52am
 
yep, works online now!  For the record, I'm using Safari on a PPC Mac running Tiger.

The new version seems a little better to me but I see what you mean about the multiple collisions.  The way I meant was: once a hit is found, and text is being displayed, no other words need to be checked until the mouse is moved away from the word that's been selected.  So they could move underneath, or bounce away if you prefer that visually.

Once a hit is found while looping through as you are now, it could be stored as an object (pointer), e.g. "shape hoverShape", and/or a boolean flagged that says "a hit has been found."  The mousecheck would in that case probably switch to an inverse:  if (!hoverShape.hover(100)), then tell the hoverShape word to move again, maybe set it to null, unflag the boolean, and resume checking hover-hits...
Re: help refining bounce mechanism
Reply #4 - May 27th, 2010, 9:44pm
 
Actually, I found a different solution. Basically it looks for whether the term has changed directions twice consecutively, then changes the direction back so it never jitters. I hadn't thought of each term being a seperate object. Basically I have one object that draws an entire shape. I see how something like that could work too, though, but I'm happy with this solution. Thanks for the help!
Page Index Toggle Pages: 1