Triangle picking
Hi, I've managed to perform triangle picking with gluProject by projecting the vertices to the window area and then checing these with the mouse coordinates. A problem arises, when any of these points lies beyond the window region. In this scenario I'm not able to pick a triangle even though it is partially visible.
So the only way to handle this situation afaik is to unproject the mouse point and then do a line-triangle intersection test. I've tried to use gluUnproject to unproject the mouse position and then make a line by adding the camera direction to this point, but then i realized it can't be done this way. The line will just extend nearly from the centre of the screen. I hope you understand what I'm trying to achieve here, any help is welcome.
Quote:Original post by jmakitaloThat's close, what you need instead of a ray from the mouse position in the same direction as the camera is a ray from the camera that goes through the mouse position. You do something like this...
...
I've tried to use gluUnproject to unproject the mouse position and then make a line by adding the camera direction to this point, but then i realized it can't be done this way. The line will just extend nearly from the centre of the screen.
...
// (winx, winy) is the position of the mouse in window coordinates// this will get the position of the mouse at the near plane (winz=0)// it doesn't really matter what you use for winz since the ray will go through any (every) point gluUnproject(winx, winy, 0.0, model, proj, view, &mousePos.x, &mousePos.y, &mousePos.z);// Origin of the ray is just the camera positionVec3 rayOrigin = camPos;// Direction of the ray is the vector from the camera position to the mouse positionVec3 rayDirection = mousePos - camPos;
Now you can use that ray in your ray-<whatever> intersection test.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement