MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
PanZoom2DState.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "ViewTransform.hpp"
4
5namespace MayaFlux::Kinesis {
6
7/**
8 * @struct PanZoom2DConfig
9 * @brief Construction parameters for a 2D pan/zoom orthographic controller.
10 */
12 glm::vec2 initial_pan { 0.0F, 0.0F }; ///< Initial pan offset in world units
13 float initial_zoom { 1.0F }; ///< Initial half-height of the orthographic frustum
14 float scroll_speed { 0.1F }; ///< Fractional zoom change per scroll tick
15 float min_zoom { 0.001F }; ///< Minimum half-height (maximum zoom in)
16 float max_zoom { 10000.0F }; ///< Maximum half-height (maximum zoom out)
17 float near_plane { -1.0F };
18 float far_plane { 1.0F };
19};
20
21/**
22 * @struct PanZoom2DState
23 * @brief Mutable 2D pan/zoom navigation state.
24 *
25 * Pan offset and zoom (orthographic half-height) are the only mutable fields.
26 * The ViewTransform is purely orthographic: view is identity, projection is
27 * derived each frame as ortho(-zoom*aspect + pan.x, zoom*aspect + pan.x,
28 * -zoom + pan.y, zoom + pan.y).
29 *
30 * Construct via make_pan_zoom_state(). Update via apply_pan_zoom_pan() and
31 * apply_pan_zoom_scroll(), then call compute_pan_zoom_view_transform() each frame.
32 */
34 glm::vec2 pan { 0.0F, 0.0F }; ///< World-space pan offset
35 float zoom { 1.0F }; ///< Orthographic half-height
36
37 float scroll_speed { 0.1F };
38 float min_zoom { 0.001F };
39 float max_zoom { 10000.0F };
40 float near_plane { -1.0F };
41 float far_plane { 1.0F };
42
43 bool drag_held { false };
44 bool first_mouse { true };
45 double last_x { 0.0 };
46 double last_y { 0.0 };
47};
48
49/**
50 * @brief Construct a PanZoom2DState from a PanZoom2DConfig.
51 * @param config Source configuration.
52 * @return Initialised PanZoom2DState.
53 */
54[[nodiscard]] MAYAFLUX_API PanZoom2DState make_pan_zoom_state(const PanZoom2DConfig& config);
55
56/**
57 * @brief Build a ViewTransform from the current PanZoom2DState.
58 *
59 * View matrix is identity. Projection is a symmetric ortho frustum centred
60 * on state.pan with half-height state.zoom.
61 *
62 * @param state PanZoom2D state (read-only).
63 * @param aspect Framebuffer width / height.
64 * @return ViewTransform ready for push constant upload.
65 */
66[[nodiscard]] MAYAFLUX_API ViewTransform compute_pan_zoom_view_transform(
67 const PanZoom2DState& state, float aspect);
68
69/**
70 * @brief Pan by a pixel delta, scaled to world units by the current zoom level.
71 *
72 * Scaling by zoom ensures pan speed stays proportionate to zoom level.
73 *
74 * @param state PanZoom2D state (pan mutated).
75 * @param dx Horizontal pixel delta (positive = right).
76 * @param dy Vertical pixel delta (positive = up).
77 * @param viewport_width Framebuffer width in pixels.
78 * @param viewport_height Framebuffer height in pixels.
79 */
80MAYAFLUX_API void apply_pan_zoom_pan(
81 PanZoom2DState& state, float dx, float dy,
82 float viewport_width, float viewport_height);
83
84/**
85 * @brief Zoom by multiplying the half-height, clamped to [min_zoom, max_zoom].
86 *
87 * @param state PanZoom2D state (zoom mutated).
88 * @param ticks Signed scroll ticks (positive = zoom in).
89 */
90MAYAFLUX_API void apply_pan_zoom_scroll(PanZoom2DState& state, float ticks);
91
92} // 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.