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: How to calcualte what viewport is pointing towards

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    8

    How to calcualte what viewport is pointing towards

    How to calculate what object or to what vertex or cordiante in the world geometry viewport is pointing towards?

    In other words how to get the point of touch to word geometry form middle of cameras view angle/direction effectively without very long calulation/comparsions
    Last edited by q13918; 06-03-2017 at 12:03 PM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,124
    If you're using an ordinary projection (orthographic or symmetric perspective projection), the ray down your eye-space -Z axis should be a pretty good indication. That's the vector (0,0,-1) originating at the point (0,0,0) in eye-space. Back-transform that to world-space if you need it there.

    If you're using an asymmetric perspective projection, this won't work well. In fact, the eye-space -Z axis may not even be in the view frustum. A better vector to use is general is one which shoots directly through the center of the frustum. For a perspective projection, that's vector ( (L+R)/2, (B+T)/2, -N ) from point (0,0,0) in eye-space. You'll notice this gives you the same answer as above for a symmetric perspective projection (once you normalize the direction vector).

    If you need to know more than that, you can easily compute the eye-space plane equations for the edges of your view frustum. Then back-transform those to world-space if you need them there. Or compute a specific ray through a specific point on your window.

Posting Permissions

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