MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NavigationState.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "ViewTransform.hpp"
4
5namespace MayaFlux::Kinesis {
6
7/**
8 * @struct NavigationConfig
9 * @brief Tuning parameters for a first-person fly-navigation controller.
10 */
12 glm::vec3 initial_eye { 0.0F, 0.0F, 5.0F };
13 glm::vec3 initial_target { 0.0F, 0.0F, 0.0F };
14 float fov_radians { glm::radians(60.0F) };
15 float near_plane { 0.01F };
16 float far_plane { 1000.0F };
17 float move_speed { 3.0F }; ///< World units per second
18 float mouse_sensitivity { 0.002F }; ///< Radians per pixel
19 float scroll_speed { 0.5F }; ///< World units per scroll tick
20};
21
22/**
23 * @struct NavigationState
24 * @brief Mutable first-person navigation state.
25 *
26 * Holds eye position, orientation angles, per-axis movement flags, and
27 * mouse tracking state. All fields are plain data; no engine or event
28 * system dependency.
29 *
30 * Construct via make_navigation_state() to derive initial yaw/pitch from
31 * NavigationConfig::initial_target. Update by mutating fields directly,
32 * then call compute_view_transform() each frame.
33 */
35 glm::vec3 eye { 0.0F, 0.0F, 5.0F };
36 float yaw { 0.0F }; ///< Radians, horizontal rotation
37 float pitch { 0.0F }; ///< Radians, vertical rotation, clamped to [-89, +89] degrees
38
39 bool forward_held { false };
40 bool back_held { false };
41 bool left_held { false };
42 bool right_held { false };
43 bool down_held { false };
44 bool up_held { false };
45
46 bool rmb_held { false };
47 bool first_mouse { true };
48 double last_x { 0.0 };
49 double last_y { 0.0 };
50
51 float move_speed { 3.0F };
52 float mouse_sensitivity { 0.002F };
53 float scroll_speed { 0.5F };
54 float fov_radians { glm::radians(60.0F) };
55 float near_plane { 0.01F };
56 float far_plane { 1000.0F };
57
58 std::chrono::steady_clock::time_point last_tick { std::chrono::steady_clock::now() };
59};
60
61/**
62 * @brief Construct a NavigationState from a NavigationConfig.
63 *
64 * Derives initial yaw and pitch from the look direction
65 * (config.initial_target - config.initial_eye) so the first frame does
66 * not produce a view jump.
67 *
68 * @param config Source configuration
69 * @return Initialised NavigationState
70 */
71[[nodiscard]] NavigationState make_navigation_state(const NavigationConfig& config);
72
73/**
74 * @brief Compute a ViewTransform from the current NavigationState.
75 *
76 * Computes dt from state.last_tick, advances eye position by held movement
77 * flags scaled by move_speed * dt, updates last_tick, then constructs view
78 * and projection matrices.
79 *
80 * @param state Navigation state (eye and last_tick mutated by this call)
81 * @param aspect Framebuffer width / height
82 * @return ViewTransform ready for push constant upload
83 */
84[[nodiscard]] ViewTransform compute_view_transform(NavigationState& state, float aspect);
85
86/**
87 * @brief Apply a mouse delta to yaw and pitch.
88 *
89 * Pitch is clamped to [-89, +89] degrees to avoid gimbal lock at the poles.
90 *
91 * @param state Navigation state (yaw, pitch mutated)
92 * @param dx Horizontal pixel delta (positive = right)
93 * @param dy Vertical pixel delta (positive = down)
94 */
95void apply_mouse_delta(NavigationState& state, float dx, float dy);
96
97/**
98 * @brief Dolly eye along the current forward vector.
99 *
100 * @param state Navigation state (eye mutated)
101 * @param ticks Signed scroll ticks (positive = forward)
102 */
103void apply_scroll(NavigationState& state, float ticks);
104
105/**
106 * @brief Snap to a named ortho view.
107 *
108 * Preserves the current distance from the origin. Yaw/pitch are set to
109 * exact axis-aligned values. The top view uses pitch = -89 degrees to
110 * avoid the degenerate lookAt case at exactly -90 degrees.
111 *
112 * @param state Navigation state (eye, yaw, pitch mutated)
113 * @param view 0 = front (+Z), 1 = right (+X), 2 = top (+Y), 3 = flip opposite
114 */
115void snap_ortho(NavigationState& state, int view);
116
117} // namespace MayaFlux::Kinesis
NavigationState make_navigation_state(const NavigationConfig &config)
Construct a NavigationState from a NavigationConfig.
void apply_mouse_delta(NavigationState &st, float dx, float dy)
Apply a mouse delta to yaw and pitch.
void apply_scroll(NavigationState &st, float ticks)
Dolly eye along the current forward vector.
ViewTransform compute_view_transform(NavigationState &st, float aspect)
Compute a ViewTransform from the current NavigationState.
void snap_ortho(NavigationState &st, int view)
Snap to a named ortho view.
float mouse_sensitivity
Radians per pixel.
float scroll_speed
World units per scroll tick.
float move_speed
World units per second.
Tuning parameters for a first-person fly-navigation controller.
float pitch
Radians, vertical rotation, clamped to [-89, +89] degrees.
float yaw
Radians, horizontal rotation.
std::chrono::steady_clock::time_point last_tick
Mutable first-person navigation state.