opengl mouse function

Started by
1 comment, last by glaeken 14 years, 12 months ago
hi, I am trying to implement pan,zoom and rotate functionality using opengl. i am calling this function glutMouseFunc(HandleMouse); in main() and in HandleMouse() i am checking and doing this if(state == GLUT_DOWN) { if(button == GLUT_RIGHT_BUTTON) // translate { translateX += (400 - x)/1000.0f; translateY += (400 - y)/1000.0f; } else if(button == GLUT_MIDDLE_BUTTON) // for zooming { translateZ += 0.2f; } else if(button == GLUT_LEFT_BUTTON) //For Rotation { angle += 10.0f; } } And in draw function i am doing this glPushMatrix(); { glTranslatef(0.0f, -1.0f , -5.0f); glTranslatef(translateX, translateY, translateZ); glRotatef(_angle, 1.0f, 1.0f, 0.0f); glBegin(GL_TRIANGLES); { } glEnd(); } But its not working.what happens is that when i click on some other window and on this then the change is reflected. My opengl window is of (400,400)...But the translation part i.e. dragging of the object is not working at all.Let me know what are the mistakes and how to improve it... Thanks in advance
Advertisement
You need to tell glut to refresh the screen to reflect your changes.

glutPostRedisplay();
Also, if you want to translate/rotate/zoom by clicking and dragging you need to implement that in a glutMotionFunc(). glutMotionFunc() generates a callback when a mouse button is pressed and the mouse moves. glutMouseFunc() generates a callback when a mouse button is pressed and released (clicked).

This topic is closed to new replies.

Advertisement