Results 1 to 2 of 2

Thread: Mouse world coordinates?

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    1

    Mouse world coordinates?

    Hello,

    How do you get the world coordinates from the canvas coordinates( clientX, clientY ), without the use of third-party libraries?

    I've looked everywhere on how to do this but I cannot find a straight-forward explanation. I am very new to webgl and programming so please bare with me.

    Thanks.

  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    17

    Re: Mouse world coordinates?

    If i remember correctly, you take the inverse of the projectionview matrix and multiply it by the screen coordinates scaled to the range [-1.0, 1.0] and the z should be the 'near' value you specified to the glFrustum/gluPerspective (yes, they're not available in GLES but, you get the idea).

    So, some pseudo code would be:

    Code :
    vec4 worldCoordinates = inverseProjectionView * vec4(2.0 * clientX / clientWidth - 1.0, 2.0 * clientY / clientHeight - 1.0, near, 1.0)

    There's an article in the GPU Gems 3 about this issue when extracting world coordinates from a rendered image using the depth of the depth buffer as the z-value: http://developer.nvidia.com/node/184

    Oh and yes, there's no way extracting the inverse of the projectionview matrix, you will have to figure out the inverse of the matrix by reading the glFrustum/gluPerspective functions...

    Hope that helps!
    //Johan

Similar Threads

  1. Draw points with mouse coordinates
    By giotis in forum Developers Coding:Beginner
    Replies: 0
    Last Post: 12-08-2012, 03:24 AM
  2. Light in world coordinates
    By wglb in forum Developers Coding:Beginner
    Replies: 1
    Last Post: 01-28-2012, 09:16 AM

Posting Permissions

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