Sign in to follow this  
vicer1234

OpenGL opengl mouse function

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this