PDA

View Full Version : relationship between mouse position and coordinate and normal



ljz
12-25-2002, 06:01 AM
I want to do something like this:
when the mouse moves upon a model rendered with openGL, the x,y,x coordinates and normal of the point on the model should be displayed. That is, how to convert from mouse position on the screen to the x,y,x coordinates and how to get the normal of this point?
Thanks for your direction in advance.

Dexter
12-25-2002, 12:34 PM
Ehehe... try to use glUnProject to retrieve mouse 3d coordinates

ljz
12-30-2002, 06:12 PM
Thanks!

ljz
01-09-2003, 06:39 PM
And how about the normal?

Ysaneya
01-10-2003, 12:06 AM
With gluUnProject you can get the position of your pixel in the world, and create a ray from your view position to this pixel. Now you can cast this ray with your world geometry to determine which triangle is hit, and get the intersection point and normal. All you need is a fast ray/triangle intersection function.

Y.

ljz
02-16-2003, 11:05 PM
Any other ideas,plz?

rgpc
02-17-2003, 12:07 AM
Originally posted by ljz:
Any other ideas,plz?

Oh dear, another Shanedudddy...

Ysaneya has given you the best answer. Implementing it will teach you a great deal about 3d intersections/transformations that will prove invaluable with more advanced 3d development.

Buffalo
02-17-2003, 05:58 AM
And don't forget that the Mouse y Corrdinate muss be inverted,since the OpenGL uses the left bottom corner and not the left upper.

V-man
02-18-2003, 10:25 AM
Originally posted by Buffalo:
And don't forget that the Mouse y Corrdinate muss be inverted,since the OpenGL uses the left bottom corner and not the left upper.

It does if you say it does. You can always exhange top and bottom you provide to glFrustum or glOrtho or whatever else you use.

Buffalo
02-18-2003, 01:54 PM
Thanks i dind't now that