17 st.
yaw = std::atan2(dir.x, dir.z);
18 st.
pitch = std::asin(glm::clamp(dir.y, -1.0F, 1.0F));
34 static constexpr float k_limit = glm::radians(89.0F);
35 st.
pitch = glm::clamp(st.
pitch, -k_limit, k_limit);
40 const glm::vec3 forward {
41 std::cos(st.
pitch) * std::sin(st.
yaw),
43 std::cos(st.
pitch) * std::cos(st.
yaw)
50 const float dist = glm::length(st.
eye);
54 st.
eye = glm::vec3(0.0F, 0.0F, dist);
59 st.
eye = glm::vec3(dist, 0.0F, 0.0F);
60 st.
yaw = glm::radians(-90.0F);
64 st.
eye = glm::vec3(0.0F, dist, 0.0F);
66 st.
pitch = glm::radians(-89.0F);
70 st.
yaw = st.
yaw + glm::pi<float>();
80 const auto now = std::chrono::steady_clock::now();
81 const float dt = std::chrono::duration<float>(now - st.
last_tick).count();
84 const glm::vec3 forward {
85 std::cos(st.
pitch) * std::sin(st.
yaw),
87 std::cos(st.
pitch) * std::cos(st.
yaw)
89 const glm::vec3 right = glm::normalize(glm::cross(forward, glm::vec3(0.0F, 1.0F, 0.0F)));
93 glm::vec3 candidate = st.
eye;
96 candidate += forward * step;
98 candidate -= forward * step;
100 candidate -= right * step;
102 candidate += right * step;
104 candidate -= glm::vec3(0.0F, 1.0F, 0.0F) * step;
106 candidate += glm::vec3(0.0F, 1.0F, 0.0F) * step;
113 const glm::vec3 forward {
114 std::cos(st.
pitch) * std::sin(st.
yaw),
116 std::cos(st.
pitch) * std::cos(st.
yaw)
120 .
view = glm::lookAt(st.
eye, st.
eye + forward, glm::vec3(0.0F, 1.0F, 0.0F)),
void advance_navigation(NavigationState &st)
Advance eye position by held movement flags against elapsed time.
void apply_scroll(NavigationState &st, float ticks)
Dolly eye along the current forward vector.
NavigationState make_navigation_state(const NavigationConfig &config)
Construct a NavigationState from a NavigationConfig.
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.
void apply_mouse_delta(NavigationState &st, float dx, float dy)
Apply a mouse delta to yaw and pitch.
ViewTransform build_view_transform(const NavigationState &st, float aspect)
Build a ViewTransform from the current NavigationState without mutating it.
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
std::function< glm::vec3(glm::vec3)> eye_constraint
Optional constraint applied to the proposed eye position after each advance.
Mutable first-person navigation state.