MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
PanZoom2DState.cpp
Go to the documentation of this file.
1#include "PanZoom2DState.hpp"
2
3namespace MayaFlux::Kinesis {
4
6{
8 st.pan = config.initial_pan;
9 st.zoom = config.initial_zoom;
10 st.scroll_speed = config.scroll_speed;
11 st.min_zoom = config.min_zoom;
12 st.max_zoom = config.max_zoom;
13 st.near_plane = config.near_plane;
14 st.far_plane = config.far_plane;
15 return st;
16}
17
19{
20 const float hw = st.zoom * aspect;
21 const float hh = st.zoom;
22 return {
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,
27 st.near_plane, st.far_plane)
28 };
29}
30
31void apply_pan_zoom_pan(PanZoom2DState& st, float dx, float dy,
32 float viewport_width, float viewport_height)
33{
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);
37}
38
40{
41 st.zoom *= (1.0F - ticks * st.scroll_speed);
42 st.zoom = glm::clamp(st.zoom, st.min_zoom, st.max_zoom);
43}
44
45} // 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.
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.