A
A
Avery0072014-05-20 14:22:53
OpenGL
Avery007, 2014-05-20 14:22:53

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

2 answer(s)
M
Makaleks, 2014-06-02
@Avery007

so I move to the center

my_x=-x+app.width/2;
my_y=-app.height/2+y;
, where appis my structure that stores the height and width of the window, and int x,y;are variables with mouse coordinates
And if I understand correctly, you need to add width/2and height/2in the appropriate places

A
Alexey Kulakov, 2014-05-20
@carbon88

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 question

Ask a Question

731 491 924 answers to any question