Skip to content

Commit

Permalink
Add smoothing toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Apr 19, 2023
1 parent ecb28ff commit ae4c459
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/mods/VR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1808,9 +1808,13 @@ void VR::on_draw_ui() {
m_previous_aim_method = (AimMethod)m_aim_method->value();
}

m_aim_interp->draw("Smoothing");
m_aim_speed->draw("Speed");

ImGui::TreePop();
}

ImGui::SetNextItemOpen(true, ImGuiCond_::ImGuiCond_Once);
if (ImGui::TreeNode("Movement Orientation")) {
m_movement_orientation->draw("Type");

Expand Down
21 changes: 14 additions & 7 deletions src/mods/vr/IXRTrackingSystemHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,16 +790,23 @@ void IXRTrackingSystemHook::update_view_rotation(Rotator<float>* rot) {
const auto right_controller_end = og_controller_pos + (right_controller_forward * 1000.0f);
const auto adjusted_forward = glm::normalize(glm::vec3{right_controller_end - vr->get_standing_origin()});
const auto target_forward = utility::math::to_quat(adjusted_forward);
// quaternion distance between target_forward and last_aim_rot
auto spherical_distance = glm::dot(target_forward, m_process_view_rotation_data.last_aim_rot);

if (spherical_distance < 0.0f) {
// we do this because we want to rotate the shortest distance
spherical_distance = -spherical_distance;
glm::quat right_controller_forward_rot{};

if (vr->is_aim_interpolation_enabled()) {
// quaternion distance between target_forward and last_aim_rot
auto spherical_distance = glm::dot(target_forward, m_process_view_rotation_data.last_aim_rot);

if (spherical_distance < 0.0f) {
// we do this because we want to rotate the shortest distance
spherical_distance = -spherical_distance;
}

right_controller_forward_rot = glm::slerp(m_process_view_rotation_data.last_aim_rot, target_forward, delta_float * vr->get_aim_speed() * spherical_distance);
} else {
right_controller_forward_rot = target_forward;
}

const auto right_controller_forward_rot = glm::slerp(m_process_view_rotation_data.last_aim_rot, target_forward, delta_float * vr->get_aim_speed() * spherical_distance);

const auto wanted_rotation = glm::normalize(rotation_offset * right_controller_forward_rot);
const auto new_rotation = glm::normalize(vqi_norm * wanted_rotation);
euler = glm::degrees(utility::math::euler_angles_from_steamvr(new_rotation));
Expand Down

0 comments on commit ae4c459

Please sign in to comment.