Search code examples
delphiopengldirectxglscene

Delphi - GLScene how to get x,y,z of a picked object


I have a scene with basic geometry (pick demo) I want when I select any object to return the x,y and z of the mouse cursor otherwise return -1


Solution

  • The general OpenGL technique is to use gluUnProject() which takes screen x,y and the z-value of the depth-buffer and reverse-transforms that into world (or view) coordinates.

    gluUnProject maps the specified window coordinates into object coordinates using model, proj, and view. The result is stored in objX, objY, and objZ. A return value of GLU_TRUE indicates success; a return value of GLU_FALSE indicates failure.

    See NeHe's tutorial on how to use it in a general OpenGL app. It should hopefully get you started in the right direction with your Delphi app.