Opengl CAD like rotation: how to rotate scene around viewport center

Viewed 170

I'm making a CAD-like 3D viewer with PyOpenGL. I managed to pan, zoom and rotate using mouse event. The problem is that I need the scene to always rotate around the center of the viewport even when the origin is translated.

With the code I have, I obtain a rotation around the translated origin:

sketch of the problem here

Here is the code snippet of those transformation:

def paintGL(self):
    aspectRatio = self.height() / self.width()

    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glLoadIdentity()
    gl.glScalef(self.zoom * aspectRatio, self.zoom , 1.0);
    gl.glTranslatef(self.xTrans, self.yTrans, -10.0)
    gl.glRotatef(self.xRot , 1.0, 0.0, 0.0)
    gl.glRotatef(self.yRot , 0.0, 1.0, 0.0)
    gl.glRotatef(self.zRot , 0.0, 0.0, 1.0)
    gl.glCallList(self.object) #drawing the objects
0 Answers
Related