20 const float hw = st.
zoom * aspect;
21 const float hh = st.
zoom;
23 .view = glm::mat4(1.0F),
24 .projection = glm::ortho(
25 st.
pan.x - hw, st.
pan.x + hw,
26 st.
pan.y - hh, st.
pan.y + hh,
32 float viewport_width,
float viewport_height)
34 const float aspect = viewport_width / viewport_height;
35 st.
pan.x -= (dx / viewport_width) * (2.0F * st.
zoom * aspect);
36 st.
pan.y += (dy / viewport_height) * (2.0F * st.
zoom);
ViewTransform compute_pan_zoom_view_transform(const PanZoom2DState &st, float aspect)
Build a ViewTransform from the current PanZoom2DState.
PanZoom2DState make_pan_zoom_state(const PanZoom2DConfig &config)
Construct a PanZoom2DState from a PanZoom2DConfig.
void apply_pan_zoom_scroll(PanZoom2DState &st, float ticks)
Zoom by multiplying the half-height, clamped to [min_zoom, max_zoom].
void apply_pan_zoom_pan(PanZoom2DState &st, float dx, float dy, float viewport_width, float viewport_height)
Pan by a pixel delta, scaled to world units by the current zoom level.
float max_zoom
Maximum half-height (maximum zoom out)
glm::vec2 initial_pan
Initial pan offset in world units.
float initial_zoom
Initial half-height of the orthographic frustum.
float scroll_speed
Fractional zoom change per scroll tick.
float min_zoom
Minimum half-height (maximum zoom in)
Construction parameters for a 2D pan/zoom orthographic controller.
float zoom
Orthographic half-height.
glm::vec2 pan
World-space pan offset.
Mutable 2D pan/zoom navigation state.