# Thread: relationship between mouse position and coordinate and normal

1. ## relationship between mouse position and coordinate and normal

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.

2. ## Re: relationship between mouse position and coordinate and normal

Ehehe... try to use glUnProject to retrieve mouse 3d coordinates

Thanks!

4. ## Re: relationship between mouse position and coordinate and normal

And how about the normal?

5. ## Re: relationship between mouse position and coordinate and normal

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.

6. ## Re: relationship between mouse position and coordinate and normal

Any other ideas,plz?

7. ## Re: relationship between mouse position and coordinate and normal

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.

8. ## Re: relationship between mouse position and coordinate and normal

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.

9. ## Re: relationship between mouse position and coordinate and normal

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.

10. ## Re: relationship between mouse position and coordinate and normal

Thanks i dind't now that

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•