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 2 of 2

Thread: the TRUE z-value, how can I compute it out?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2001
    Location
    us
    Posts
    22

    the TRUE z-value, how can I compute it out?

    It's said the z-value stored in OpenGl is between [0, 1] and it is converted by the following equation:
    z' = (-(f+n)/(f-n))*z - (2fn/(f-n))*w.

    That means, the TRUE z value is inverse of the equation:
    z=-(f-n)/(f+n)*z' - 2fn/(f+n)*w,
    where z' is between [0,1].
    Is that right?

    Also, can I assume w=1.0 always?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Adelaide, South Australia, Australia
    Posts
    839

    Re: the TRUE z-value, how can I compute it out?

    okay, now i see what you're getting at. but i'm not sure about the validity of your equation, there. but i'm guessing you realise it's the third row of the equation multiplied by the vector, DIVIDED by the fourth row of the equatiojn, multipled by the vector. does this make sense? recapping the w co-ordinate:

    if P is our projection matrix, and v and v' is the vertex and its projection respectively, then

    v' = P v

    ie.

    [ x' y' z' w'] ' = P [ x y z w ] '

    (where ' on the vector is the transpose op and ' on the scalar indicates the projected coordinate).

    now, to convert the homogeneous projected vector into a cartesian projected vector, then

    z.cartesian = z' / w'

    because we divide by w... so.... getting back to your equation: you multiply the third row of P by the vector (to get z') and divide it by the fourth row of P by the vector (to get w').

    so, then, what's w? well, in this case, then yes---you CAN simply set w to equal 1.0.

    hope this helps,

    cheers ,
    John

Posting Permissions

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