Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Get 3d-coordinates of cursor

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    2

    Get 3d-coordinates of cursor

    Hello,

    I'd like to get the coordinates of cursor (x,y,z).
    I use glReadPixels() with DEPTH_COMPONENT and gluUnproject() functions. The method returns correct result when cursor is over a 3d-vertex (or over some other object). But when it isn't over any object I cannot use this method because glReadPixels() always assigns Z to 1 (z=1 as result). Are there any ways to get 3d - coordinates of cursor if it isn't over any object ( it's pointing to nothing, plane)?

    I need this to move 3d-vertex by mouse (with changing it's World x,y and z coordinates). I'll be very happy if anybody help me with this problem.

    (sorry for my English)

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    Quote Originally Posted by ukrainian)) View Post
    But when it isn't over any object I cannot use this method because glReadPixels() always assigns Z to 1 (z=1 as result). Are there any ways to get 3d - coordinates of cursor if it isn't over any object ( it's pointing to nothing, plane)?
    What would you expect to get back when you're over an area for which you have not drawn any 3D object?

    You're getting back the far clip value (i.e. 1, assuming you leave glDepthRange to the default 0..1 range). Which is exactly what you likely "drew" in there when you cleared the depth buffer. If you want a 3D coordinate for all pixels, ensure that you draw something (e.g. a 3D backdrop) over your entire window.

  3. #3
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    2
    Quote Originally Posted by Dark Photon View Post
    If you want a 3D coordinate for all pixels, ensure that you draw something (e.g. a 3D backdrop) over your entire window.
    Thank you, but which 3d shape should I use as a background to provide getting correct value of Z?
    For example we have a 3d point. When we move it right we expect it's X coordinate to increase (from x1 to x1+m), and Z, Y must not change. But if we use an empty hemisphere as a background and move point right, Z coordinate changes it's value.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    Quote Originally Posted by ukrainian)) View Post
    Thank you, but which 3d shape should I use as a background to provide getting correct value of Z?
    Correct is defined by you. So whatever shape you want that you judge to provide "correct" Z values for your use case.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •