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

Thread: Specification Understanding difficulty

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    4

    Exclamation Specification Understanding difficulty

    Good Evening everybody.

    I am currently re encoding opengl 1.5 and a problem appears with the light process.

    On the specification there is a blurry part :

    if P 1 and P 2 are (homogeneous, with four coordinates) points then let P1 P 2 be the unit vector that points from P1 to P2 .

    Note that if P2 has a zero w coordinate and P1 has non-zero w coordinate, then P1 P2 is the unit vector corresponding to the direction specified by the x, y, and z coordinates of P2 ; if P1 has a zero w coordinate and P2 has a non-zero w coordinate then P1 P2 is the unit vector that is the negative of that corresponding to the direction specified by P1 . If both P1 and P2 have zero w coordinates, then P1 P2 is the unit vector obtained by normalizing the direction corresponding to P2 − P1 .

    I guess that if a something has 0 w coordinate, it is a direction, otherwise it is a position (Isn't it ? there is very important)
    Does it mean that if i have two vertex , one for my triangle position P1(2, 4, 6, 1) and another for the light position P2(1, 5, 9, 0),
    if i have to compute the vertex P1P2, then i will only considere that P1P2 is P1P2(1, 5, 9, 0) and i will have to normalize it ?

    Is the mindset to consider that something that is not a direction is a position , and above all that :
    2 positions stay a position, 2 direction stay a direction , a direction and a position is a direction ?


    I expect that my questions were clear, but it is really important to me to understand it.

    Thank for your time passed to my post.

    zuraneur.

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214
    [QUOTE=zuraneur;1262944]
    if P 1 and P 2 are (homogeneous, with four coordinates) points then let P1 P 2 be the unit vector that points from P1 to P2 .
    [\QUOTE]
    P2-P1 is a vector from point P1 to point P2.

    [QUOTE=zuraneur;1262944]Note that if P2 has a zero w coordinate...[\QUOTE]
    Then P2 is not a point, but a vector (a direction)!

    Quote Originally Posted by zuraneur View Post
    I guess that if a something has 0 w coordinate, it is a direction, otherwise it is a position (Isn't it ? there is very important)
    Yes it is.

    Quote Originally Posted by zuraneur View Post
    Does it mean that if i have two vertex , one for my triangle position P1(2, 4, 6, 1) and another for the light position P2(1, 5, 9, 0),
    if i have to compute the vertex P1P2, then i will only considere that P1P2 is P1P2(1, 5, 9, 0) and i will have to normalize it ?
    I don't understand what you want to achieve? P2 is not a vertex. Formally, P1P2=P2-P2=(1, 5, 9, 0)-(2, 4, 6, 1)=(-1, 1, 3, -1). In Cartesian coordinate system, that point has coordinates (1,-1,-3).

    Quote Originally Posted by zuraneur View Post
    Is the mindset to consider that something that is not a direction is a position , and above all that :
    2 positions stay a position, 2 direction stay a direction , a direction and a position is a direction ?
    As you can see from the previous calculation, a position and direction give a position.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    4
    Hello Aleksandar and thank you for your answer.

    [QUOTE=Aleksandar;1262947]
    Quote Originally Posted by zuraneur View Post
    if P 1 and P 2 are (homogeneous, with four coordinates) points then let P1 P 2 be the unit vector that points from P1 to P2 .
    [\QUOTE]
    P2-P1 is a vector from point P1 to point P2.

    I don't understand what you want to achieve? P2 is not a vertex. Formally, P1P2=P2-P2=(1, 5, 9, 0)-(2, 4, 6, 1)=(-1, 1, 3, -1). In Cartesian coordinate system, that point has coordinates (1,-1,-3).
    I'm trying to translate what the specification tell me to do when I have to compute a vector such as P1P2 on lighting formula.
    For example, my highlight point position is P1 (1, 2, 3, 1) and my light has a parameter "position" with four coordinates, so it involve that his w coordinate will always be 1 because that's a position parameters.

    But users can change fours of them, so my light "position" could become a direction.

    That's why opengl specification told me how to react if i have to compute a position and a direction.
    That's what I don't understand.
    According to specification :
    Note that if P2 has a zero w coordinate and P1 has non-zero w coordinate, then P1 P2 is the unit vector corresponding to the direction specified by the x, y, and z coordinates of P2
    Does it means that if i have to build a vector with a position and a direction, then i will only build my result with direction coordinates ?
    It is what the previous sentence means to me, but i must be wrong.

    That's why I told you with position P1(1, 2, 3, 1), and direction P2(4, 5, 6, 0), If i build P1P2, i will just have P1P2(4, 5, 6, 0).

    I expect you could enlighten me.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,402
    Quote Originally Posted by zuraneur View Post
    Does it means that if i have to build a vector with a position and a direction, then i will only build my result with direction coordinates ?
    For homogeneous vectors P1 and P2, the direction from P1 to P2 is defined as
    Code :
    D = P2/P2.w - P1/P1.w

    In the case where a vector has a zero w component, the division cannot be performed. However, we can take account of the fact that scaling all four components of a homogeneous vector by the same factor doesn't change the Euclidean vector which it represents, and convert the above to:
    Code :
    D' = P1.w*P2.w*D = P1.w*P2 - P2.w*P1
    Now, we no longer need to perform division, only multiplication. If either vector's w component is zero, that vector disappears from the equation, and we're left with either P1 (if P2.w is zero) or -P2 (if P1.w is zero).

    So, what the specification is saying is that the direction is defined as:
    Code :
    // calculate direction from P1 to P2, i.e. P2-P1
    vec4 direction(vec4 P1, vec4 P2)
    {
        if (P1.w == 0 && P2.w == 0)
            return P2 - P1;
        else if (P2.w == 0)
            return P2;
        else if (P1.w == 0)
            return -P1;
        else
            return P2/P2.w - P1/P1.w;
    }
    Note that in all four cases, the result will have w equal to zero (in the last case, both operands to the subtraction will have w equal to 1).

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    4
    Thanks a lot for these answers, they really make me aware that I have to study what projection geometry really are, then I can continue to code to implement light.

    Gentlemen, have a nice day.

Posting Permissions

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