Psyko
YaBB Newbies
Offline
Posts: 5
cursor location with translate and rotation
Apr 15th , 2008, 8:39pm
hello, i'm working on a project with a large amount of words displayed inside a 3d scene. i'm trying to make a simple selection of a word when the user clicks on it. it sounds easy but when i rotate or translate my scene, the mouse position (mouseX and mouseY) doesn't match with the word position (x y, z), wich is normal, but i just don't know how to do it. actually, i'd need a method to convert the words positions in 2d and inside the display (like the mouse position)... the basic mousePressed function: void mousePressed() { if (mouseButton == LEFT){ float distance=10; for (int i = 0; i < wordNum; i++) { Word w = words[i]; float d = dist(mouseX, mouseY, w.x, w.y); if (d < distance) { selection = w; distance = d; } } if (selection != null) print(w.label); } } it works if i don't translate anything but when i do: translate(width/2,height/2,zoom); before displaying my words inside the draw loop, it doesn't work anymore... so i tried this: void mousePressed() { if (mouseButton == LEFT){ float distance=10; float newx=map(mouseX,0,width,-width/2,width/2); float newy=map(mouseY,0,height,-height/2,height/2); for (int i = 0; i < wordNum; i++) { Word w = words[i]; float d = dist(newx, newy, w.x, w.y); if (d < distance) { selection = w; distance = d; } } if (selection != null) print(w.label); } } if there is no z translation, it works, but i need some z translations and some rotations... help is welcome!!!!!