|
Author |
Topic: world to local coordinates (Read 291 times) |
|
theserge
|
world to local coordinates
« on: Dec 23rd, 2004, 10:08am » |
|
I am trying to pass the mouse coordinates to a button for a hit-test, but the button has been transformed (scaled and translated). Is there a simple way to convert mouseX and mouseY to the local coordinates of the button? Thanks!
|
|
|
|
st33d
|
Re: world to local coordinates
« Reply #1 on: Dec 23rd, 2004, 2:49pm » |
|
Convert mouseX and mouseY to the mouse button? I'm sorry but I don't understand. I've presented a travelling button below that scales. I didn't have to convert anything though. Perhaps you can say what it is you wanted to do in reference to this thing below. Code: //execute code and wave mouse over expanding square myButton one; //button is used by java void setup(){ size(400,400); one = new myButton(0.0); smooth(); framerate(24); } void loop(){ one.update(); } class myButton{ float x, y, sizeR; color c; myButton(float x){ this.x = x; y = 100; sizeR = 10; c = #FFFFFF; }//constructor; void update(){ background(0); x = (x + 0.5)%width; sizeR = (sizeR + 0.5)%40.0; if (overRect(mouseX, mouseY , x, y, x+sizeR, y+sizeR)){ c = #FF00FF; }else{ c = #FFFFFF; } fill (c); rect (x, y, sizeR, sizeR); }//void; }//class; boolean overRect(float xo, float yo, float x1, float y1, float x2, float y2){ if (xo >= x1 && xo <= x2 && yo >= y1 && yo <= y2) { return true; } else { return false; } } |
| At the least I hope it shows a different method.
|
I could murder a pint.
|
|
|
|