Thanks for the examples and advice everyone, I really appreciate it!

To start, I was able to adapt Nathan's example for "panning".
It's a bit different than usual. You click somewhere with the middle mouse 
button
and then that location becomes the new center of the screen.
Ctrl + middle-mouse restores the default view.

    def on_mouse_press(self, x, y, button, modifiers):
        if button == mouse.MIDDLE:
                if self.keys[key.LCTRL]:
                    # Center = default
                    gl.glViewport(0, 0, self.width, self.height)
                    gl.glMatrixMode(gl.GL_PROJECTION)
                    gl.glLoadIdentity()
                    gl.glOrtho(0, self.width,
                                0, self.height,
                                -1, 1)
                    gl.glMatrixMode(gl.GL_MODELVIEW)
                    self.originx = 0
                    self.originy = 0
                else:
                    # Center = xp, yp
                    xp = x + self.originx
                    yp = y + self.originy
                    self.originx = xp - (self.width / 2)
                    self.originy = yp - (self.height / 2)
                    gl.glViewport(0, 0, self.width, self.height)
                    gl.glMatrixMode(gl.GL_PROJECTION)
                    gl.glLoadIdentity()
                    gl.glOrtho(self.originx, self.originx + self.width,
                                self.originy, self.originy + self.height,
                                    -1, 1)
                    gl.glMatrixMode(gl.GL_MODELVIEW)

I found an example of 'zooming to a point of interest' with glOrtho on 
stackOverflow:
http://stackoverflow.com/a/10136205/1217270
I've tweaked it a dozen times but have been unable to get it working as 
desired.
I'm keeping track of the origin so that I can translate the window 
coordinates into world coordinates.
Honestly I'm not sure what they intended the zoomLevel (self.zoom) to be.
Right now this zooms in a bit on the first scroll, 
then everything just starts moving down to the left, on subsequent scrolls.
Maybe someone will see what I need to change.

        self.originx = 0.0
        self.originy = 0.0
        self.zoom = 1.0

    def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
        if scroll_y > 0:
            self.zoom += 0.1
            xp = x + self.originx
            yp = y + self.originy
            gl.glViewport(0, 0, self.width, self.height)
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            left = (self.originx - xp) / self.zoom + xp
            right = ((self.originx + self.width) - xp) / self.zoom + xp
            bottom = (self.originy - yp) / self.zoom + yp
            top = ((self.originy + self.height) - yp) / self.zoom + yp
            gl.glOrtho(int(left), int(right),
                        int(bottom), int(top),
                        -1, 1)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            self.originx = int(left)
            self.originy = int(bottom)

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pyglet-users/-/7_WaNmIPNCkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to