MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
OrbitState.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "ViewTransform.hpp"
4
5namespace MayaFlux::Kinesis {
6
7/**
8 * @struct OrbitConfig
9 * @brief Construction parameters for an orbit navigation controller.
10 */
12 glm::vec3 focal_point { 0.0F, 0.0F, 0.0F }; ///< World-space point the camera orbits around
13 float initial_distance { 5.0F }; ///< Initial radius from focal point
14 float initial_azimuth { 0.0F }; ///< Initial horizontal angle in radians
15 float initial_elevation { glm::radians(20.0F) }; ///< Initial vertical angle in radians
16 float fov_radians { glm::radians(60.0F) };
17 float near_plane { 0.01F };
18 float far_plane { 1000.0F };
19 float rotate_sensitivity { 0.005F }; ///< Radians per pixel for MMB drag
20 float pan_sensitivity { 0.001F }; ///< World units per pixel, scaled by distance
21 float scroll_speed { 0.1F }; ///< Fractional distance change per scroll tick
22 float min_distance { 0.1F }; ///< Minimum dolly distance
23 float max_distance { 10000.0F }; ///< Maximum dolly distance
24};
25
26/**
27 * @struct OrbitState
28 * @brief Mutable orbit navigation state.
29 *
30 * Stores spherical coordinates relative to a focal point. Eye position is
31 * derived each frame: focal + spherical_to_cartesian(azimuth, elevation, distance).
32 *
33 * Construct via make_orbit_state(). Update by calling the apply_* free
34 * functions on mouse/scroll events, then call compute_orbit_view_transform()
35 * each frame.
36 */
37struct OrbitState {
38 glm::vec3 focal { 0.0F, 0.0F, 0.0F }; ///< World-space orbit target
39 float azimuth { 0.0F }; ///< Horizontal angle in radians
40 float elevation { glm::radians(20.0F) }; ///< Vertical angle in radians, clamped away from poles
41 float distance { 5.0F }; ///< Radius from focal point
42
43 float fov_radians { glm::radians(60.0F) };
44 float near_plane { 0.01F };
45 float far_plane { 1000.0F };
46 float rotate_sensitivity { 0.005F };
47 float pan_sensitivity { 0.001F };
48 float scroll_speed { 0.1F };
49 float min_distance { 0.1F };
50 float max_distance { 10000.0F };
51
52 bool mmb_held { false };
53 bool pan_held { false };
54 bool first_mouse { true };
55 double last_x { 0.0 };
56 double last_y { 0.0 };
57};
58
59/**
60 * @brief Construct an OrbitState from an OrbitConfig.
61 * @param config Source configuration.
62 * @return Initialised OrbitState.
63 */
64[[nodiscard]] MAYAFLUX_API OrbitState make_orbit_state(const OrbitConfig& config);
65
66/**
67 * @brief Derive eye position from the current orbit state.
68 *
69 * Pure computation; does not mutate state.
70 *
71 * @param state Read-only orbit state.
72 * @return World-space eye position.
73 */
74[[nodiscard]] MAYAFLUX_API glm::vec3 orbit_eye(const OrbitState& state);
75
76/**
77 * @brief Build a ViewTransform from the current OrbitState.
78 *
79 * Pure read; does not mutate state.
80 *
81 * @param state Orbit state.
82 * @param aspect Framebuffer width / height.
83 * @return ViewTransform ready for push constant upload.
84 */
85[[nodiscard]] MAYAFLUX_API ViewTransform compute_orbit_view_transform(
86 const OrbitState& state, float aspect);
87
88/**
89 * @brief Apply a mouse delta to azimuth and elevation.
90 *
91 * Elevation is clamped to [-89, +89] degrees to avoid gimbal lock at the poles.
92 *
93 * @param state Orbit state (azimuth, elevation mutated).
94 * @param dx Horizontal pixel delta (positive = right).
95 * @param dy Vertical pixel delta (positive = down).
96 */
97MAYAFLUX_API void apply_orbit_rotate(OrbitState& state, float dx, float dy);
98
99/**
100 * @brief Dolly the camera toward or away from the focal point.
101 *
102 * Distance is multiplied by (1 - ticks * scroll_speed) and clamped to
103 * [min_distance, max_distance].
104 *
105 * @param state Orbit state (distance mutated).
106 * @param ticks Signed scroll ticks (positive = closer).
107 */
108MAYAFLUX_API void apply_orbit_scroll(OrbitState& state, float ticks);
109
110/**
111 * @brief Pan the focal point in the camera's local right/up plane.
112 *
113 * Delta is scaled by distance so pan speed stays proportionate to zoom level.
114 *
115 * @param state Orbit state (focal mutated).
116 * @param dx Horizontal pixel delta.
117 * @param dy Vertical pixel delta.
118 */
119MAYAFLUX_API void apply_orbit_pan(OrbitState& state, float dx, float dy);
120
121/**
122 * @brief Snap to a named ortho view, preserving distance and focal point.
123 *
124 * @param state Orbit state (azimuth, elevation mutated).
125 * @param view 0 = front (+Z), 1 = right (+X), 2 = top (+Y), 3 = flip opposite.
126 */
127MAYAFLUX_API void snap_orbit_ortho(OrbitState& state, int view);
128
129} // namespace MayaFlux::Kinesis
void apply_orbit_rotate(OrbitState &st, float dx, float dy)
Apply a mouse delta to azimuth and elevation.
glm::vec3 orbit_eye(const OrbitState &st)
Derive eye position from the current orbit state.
void snap_orbit_ortho(OrbitState &st, int view)
Snap to a named ortho view, preserving distance and focal point.
void apply_orbit_scroll(OrbitState &st, float ticks)
Dolly the camera toward or away from the focal point.
ViewTransform compute_orbit_view_transform(const OrbitState &st, float aspect)
Build a ViewTransform from the current OrbitState.
void apply_orbit_pan(OrbitState &st, float dx, float dy)
Pan the focal point in the camera's local right/up plane.
OrbitState make_orbit_state(const OrbitConfig &config)
Construct an OrbitState from an OrbitConfig.
Definition OrbitState.cpp:5
float pan_sensitivity
World units per pixel, scaled by distance.
glm::vec3 focal_point
World-space point the camera orbits around.
float initial_distance
Initial radius from focal point.
float min_distance
Minimum dolly distance.
float initial_azimuth
Initial horizontal angle in radians.
float initial_elevation
Initial vertical angle in radians.
float scroll_speed
Fractional distance change per scroll tick.
float max_distance
Maximum dolly distance.
float rotate_sensitivity
Radians per pixel for MMB drag.
Construction parameters for an orbit navigation controller.
float distance
Radius from focal point.
glm::vec3 focal
World-space orbit target.
float elevation
Vertical angle in radians, clamped away from poles.
float azimuth
Horizontal angle in radians.
Mutable orbit navigation state.