17 st.
yaw = std::atan2(dir.x, dir.z);
18 st.
pitch = std::asin(glm::clamp(dir.y, -1.0F, 1.0F));
25 const auto now = std::chrono::steady_clock::now();
26 const float dt = std::chrono::duration<float>(now - st.
last_tick).count();
29 const glm::vec3 forward {
30 std::cos(st.
pitch) * std::sin(st.
yaw),
32 std::cos(st.
pitch) * std::cos(st.
yaw)
34 const glm::vec3 right = glm::normalize(glm::cross(forward, glm::vec3(0.0F, 1.0F, 0.0F)));
39 st.
eye += forward * step;
41 st.
eye -= forward * step;
43 st.
eye -= right * step;
45 st.
eye += right * step;
47 st.
eye -= glm::vec3(0.0F, 1.0F, 0.0F) * step;
49 st.
eye += glm::vec3(0.0F, 1.0F, 0.0F) * step;
52 .view = glm::lookAt(st.
eye, st.
eye + forward, glm::vec3(0.0F, 1.0F, 0.0F)),
62 static constexpr float k_limit = glm::radians(89.0F);
63 st.
pitch = glm::clamp(st.
pitch, -k_limit, k_limit);
68 const glm::vec3 forward {
69 std::cos(st.
pitch) * std::sin(st.
yaw),
71 std::cos(st.
pitch) * std::cos(st.
yaw)
78 const float dist = glm::length(st.
eye);
82 st.
eye = glm::vec3(0.0F, 0.0F, dist);
87 st.
eye = glm::vec3(dist, 0.0F, 0.0F);
88 st.
yaw = glm::radians(-90.0F);
92 st.
eye = glm::vec3(0.0F, dist, 0.0F);
94 st.
pitch = glm::radians(-89.0F);
98 st.
yaw = st.
yaw + glm::pi<float>();
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.