PanZoom

class glumpy.transforms.PanZoom(*args, **kwargs)

Bases: glumpy.transforms.transform.Transform

2D pan & zoom transform.

Parameters:
  • aspect (float) – Indicate what is the aspect ratio of the object displayed. This is necessary to convert pixel drag move in oject space coordinates. Default is None.
  • pan (float,float) – Initial translation. Default is (0,0)
  • zoom (float,float) – Initial zoom level. Default is (1,1)
  • zoom_min (float) – Minimal zoom level. Default is 0.01
  • zoom_max (float) – Minimal zoom level. Default is 1000.0

The panzoom transform allow to translate and scale a scene in the window space coordinate (2D). This means that whatever point you grab on the screen, it should remains under the mouse pointer. Zoom is realized using the mouse scroll and is always centered on the mouse pointer.

The transform is connected to the following events:

  • on_attach: Transform initialization
  • on_resize: Tranform update to maintain aspect
  • on_mouse_scroll: Zoom in & out (user action)
  • on_mouse_grab: Pan (user action)

Usage example:

vertex = '''
attribute vec2 position;
void main()
{
    gl_Position = <transform>(vec4(position, 0.0, 1.0));
} '''

...
window = app.Window(width=800, height=800)
program = gloo.Program(vertex, fragment, count=4)
...
program['transform'] = PanZoom(aspect=1)
window.attach(program['transform'])
...
aspect

Aspect (width/height)

pan

Panning (translation)

reset()

Reset transform (zoom=1, pan=(0,0))

zoom

Zoom level

zoom_max

Maximal zoom level

zoom_min

Minimal zoom level