Advertisement

Adding zoom functionality to lesson 5?

Started by April 10, 2002 05:12 PM
0 comments, last by JustAnotherBill 22 years, 10 months ago
I''m attempting to implement a virtual tracball with zoom features and am using the glut version of lesson 5 as my playground. The code I''ve added is as follows: void mouse_func (int button, int state, int x, int y) { //set motion states if (button == GLUT_LEFT_BUTTON) { if (state == GLUT_DOWN) { tbaction = ROTATE; glMatrixMode(GL_MODELVIEW); lastx = x; lasty = y; } else if (state == GLUT_UP) { tbaction = NONE; } } if (button == GLUT_RIGHT_BUTTON) { if (state == GLUT_DOWN) { lastx = x; lasty = y; glMatrixMode(GL_PROJECTION); tbaction = ZOOM; } else if (state == GLUT_UP) { tbaction = NONE; } } } void mousemove_func(int x, int y) { switch (tbaction) { case ZOOM: float pixdiff; float zoomval; pixdiff = (float)lastx - (float)x; zoomval = 1.0 + pixdiff * 0.008; glScalef( zoomval, zoomval, zoomval ); lastx = x; lasty = y; glutPostRedisplay(); break; case ROTATE: glMatrixMode(GL_MODELVIEW); break; case NONE: default: break; } } with the following in main to enable the above: glutMouseFunc ( mouse_func ); glutMotionFunc ( mousemove_func ); The problem right now is that when the glMatrixMode is set to projection, it goes blank. adding a matrix mode change to modelview in the display function will fix that, however then the zoom function doesn''t work (hold down right button and drag to zoom). I''m trying to adapt some messy MFC code in which the zoom by scale does work. Anyone know what I''m doing wrong?
Nevermind, found it. combination of scaling factor and changing the matrix mode in other places.

This topic is closed to new replies.

Advertisement