Ok, here’s what I am trying to accomplish. Have you seen those applications that zoom around the mouse? AutoCAD is a really good example. The page doesn’t center on the mouse but the pointer is the focal point for the zooming action. I have a program that displays map data on and AWTGLCanvas and I need to implement that same kind of thing. Here is my idea (feel free to shoot this idea down (In fact please do there has got to be a better way)):
- Get the mouse location from the MouseEvent
- Translate that to world coords
- Zoom
- Get the new screen coords of where the mouse had been pointing
- Adjust to reconcile the difference vetween the two sets of screen coords
Now in pseudo-code:
Do you think that'll work?
oldX = mouseEvent.getX();
oldY = mouseEvent.getY();
gluUnProject((float)oldX, (float)oldY, zoomLevel, modelArray, projectionArray, viewportArray, result);
worldX = result[0];
worldY = result[1];
zoom();
gluProject(worldX, worldY, zoomLevel, modelArray, projectionArray, viewportArray, result);
newX = result[0];
newY = result[1];
pan(newX - oldX, newY - oldY);