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

Thread: Help needed desperately - Normal vectors and picking

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    6

    Help needed desperately - Normal vectors and picking

    Hi Everyone

    I have a question about OpenGL. I know how to find out the coordinate
    of the point when the mouse cursor is over it using gluUnProject() but
    i am wondering if there is a way in OpenGL that can help me find out
    the surface normal at that point as the cursor is moved?

    Any suggestion and comments will be MUCH appreciated.

    thank you in advance

    Sitara

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2002
    Location
    Espoo, Finland
    Posts
    599

    Re: Help needed desperately - Normal vectors and picking

    Well there are no really easy ways. Your options are:

    Find out which triangle has been clicked and interpolate it's normal at the position where the mouse is. You can do this easily using barycentric coordinates (search).

    The other option is to draw the scene by encoding normals into colors. The rgb value at each vertex should be (nx*0.5+0.5, ny*0.5+0.5, nz*0.5+0.5), gl will interpolate them for you. Then just read the color under the mouse and decode it. This could be an easier solution if you haven't implemented triangle picking, but it doesn't give as accurate results and is dependent on the user's color depth. I'd go with the first one.

    -Ilkka

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    6

    Re: Help needed desperately - Normal vectors and picking

    Hi,

    thank you for your reply

    I have used glquads to display a sin wave surface - does that work in the same way as triangles?

    do you know of any example code out there?

  4. #4
    Member Regular Contributor
    Join Date
    Feb 2002
    Location
    Hamburg, Germany
    Posts
    415

    Re: Help needed desperately - Normal vectors and picking

    Originally posted by Sitara:

    I have used glquads to display a sin wave surface - does that work in the same way as triangles?
    any quad can be created using two triangles.
    (quad: 0 1 2 3 -> tri1: 0 1 2, tri2 0 2 3)

Posting Permissions

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