1

What I want to do

Picking an object.

Requirements / Conditions

  • My mouse is always in the center of the screen.
  • Pick only the first / nearest object

What I want to know

How can I convert my mouse coordinates (actually 0,0 since the mouse is locked to the mid) to world coordinates?

How do I get the actual view direction?

What I think I have to do

pseudo code

int mx,my = convert(Mouse.getX()), convert(Mouse.getY())
int mz = ??
int dx, dy, dz = ?? # direction of view
drawRay(mx, my, mz, 
        dx, dy, dz + 10) # 10 shall be the range to pick

# later check for intersections
boop
  • 7,413
  • 13
  • 50
  • 94
  • camera position + camera direction + fov + aspect ratio + near plane + basic geometry – dari Jul 24 '14 at 23:26
  • 1
    In your case, it might be worth checking out [color-based mouse picking](http://content.gpwiki.org/index.php/OpenGL_Selection_Using_Unique_Color_IDs). Otherwise, take a look at the [source code of gluUnproject](http://www.opengl.org/wiki/GluProject_and_gluUnProject_code) – vesan Jul 25 '14 at 03:44

0 Answers0