Answer the question
In order to leave comments, you need to log in
How to translate mouse coordinates received by glutMouseFunc to OpenGL coordinates?
The OpenGL origin is from the bottom left corner and the mouse position given by glutMouseFunc is from the top left corner, I need to convert the glutMouseFunc coordinates to OpenGL.
Answer the question
In order to leave comments, you need to log in
so I move to the center
my_x=-x+app.width/2;
my_y=-app.height/2+y;
, where app
is my structure that stores the height and width of the window, and int x,y;
are variables with mouse coordinates width/2
and height/2
in the appropriate places
if the units of measurement are comparable and the dimension of the scale is the same. that is, the upper left corner in the first case is 0. and in the second - X and the lower left in the first case is X, and in the second 0, then you can simply do
X - currentXPositionOfMouse for translation,
otherwise you will probably need to enter a certain coefficient.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question