# Thread: Help needed desperately - Normal vectors and picking

1. ## 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.

Sitara

2. ## 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. ## Re: Help needed desperately - Normal vectors and picking

Hi,

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. ## 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
•