3D Scene transformations not quite working

后端 未结 1 955
無奈伤痛
無奈伤痛 2020-12-22 11:43

In an attempt to convert screen space coordinates into world space coordinates, I\'ve been doing the following calculation:

WorldSpace Vector = inverse(Projection M

1条回答
  •  生来不讨喜
    2020-12-22 12:42

    In this last stage of my ray picking problem, I was informed that I was doing several things wrong:

    1. My z coordinate for a window space near plane should be -1, not 0
    2. Reminder that I need 2 separate vectors at the opposing planes, don't just use 1 for testing, run it through the actual ray picker to see if it works.
    3. Use a "w" value of 1, not 0. This is the last spot of the glm::vec4 wSC = (mat) * glm::vec4(winX,winY,0,0); line.
    4. That I need to convert my mouse coordinates into NDC coordinates before performing any calculations, so this is:
      • divide mouse x by screen width, times 2, minus 1.
      • subtract mouse y from screen height, divide by screen height, times 2, minus 1: winX = ((float)x/viewport[2]*2)-1; winY = ((float)(viewport[3]-y)/viewport[3]*2)-1;

    Since my problem extended over quite a great length of time, and took up several questions, I owe credit to a few individuals who helped me along the way:

    • srobins of facepunch, in this thread
    • derhass from here, in this question, and this discussion

    0 讨论(0)
提交回复
热议问题