Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I don't want it to be transformed, instead I want it to appear as flat 2D label that always faces the camera and remains the same size on the screen at all times. However, if it is hidden behind something I want it to appear hidden.</p> </blockquote> <p>First, you should have put <em>that</em> in your question; it explains far more about what you're trying to do than your question.</p> <p>To achieve this, what you need to do is find the z-coordinate in the orthographic projection that matches the z-coordinate in pre-projective space of where you want the label to appear.</p> <p>When you used <code>gluProject</code>, you got <em>three</em> coordinates back. The Z coordinate is important. What you need to do is reverse-transform the Z coordinate based on the zNear and zFar values you give to <code>glOrtho</code>.</p> <p><strong>Pedantic note:</strong> <code>gluProject</code> doesn't transform the Z coordinate to window space. To do so, it would have to take the <code>glDepthRange</code> parameters. What it really does is assume a depth range of near = 0.0 and far = 1.0.</p> <p>So our first step is to transform from window space Z to normalized device coordinate (NDC) space Z. We use this simple equation:</p> <pre><code>ndcZ = (2 * winZ) - 1 </code></pre> <p>Simple enough. Now, we need to go to clip space. Which is a no-op, because with an orthographic projection, the W coordinate is assumed to be 1.0. And the division by W is the difference between clip space and NDC space.</p> <pre><code>clipZ = ndcZ </code></pre> <p>But we don't need clip space Z. We need pre-orthographic projection space Z (aka: camera space Z). And that requires the zNear and zFar parameters you gave to <code>glOrtho</code>. To get to camera space, we do this:</p> <pre><code>cameraZ = ((clipZ + (zFar + zNear)/(zFar - zNear)) * (zFar - zNear))/-2 </code></pre> <p>And you're done. Use that Z position in your rendering. Oh, and make sure your modelview matrix doesn't include any transforms in the Z direction (unless you're using the modelview matrix to apply this Z position to the label, which is fine).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload