OpenGl 2d scaling (using scale and translation instead of glOrtho)

This seems like a fairly common question, but I can't find a person with the same circumstances. Closest seems: OpenGL: scale, and then translate? And How? .

The problem I really need help with is moving, as well as zooming in (out) of the 2d scene using OpenGl. The code for scaling is pretty simple:

void RefMapGLScene::zoomOut(){
  currentScale = currentScale-zoomFactor;
  double xAdjust = (((get_width())*zoomFactor/2));
  double yAdjust = ((get_height()*zoomFactor/2));
  zoomTranslateX -= xAdjust;
  zoomTranslateY -= yAdjust;
}

The code for scaling is basically the same (add zoomFactor to currentScale and zoom in on TranslateX and Y).

The code for parsing everyone is also simple:

glPushMatrix();
glTranslated(-zoomTranslateX, -zoomTranslateY, 0);

glScaled(currentScale, currentScale, 1);
glTranslated(totalMovedX, totalMovedY, 0);

graph->draw();

glPopMatrix();

, zoomTranslate , , . , , , (.. / ). TotalMovedX Y :

if (parent->rightButtonDown){
  totalMovedX += (-(mousex-curx))/currentScale;
  totalMovedY += (-(mousey-cury))/currentScale;
}

. . / . , , . .

, , . , glOrtho , , . - , ?

+3
1

. , . , .

:

glPushMatrix();
glTranslated(-zoomTranslateX, -zoomTranslateY, 0);

glTranslated(totalMovedX, totalMovedY, 0);
glScaled(currentScale, currentScale, 1);

graph->draw();

glPopMatrix();

, currentScale

if (parent->rightButtonDown){
  totalMovedX += (-(mousex-curx));
  totalMovedY += (-(mousey-cury));
}
+3

All Articles