🔒 Locked
Picking
Advertisement
Original Post
Does anyone have any links or explanations of the process of 3D picking without using any API specific stuff and without projecting everything in question and checking it against the mouse in screen space (that is, picking in 3D view space and not 2D screen space)?
I''ve searched, but found nothing terribly useful.
Thanks!
Maybe I should be more specific. Previously responded-to topics seem to say that you must cast a ray from the camera position through the world space position of the cursor, obtained via unprojection. But how is one supposed to choose the z coordinate of the mouse cursor in order to correctly unproject it?
This is the classic problem. You can''t. Your best bet is probably just to test which objects the ray hits and choose the nearest one.
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
No, I know that. But I mean that in order to unproject the cursor position you need to choose a z value for it, in order to get the direction vector for the ray.
I know that you have to just test to find the nearest intersection, but what z value should be chosen simply to unproject the point?
eg: what should be used for the 'winz' value in
int gluUnProject(
GLdouble winx,
GLdouble winy,
GLdouble winz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *objx,
GLdouble *objy,
GLdouble *objz
);
assuming the 'winx' and 'winy' values are the mouse x and y coordinates in OGL window coordinates.
[edited by - Qoy on April 10, 2002 6:41:38 PM]
I know that you have to just test to find the nearest intersection, but what z value should be chosen simply to unproject the point?
eg: what should be used for the 'winz' value in
int gluUnProject(
GLdouble winx,
GLdouble winy,
GLdouble winz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *objx,
GLdouble *objy,
GLdouble *objz
);
assuming the 'winx' and 'winy' values are the mouse x and y coordinates in OGL window coordinates.
[edited by - Qoy on April 10, 2002 6:41:38 PM]
I''m using a ray from (0,0,0) through (xm,ym,1) where xm and ym are the unprojected mouse-coords using z=1 as the z-value. In my engine, this works 100% correct. I''m able to pick polygons that are one pixel in size with this method...which i find quite astonishing myself....
Shouldn''t the z value be ((SCREEN_WIDTH/2)/tan(FOV/2))?
Doesn't the formular above calculates the z-value of a point onto the left or right viewfrustum-plane which x-value is +/- screenwidth/2? I don't get how this should be usefull here...could you please explain!?!
After thinking some more about the topic, i came to the conclusion that Z doesn't matter. When reprojection xm and ym back into 3D, you are basically calculating which x3d and y3d values a point with a z-value of foo should have to be projected onto the selected point in 2d. As Anonymous said: You are just changing the length of the vector, which doesn't matter at all. I verified this thesis by using 100430.2727
as the value for Z and it still works like a charm.
[edited by - EgonOlsen on April 16, 2002 6:24:38 PM]
After thinking some more about the topic, i came to the conclusion that Z doesn't matter. When reprojection xm and ym back into 3D, you are basically calculating which x3d and y3d values a point with a z-value of foo should have to be projected onto the selected point in 2d. As Anonymous said: You are just changing the length of the vector, which doesn't matter at all. I verified this thesis by using 100430.2727
[edited by - EgonOlsen on April 16, 2002 6:24:38 PM]
I meant the value of the z component of the vector. The z component of the vector is irrelevant only if the x and y components are zero. Look at this:
In each case, I''m referring to the vector defined by the dotted line. In both, the x value is the same (3) but the orientations of the vectors are clearly different because their z values are different.
Of course, since you changed the value and it worked fine, I''m led to believe that either...
A - When I speak of z values I mean one thing but when you do your mean something else
OR
B - There is something seriously flawed with my understanding of how you generate rays for raytracing.
Right now, either one is a possibility.
.|
. | x
.__|
z
versus...
.
. |
. | x
.___________|
z
In each case, I''m referring to the vector defined by the dotted line. In both, the x value is the same (3) but the orientations of the vectors are clearly different because their z values are different.
Of course, since you changed the value and it worked fine, I''m led to believe that either...
A - When I speak of z values I mean one thing but when you do your mean something else
OR
B - There is something seriously flawed with my understanding of how you generate rays for raytracing.
Right now, either one is a possibility.
quote:Yes, but these two points won''t be projected onto the same 2d point then, because (as you said) z is different but x stays the same.
Original post by TerranFury
In each case, I''m referring to the vector defined by the dotted line. In both, the x value is the same (3) but the orientations of the vectors are clearly different because their z values are different.
It''s hard to explain what i mean...well, i''ll try to...
The ray (vector) you are looking for is a vector of which every point in 3d will be projected onto the same point in 2d. In other words: Take any point (x/y/z) that can be defined by multiplying a constant to this vector (i.e. that lies within the ray), project it into 2d (i.e. on screen) and it will fall onto the same point. This point is the point that you are clicking on with the mouse-pointer. If you do, you''ll get xm and ym (in 2d). Now reproject them into 3d using any Z-value you like and you get a point (xm'',ym'', z). This point will always be a point like i described above (i.e. a point where the ray goes through). Therefor, z doesn''t matter. For different z-values, you''ll of course get different xm'' and ym'' values...but projected back again into 2d, all possible values will result into xm and ym...and that''s where you have clicked.
I tried my best, but i don''t think that i did a good job in explaining it...
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement