Posted by
elect on
Feb 26, 2016; 8:28am
URL: https://forum.jogamp.org/SOLVED-mouse-input-tp3504609p4036357.html
Irene Tang wrote
Did you see that red rectangle? it is not in the same plane of the red cylinder. I want to draw a rectangle as a selection of a part of the red cyclinder. Do you have any ideas about this?
Yep, which projection type are you using?
When you unproject you have to pass the position in window space (x, y, z), x and y are easy, but what matters to you here is the depth value, that is z.
z ranges from 0 (near plane) to 1 (far plane). This means if click on p0 (x0, y0) and you unproject passing (x0, y0, 0) you will get the position of your click on the near plane in object space.
I guess the easiest way for you is to set boundaries when you are axis aligned. this means when you look at the red cylinder and the walls of the grid are either parallel or perpendicular to you.
Then you click on two points, one minimum p0 and one max p1. This defines a 3d space between (x0, y0, z0) and (x1, y1, z1), you may want to do this in world space.
Now, you can store this parameters in your program/shader and when you render, if your world space position
vec3 world(x, y, z)
fall between this range, that means if, and only if:
world.x > x0 && world.x < x1
&& world.y > y0 && world.y < y1
&& world.z > z0 && world.z < z1
then you are in the selected area and you will render your fragment based on your wishes