Jump to content
  • Advertisement
Sign in to follow this  
Alessandro

OpenGL opengl picking with gluproject: one issue to solve

This topic is 2527 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

I do opengl picking by using gluproject on all the triangle of a mesh, and testing the projected window coordinates against the mouse position.

It works fine, except the fact that it will gather all points regardless of their depth.

So, for example, if you have a cube facing the camera, clicking on a triangle will return 2 picked triangles (one facing, one backfacing).

What could I use to discard the farthest picked triangle? Casting a ray from the camera and test which of those two triangles is closest ?

Share this post


Link to post
Share on other sites
Advertisement
Furthermore, typically if you are casting rays against triangles, you might have your space split up into a bsp(grid) etc. You decide which grid the camera is in or closest to, and then check the closest grids first until you hit a triangle, if not, keep checking.

< |....|.^. |.....|..^..|....|
.....1...2...3....4...5

(camera on left, empty grid, triangle, empty grid, triangle, empty grid)
Space 1 has no triangles, space 2 has 1 and it hits, return because it is the closest triangle, no need to go to 3,4,5 spaces.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!