p5js-screenPosition icon indicating copy to clipboard operation
p5js-screenPosition copied to clipboard

Correspondence of x,y co-ordinate of 3D cube into x,y co -ordinate in 2D canvas ?

Open timtensor opened this issue 3 years ago • 1 comments

Hello , thanks for this library implementation. I had a doubt on the implementation with regards to finding corresponding co-ordinates in the 2D canvas. In the sketch below , I have used p5js screen position as suggested. The idea is to have a new cube appear when the x, y position of the mouse is inside the cube. (that is within the x,y co -ordinate of the cube) . However , i am not able to achieve that , I also reset the center position to (0,0,0) for a new co-ordinate system . I am wondering if you give me some pointers on this . The link to the sketch is here Sketch

timtensor avatar Apr 14 '22 08:04 timtensor

Hello @timtensor, you could use this function for hit testing of the cube, but you should calculate the screen positions of two of the front corners of the cube. That would look somehow like this:

ScreenPosition1 = screenPosition(-40,-40,40);
ScreenPosition2 = screenPosition(40,40,40);

Then you could check if mouseX is between ScreenPosition1.x and ScreenPosition2.x and the same with the y-coordinates.

bohnacker avatar Apr 19 '22 07:04 bohnacker