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:
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