Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QGLViewer - Depthbuffer z distance
QtWS25 Last Chance

QGLViewer - Depthbuffer z distance

Scheduled Pinned Locked Moved 3rd Party Software
2 Posts 1 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    techean
    wrote on 9 Mar 2012, 19:39 last edited by
    #1

    Hi, I'm to use Depthbuffer to retrieve the Z distance of objets in my OpenGl scene using QglViewer.
    I'm using the following code:
    glReadPixels(nStartX, nStartY, nWidth, nHeight, GL_DEPTH_COMPONENT, GL_FLOAT, f_Depth);
    This retrieves the Depth Component.
    BUT I'm reading on http://www.opengl.org/resources/faq/technical/depthbuffer.htm
    "The depth buffer precision in eye coordinates is strongly affected by the ratio of zFar to zNear, the zFar clipping plane, and how far an object is from the zNear clipping plane."
    So, this make that my Depth Value are not linear. So I can't use theses values the have a real Z matrix of the scene.
    This cause many problem since I can't set a "unit" to these value.

    My usage is to use these Depth Matrix to use the technology SLAM(Simultaneous localization and mapping )
    So I need real distance in the matrix, not perspective value that mean nothing.

    If anyone have any idea to retrieve the good Z value of the pixel, I would be so happy.

    The first link I gave explain in some way how the calcul is done, but I'm not able to understand the functions given and how to retrieve the REAL Z distance...

    Thanks!!!!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      techean
      wrote on 9 Mar 2012, 22:03 last edited by
      #2

      I finally found the answers after a couple of hours of googling:
      bufferToCamera[zb_, near_, far_] := far * near / (zb * (far - near) - far);
      where zb = z from buffer
      bufferToCamera= z from camera
      http://olivers.posterous.com/linear-depth-in-glsl-for-real

      1 Reply Last reply
      0

      1/2

      9 Mar 2012, 19:39

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved