I just got camera zoom with OpenGL up and running in my little Pyglet game, but now I'm facing a problem: When I zoom in or out, the game objects' hitboxes won't obviously scale, so the game doesn't respond to mouse events correctly. Altering thousands of objects' properties might just be a bit slow, so I was wondering if I could modify the mouse's position instead. I just have no idea how. Zooming is done by glOrtho()
, with multiplying the parameters.
Zooming code (self.dx
and self.dy
are the total movement of the camera so far, and self.zoom
is a multiplier from 0.1 to 2):
pyglet.gl.glMatrixMode(pyglet.gl.GL_PROJECTION)
pyglet.gl.glLoadIdentity()
pyglet.gl.glOrtho(-screen.width / (2 * self.zoom), screen.width / (2 * self.zoom), -screen.height / (2 * self.zoom), screen.height / (2 * self.zoom), -1, 1)
pyglet.gl.glTranslatef(self.dx - screen.width / 2, self.dy - screen.height / 2, 0)
pyglet.gl.glMatrixMode(pyglet.gl.GL_MODELVIEW)
Edit
What about reversing the zooming calculations for the mouse coordinates?
Edit 2
The way I'm handling mouse collisions with game objects is at least notorious. I'm actually using pygame.Rect
objects to represent object's position, and then colliding it with mouse's position. It has worked great so far, since I haven't done any zooming until now. Maybe there's a way that suits better the OpenGL/3D world?