PDA

View Full Version : Help needed desperately - Normal vectors and picking



Sitara
08-28-2003, 06:45 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

Sitara

JustHanging
08-28-2003, 11:34 PM
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

Sitara
08-29-2003, 05:31 AM
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?

AdrianD
08-29-2003, 05:55 AM
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)