Hi again.
Yes, you can use glOrtho to scale the camera ("zoom" is for 3D
perspective), you simply specify the "box" the camera sees.
zoom = 2
glViewport(0, 0, width, height) -> set the drawing window.
# Now set uo the camera:
glOrtho(0, width, 0, height, -1, 1) -> Origin at bottom left corner
glOrtho(0, width/zoom, 0, height/zoom, -1, 1) -> Origin at bottom left
corner, zoom x2
glOrtho(-width/2, width/2, -height/2, height/2, -1, 1) -> Origin at center
glOrtho(-width/(2*zoom), width/(2*zoom), -height/(2*zoom),
height/(2*zoom), -1, 1) -> Origin at center, zoom x2
This should work too:
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, width, 0, height, -1, 1)
glTranslatef(pan_x, pan_y, 0) -> move the box
glScalef(zoom, zoom, 1) -> scale the box
glMatrixMode(GL_MODELVIEW)
El 27/07/2012 20:37, Derek S. escribió:
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.
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
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.