mouse coordinates to opengl

Started by
2 comments, last by Four 18 years, 11 months ago
How may I get the coordinates of mouse to opengl coordinates. I looked at a tutorial on Nehe, it works but the problem is, it only works properly when the viewport is the entire screen. Thanks in advance!
Advertisement
Hi,
Make sure you do this somthing like this:

Mouse_coord_in_ogl_Y= Window_Height-Mouse_Y_position
Mouse_Y_position=this the Coord for the mouse that you get it from HIWORD() (if you use windows.h)
Maybe not exactly related, but still.
I wonder how in theory the Mouse-OpenGL coordinate translation works.
Nouse coordinate is a point in 2D space, so that would give me a line in 3D space, right? If I remember correctly, there is a GLU function that does the translation, but what does it give you? The line formula, or a point on the line (and which point, if so)?
Thank you!

The mistake I made is when trying to get where point is in opengl coordinates is that, before doing anything from the very begining once I get the coordinates of the mouse I should revert the y coordinates to be (0,0) at lower left corner(height-y).

Seroja said:
Maybe not exactly related, but still.
I wonder how in theory the Mouse-OpenGL coordinate translation works.
Nouse coordinate is a point in 2D space, so that would give me a line in 3D space, right? If I remember correctly, there is a GLU function that does the translation, but what does it give you? The line formula, or a point on the line (and which point, if so)?


The function is gluUnProject, I don't know how it works too, it would be very interesting to hear. gluUnProject gives a point on the line.

This topic is closed to new replies.

Advertisement