我有以下变量:
这是我到目前为止的代码。
void Zoom(int pointOfInterestX,int pointOfInterstY,int screenWidth,
int screenHeight,int zoomLevel)
{
glScalef(1,1,1);
glTranslatef( (pointOfInterestX/2) - (screenWidth/2), (pointOfInterestY/2) - (screenHeight/2),0);
glScalef(zoomLevel,zoomLevel,1);
}
我想放大/缩小,但要将关注点保持在屏幕中间。但到目前为止,我的所有尝试都失败了。
答案 0 :(得分:5)
您可以像这样开始渲染帧:
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLdouble left = (0 - pointOfInterestX) / zoomLevel + pointOfInterestX;
GLdouble right = (WindowW - pointOfInterestX) / zoomLevel + pointOfInterestX;
GLdouble bottom = (WindowH - pointOfInterestY) / zoomLevel + pointOfInterestY;
GLdouble top = (0 - pointOfInterestY) / zoomLevel + pointOfInterestY;
glOrtho(left, right, bottom, top, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();