Advanced picking ??
I''ve read somewhere else on this board how you can use OpenGl functionality to determine on which object the user is clicking.
I now need something a bit more advanced then just getting the selected object. What I want to do is create a line in 3d space from the point of the camera in the direction where the user clicked. So if you look from the camera you would only see a point.
I want this line in the form ''l = v1 + k * v2'' where v1 and v2 are vectors. v1 ofcourse would just be the position of the camera and v2 would be the direction vector which is a lot harder to obtain.
I''ve allready tried some ideas non of which really worked.
So if someone could give me some pointers I''d be really gratefull.
Prosser: But the plans were on display.Arthur Dent: On display? I eventually had to go down to the cellar.Prosser: That's the display department.Arthur Dent: With a torch.Prosser: The lights had probably gone.Arthur Dent: So had the stairs.Prosser: But you did see the notice, didn't you?Arthur Dent: Oh, yes. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign outside the door saying "Beware of the Leopard." Ever thought of going into advertising?
Run your 2D screen point backwards through the OpenGL transformation pipeline and that will give you a point in 3D space. Look in the Redbook for this, it has an overview of what goes on. Getting the exact place where the user clicked in the world will be a bit harder since you don''t know the Z coordinate of the point, just X and Y. There are a ton of different ways that I can think of to come up with the Z portion, but a lot of it has to do with what you are working with.
Nate Miller
http://nate.scuzzy.net
Nate Miller
http://nate.scuzzy.net
read the depth buffer with readpixels to get the depth part.
"where v1 and v2 are vectors. v1 ofcourse would just be the position of the camera and v2 would be the direction vector which is a lot harder to obtain."
im crap in maths but v1(camera) - object = the vector between them ie v2
http://members.xoom.com/myBollux
"where v1 and v2 are vectors. v1 ofcourse would just be the position of the camera and v2 would be the direction vector which is a lot harder to obtain."
im crap in maths but v1(camera) - object = the vector between them ie v2
http://members.xoom.com/myBollux
thanks for the response guys, but I have managed to do it another way...
I've done it sort of in the following way (hope this comes out right):
...........***|.
........***...|.
....***.......|.
..**..........|.This is the 'virtual screen' for which you could
.*#####.......|.in theorie take any value but you need to keep
.|**...#####..|.it square.
.|..***.....##|.
.|......***...|.
.|.........***|.
.|..............
.v..............
This point is the position of the camera this is the postion of v1 (position vector). The lines radiating from this point is the viewing frustum. The ### is the needed direction vector. Now you calculate the distance from the camera point to the 'virtual screen' by using the FOV angle. The z coordinate is now this distance. For the x and y you do the following taking the x as an example:
dir.x = ( (mouseX - 0.5f * windowWidth)/(windowWidth - 0.5f * windowWidth) ) * winWidth;
do the same for y then normalize the result. Now you have to manualy rotate the vector to get it properly alligned in the world. And that's it.
[EDIT: sorry for all the points, but it would collapse the spaces other wise ]
Edited by - mars_888 on October 28, 2000 3:32:58 PM
I've done it sort of in the following way (hope this comes out right):
...........***|.
........***...|.
....***.......|.
..**..........|.This is the 'virtual screen' for which you could
.*#####.......|.in theorie take any value but you need to keep
.|**...#####..|.it square.
.|..***.....##|.
.|......***...|.
.|.........***|.
.|..............
.v..............
This point is the position of the camera this is the postion of v1 (position vector). The lines radiating from this point is the viewing frustum. The ### is the needed direction vector. Now you calculate the distance from the camera point to the 'virtual screen' by using the FOV angle. The z coordinate is now this distance. For the x and y you do the following taking the x as an example:
dir.x = ( (mouseX - 0.5f * windowWidth)/(windowWidth - 0.5f * windowWidth) ) * winWidth;
do the same for y then normalize the result. Now you have to manualy rotate the vector to get it properly alligned in the world. And that's it.
[EDIT: sorry for all the points, but it would collapse the spaces other wise ]
Edited by - mars_888 on October 28, 2000 3:32:58 PM
Prosser: But the plans were on display.Arthur Dent: On display? I eventually had to go down to the cellar.Prosser: That's the display department.Arthur Dent: With a torch.Prosser: The lights had probably gone.Arthur Dent: So had the stairs.Prosser: But you did see the notice, didn't you?Arthur Dent: Oh, yes. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign outside the door saying "Beware of the Leopard." Ever thought of going into advertising?
use a
http://members.xoom.com/myBollux
block to ratain the spaces (view the page source) http://members.xoom.com/myBollux
Thanks for the tip. But maybe this will work even better:
Now you just normalize the vector and manually rotate it acording to the rotation of the camera.
I hope this makes sense and if anybody wants to know some more of the details or even see the sourcecode please ask.
[EDIT: my html is a bit rusty ]
Edited by - mars_888 on October 29, 2000 5:58:57 PM
Edited by - mars_888 on October 29, 2000 5:59:28 PM
Now you just normalize the vector and manually rotate it acording to the rotation of the camera.
I hope this makes sense and if anybody wants to know some more of the details or even see the sourcecode please ask.
[EDIT: my html is a bit rusty ]
Edited by - mars_888 on October 29, 2000 5:58:57 PM
Edited by - mars_888 on October 29, 2000 5:59:28 PM
Prosser: But the plans were on display.Arthur Dent: On display? I eventually had to go down to the cellar.Prosser: That's the display department.Arthur Dent: With a torch.Prosser: The lights had probably gone.Arthur Dent: So had the stairs.Prosser: But you did see the notice, didn't you?Arthur Dent: Oh, yes. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign outside the door saying "Beware of the Leopard." Ever thought of going into advertising?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement