Help with glutPassiveMotionFunc

Hi guys

I have a stupid problem but i don’t resolve.
I like to translate an object according to passive movement of mouse, with callback glutPassiveMotionFunc.

At initialize I draw my objetc, at (0,0,0) position,
in mousemove function I trying:

void onMouseMove(int x, int y) {
dx = x - onMouse_prev_x;
dy = y - onMouse_prev_y;
onMouse_xtrans -= dx / 100;
onMouse_ytrans -= dy / 100;
glTranslated(onMouse_xtrans, onMouse_ytrans, 0.0);

when run a program, next a first movement (passive) of mouse o object the object disappears.


try declaring dx and dy as double instead of int, otherwise dx/ 100 will give and integer result…


its, are float.

You don’t show how any variable is declared, or how onMouse_prev_* is defined. Mouse movements are reported from the mouse as relative coordinates, not absolute (but you haven’t shown how parameters x and y are defined). You don’t show which GL matrix is current (i.e., which one is acted on by glTranslated()). Finally, like nearly every example posted in this forum, you don’t have a single comment in your code. I guess you think everyone here is a mind reader?

hei david,

I didn’t know, for example, with the texture matrix we were doing translation.

Are you remember that all transformation is done with the modelview matrix? or I am wrong ?

If you don’t help, do not write.