MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
PanZoom2DState.cpp
Go to the documentation of this file.
1#include "PanZoom2DState.hpp"
2
3#include "ScrollState.hpp"
4
5namespace MayaFlux::Kinesis {
6
8{
10 st.pan = config.initial_pan;
11 st.zoom = config.initial_zoom;
12 st.scroll_speed = config.scroll_speed;
13 st.min_zoom = config.min_zoom;
14 st.max_zoom = config.max_zoom;
15 st.near_plane = config.near_plane;
16 st.far_plane = config.far_plane;
17 return st;
18}
19
21{
22 const float hw = st.zoom * aspect;
23 const float hh = st.zoom;
24 return {
25 .view = glm::mat4(1.0F),
26 .projection = glm::ortho(
27 st.pan.x - hw, st.pan.x + hw,
28 st.pan.y - hh, st.pan.y + hh,
29 st.near_plane, st.far_plane)
30 };
31}
32
33void apply_pan_zoom_pan(PanZoom2DState& st, float dx, float dy,
34 float viewport_width, float viewport_height)
35{
36 const float aspect = viewport_width / viewport_height;
37 const glm::vec2 delta = drag_to_offset_delta(
38 { dx, dy },
39 { 2.0F * st.zoom * aspect, 2.0F * st.zoom },
40 { viewport_width, viewport_height });
41
42 st.pan.x -= delta.x;
43 st.pan.y += delta.y;
44}
45
47{
48 st.zoom *= (1.0F - ticks * st.scroll_speed);
49 st.zoom = glm::clamp(st.zoom, st.min_zoom, st.max_zoom);
50}
51
52} // namespace MayaFlux::Kinesis
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.
glm::vec2 drag_to_offset_delta(glm::vec2 pixel_delta, glm::vec2 visible_extent, glm::vec2 viewport_size_pixels) noexcept
Convert a pixel-space drag delta into a content-space delta.
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.
View and projection matrices as a named push constant slot.