From 9500e9e05b7b32f0bd68967a403af2c761132642 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 4 Jul 2023 04:34:25 -0700 Subject: [PATCH] [Bugfix]: Fix player_hud_tune item position/rotation adjustment (#1390) A bit of refactoring after fa0769dadb1d176f21135d8dc9208ff679fe2fd6 --- src/xrGame/player_hud.cpp | 24 ++++++++++++++---------- src/xrGame/player_hud.h | 1 + src/xrGame/player_hud_tune.cpp | 24 ++++++++++++------------ 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/xrGame/player_hud.cpp b/src/xrGame/player_hud.cpp index 965d14a60bb..285ff3632fc 100644 --- a/src/xrGame/player_hud.cpp +++ b/src/xrGame/player_hud.cpp @@ -8,6 +8,7 @@ #include "ActorEffector.h" #include "WeaponMagazinedWGrenade.h" // XXX: move somewhere +extern u32 hud_adj_mode; player_hud* g_player_hud = nullptr; // clang-format off @@ -129,6 +130,9 @@ void attachable_hud_item::update(bool bForce) { reload_measures(); } + + if (hud_adj_mode > 0) + m_measures.update(m_attach_offset); m_parent->calc_transform(m_attach_place_idx, m_attach_offset, m_item_transform); m_upd_firedeps_frame = Device.dwFrame; @@ -217,12 +221,8 @@ Fmatrix hud_item_measures::load(const shared_str& sect_name, IKinematics* K) m_item_attach[0] = pSettings->r_fvector3(sect_name, "item_position"); m_item_attach[1] = pSettings->r_fvector3(sect_name, "item_orientation"); - Fvector ypr = m_item_attach[1]; - ypr.mul(PI / 180.f); - Fmatrix attach_offset; - attach_offset.setHPB(ypr.x, ypr.y, ypr.z); - attach_offset.translate_over(m_item_attach[0]); + update(attach_offset); shared_str bone_name; m_prop_flags.set(e_fire_point, pSettings->line_exist(sect_name, "fire_bone")); @@ -286,12 +286,8 @@ Fmatrix hud_item_measures::load_monolithic(const shared_str& sect_name, IKinemat m_item_attach[0] = pSettings->r_fvector3(sect_name, "position"); m_item_attach[1] = pSettings->r_fvector3(sect_name, "orientation"); - Fvector ypr = m_item_attach[1]; - ypr.mul(PI / 180.f); - Fmatrix attach_offset; - attach_offset.setHPB(ypr.x, ypr.y, ypr.z); - attach_offset.translate_over(m_item_attach[0]); + update(attach_offset); // fire bone if (auto* wpn = smart_cast(owner)) @@ -362,6 +358,14 @@ void hud_item_measures::load_inertion_params(const shared_str& sect_name) //--#SM+# End-- } +void hud_item_measures::update(Fmatrix& attach_offset) +{ + Fvector ypr = m_item_attach[1]; + ypr.mul(PI / 180.f); + attach_offset.setHPB(ypr.x, ypr.y, ypr.z); + attach_offset.translate_over(m_item_attach[0]); +} + attachable_hud_item::~attachable_hud_item() { IRenderVisual* v = m_model->dcast_RenderVisual(); diff --git a/src/xrGame/player_hud.h b/src/xrGame/player_hud.h index 141463492c7..aa0aaea7683 100644 --- a/src/xrGame/player_hud.h +++ b/src/xrGame/player_hud.h @@ -59,6 +59,7 @@ struct hud_item_measures Fmatrix load(const shared_str& sect_name, IKinematics* K); Fmatrix load_monolithic(const shared_str& sect_name, IKinematics* K, CHudItem* owner); void load_inertion_params(const shared_str& sect_name); + void update(Fmatrix& attach_offset); struct inertion_params { diff --git a/src/xrGame/player_hud_tune.cpp b/src/xrGame/player_hud_tune.cpp index 5d3a82eb595..9f979f4b071 100644 --- a/src/xrGame/player_hud_tune.cpp +++ b/src/xrGame/player_hud_tune.cpp @@ -349,32 +349,32 @@ void hud_adjust_mode_keyb(int dik) { if (pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT)) { - if (dik == SDL_SCANCODE_KP_0) + if (dik == SDL_SCANCODE_KP_0 || dik == SDL_SCANCODE_0) hud_adj_mode = 0; - if (dik == SDL_SCANCODE_KP_1) + if (dik == SDL_SCANCODE_KP_1 || dik == SDL_SCANCODE_1) hud_adj_mode = 1; - if (dik == SDL_SCANCODE_KP_2) + if (dik == SDL_SCANCODE_KP_2 || dik == SDL_SCANCODE_2) hud_adj_mode = 2; - if (dik == SDL_SCANCODE_KP_3) + if (dik == SDL_SCANCODE_KP_3 || dik == SDL_SCANCODE_3) hud_adj_mode = 3; - if (dik == SDL_SCANCODE_KP_4) + if (dik == SDL_SCANCODE_KP_4 || dik == SDL_SCANCODE_4) hud_adj_mode = 4; - if (dik == SDL_SCANCODE_KP_5) + if (dik == SDL_SCANCODE_KP_5 || dik == SDL_SCANCODE_5) hud_adj_mode = 5; - if (dik == SDL_SCANCODE_KP_6) + if (dik == SDL_SCANCODE_KP_6 || dik == SDL_SCANCODE_6) hud_adj_mode = 6; - if (dik == SDL_SCANCODE_KP_7) + if (dik == SDL_SCANCODE_KP_7 || dik == SDL_SCANCODE_7) hud_adj_mode = 7; - if (dik == SDL_SCANCODE_KP_8) + if (dik == SDL_SCANCODE_KP_8 || dik == SDL_SCANCODE_8) hud_adj_mode = 8; - if (dik == SDL_SCANCODE_KP_9) + if (dik == SDL_SCANCODE_KP_9 || dik == SDL_SCANCODE_9) hud_adj_mode = 9; } if (pInput->iGetAsyncKeyState(SDL_SCANCODE_LCTRL)) { - if (dik == SDL_SCANCODE_KP_0) + if (dik == SDL_SCANCODE_KP_0 || dik == SDL_SCANCODE_0) hud_adj_item_idx = 0; - if (dik == SDL_SCANCODE_KP_1) + if (dik == SDL_SCANCODE_KP_1 || dik == SDL_SCANCODE_1) hud_adj_item_idx = 1; } }