View Full Version : Get Normal and TextureCoordinate by mouse via ray picking?

Thank you for view this topic at first http://www.opengl.org/discussion_boards/ubb/smile.gif Maybe this isn't a advanced question,but it is really difficult for me,please help me.

I have useing gluUnProject() to get the vertex selected by mouse.Now i want to get the Normal and TextureCoordinate of this vertex.is there any easy way?

Jared

02-16-2004, 01:55 AM

of course its difficult for a beginner, but thats why there is a beginners section. that doesnt mean "only amateurs to answer your question" but "ask beginner questions here".

the function doesnt return a vertex, it returns a point you can use to build a ray that you can then use to check for intersection. there is no normal and no texture coordinate for this point.

Ysaneya

02-16-2004, 02:57 AM

Yeah it's annoying to see your name appear 4 times with 4 different, but basic questions, on the advanced board.

gluUnproject does not know anything about "vertices". It just returns a position in world space. You can then use it to generate a ray going from your camera "into the direction" of the pixel you clicked on, but then it's up to you to intersect this ray with your world polygons. This should give you a list of triangles along that ray, and the points of intersection (there can be multiple points, you can keep the nearest one only if you want). Then, use barycentric coordinates (for example the well known area trick) to get 3 weights, for each vertex of your triangle. Simply use these weights to interpolate the normal or the tex coords (or anything else).

Y.

I'm sorry for my poor English.

I know what i get via ray picking---it is a point with true x,y and z.

I also know the way:

"Then, use barycentric coordinates (for example the well known area trick) to get 3 weights, for each vertex of your triangle. Simply use these weights to interpolate the normal or the tex coords (or anything else).

"

What I want to get is a more EASY way.is anybody know?

Thanks Jared and Ysaneya also.

Yes,I have post 4 basic questions.

Ysaneya

02-17-2004, 04:07 AM

I'm sorry to say that this IS the easy way :) The trick is to perform fast scene/ray intersections, the rest is 30 lines of code, so i don't know how you could expect it to be more simple..

Y.

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.