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

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 (nx0.5+0.5, ny0.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

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?

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)