in opengl context, have seen possible convert mouse coordinates 3d world coordinates (e.g. mfc opengl 3d coordinate 2d coordinate of mouse). however, not work when have set of glpoint
s , lots of empty space: when i'm hovering mouse on empty space, 3d coordinates have no meaning.
how can coordinates of nearest 3d point mouse position?
recognize "unprojecting" 2d mouse coordinates 3d world requires additional information. 2d position on screen corresponds infinite number of points along line, near plane far plane in 3d. means 3d point, need provide depth value well.
the gluunproject
function convenient way of doing , provides parameter winz
. 0.0 find 3d point @ near plane , 1.0 find @ far plane.
gluunproject(winx, winy, winz, model, proj, view, objx, objy, objz);
note: if gluunproject
not available can figure out same thing pretty matrices)
when mouse used interact 3d objects depth value typically found sampling depth buffer, or intersecting ray scene geometry, or primitive (such sphere or box). if objective interact points, use sphere around each point. if want 3d point "somewhere out there" decide on depth value (maybe 0.0 on near plane or 0.5 - halfway between near , far plane).