Skip to content

Commit

Permalink
Aiming: Recenter view after 2s timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Apr 20, 2023
1 parent f33ce01 commit c607e55
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
23 changes: 18 additions & 5 deletions src/mods/vr/IXRTrackingSystemHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,24 @@ IXRTrackingSystemHook::IXRTrackingSystemHook(FFakeStereoRenderingHook* stereo_ho
}

void IXRTrackingSystemHook::on_pre_engine_tick(sdk::UGameEngine* engine, float delta) {
if (m_initialized) {
return;
}
auto& vr = VR::get();

if (vr->is_any_aim_method_active()) {
if (!m_initialized) {
initialize();
}

auto& data = m_process_view_rotation_data;

if (VR::get()->is_any_aim_method_active()) {
initialize();
// This can happen if player logic stops running (e.g. player has died or entered a loading screen)
// so we dont want the UI off in nowhere land
if (data.was_called && std::chrono::high_resolution_clock::now() - data.last_update >= std::chrono::seconds(2)) {
data.was_called = false;
vr->recenter_view();
vr->set_pre_flattened_rotation(glm::identity<glm::quat>());

SPDLOG_INFO("IXRTrackingSystemHook: Recentering view because of timeout");
}
}
}

Expand Down Expand Up @@ -736,6 +748,7 @@ void IXRTrackingSystemHook::update_view_rotation(Rotator<float>* rot) {
const auto delta_time = now - m_process_view_rotation_data.last_update;
const auto delta_float = std::chrono::duration_cast<std::chrono::duration<float>>(delta_time).count();
m_process_view_rotation_data.last_update = now;
m_process_view_rotation_data.was_called = true;

auto& vr = VR::get();

Expand Down
14 changes: 10 additions & 4 deletions src/mods/vr/IXRTrackingSystemHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ class IXRCamera;
class FFakeStereoRenderingHook;

class IXRTrackingSystemHook : public ModComponent {
public:
struct ProcessViewRotationData {
std::chrono::high_resolution_clock::time_point last_update{std::chrono::high_resolution_clock::now()};
glm::quat last_aim_rot{glm::identity<glm::quat>()};
bool was_called{false};
};

public:
IXRTrackingSystemHook(FFakeStereoRenderingHook* stereo_hook, size_t offset_in_engine);

void on_pre_engine_tick(sdk::UGameEngine* engine, float delta) override;

auto& get_process_view_rotation_data() { return m_process_view_rotation_data; }

private:
struct ReferenceController {
virtual void destroy() { }
Expand Down Expand Up @@ -74,10 +83,7 @@ class IXRTrackingSystemHook : public ModComponent {
void* unk{nullptr};
} m_hmd_device;

struct ProcessViewRotationData {
std::chrono::high_resolution_clock::time_point last_update{std::chrono::high_resolution_clock::now()};
glm::quat last_aim_rot{glm::identity<glm::quat>()};
} m_process_view_rotation_data;
ProcessViewRotationData m_process_view_rotation_data{};

std::unique_ptr<ReferenceController> m_ref_controller{std::make_unique<ReferenceController>()};
std::unique_ptr<ReferenceController> m_ref_controller2{std::make_unique<ReferenceController>()};
Expand Down

0 comments on commit c607e55

Please sign in to comment.