Sign in to follow this  

Triangle picking

This topic is 4304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Quote:
Original post by jmakitalo
...
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.
...
That'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...
// (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 position
Vec3 rayOrigin = camPos;

// Direction of the ray is the vector from the camera position to the mouse position
Vec3 rayDirection = mousePos - camPos;
Now you can use that ray in your ray-<whatever> intersection test.

Share this post


Link to post
Share on other sites

This topic is 4304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this