diff --git a/src/xrGame/HudItem.cpp b/src/xrGame/HudItem.cpp index 8ab345c360..6b8ed882d1 100644 --- a/src/xrGame/HudItem.cpp +++ b/src/xrGame/HudItem.cpp @@ -21,6 +21,11 @@ #include "HUDAnimItem.h" #include "ActorEffector.h" +#ifdef DEBUG_DRAW +extern u32 hud_adj_mode; +#include "debug_renderer.h" +#endif + ENGINE_API extern float psHUD_FOV_def; CHudItem::CHudItem() @@ -145,29 +150,24 @@ void CHudItem::PlaySound(LPCSTR alias, const Fvector& position, bool allowOverla m_sounds.PlaySound(alias, position, object().H_Root(), !!GetHUDmode(), false, allowOverlap, m_started_rnd_anim_idx); } -void CHudItem::renderable_Render() +void CHudItem::renderable_Render() { - UpdateXForm (); - BOOL _hud_render = ::Render->get_HUD() && GetHUDmode(); - - if(_hud_render && !IsHidden()) - { + UpdateXForm(); + BOOL _hud_render = ::Render->get_HUD() && GetHUDmode(); + + if(_hud_render && !IsHidden()) { } - else - { - if (!object().H_Parent() || (!_hud_render && !IsHidden())) - { - on_renderable_Render (); - debug_draw_firedeps (); - }else - if (object().H_Parent()) - { - CInventoryOwner *owner = smart_cast(object().H_Parent()); - VERIFY (owner); - CInventoryItem *self = smart_cast(this); - if (owner->attached(self) || - (item().BaseSlot() == INV_SLOT_3 /*|| item().BaseSlot() == INV_SLOT_2*/)) + else { + if(!object().H_Parent() || (!_hud_render && !IsHidden())) { + on_renderable_Render(); + } + else if(object().H_Parent()) { + CInventoryOwner* owner = smart_cast(object().H_Parent()); + VERIFY(owner); + CInventoryItem* self = smart_cast(this); + if(owner->attached(self) || item().BaseSlot() == INV_SLOT_3) { on_renderable_Render(); + } } } } @@ -1131,6 +1131,31 @@ bool CHudItem::isSuicideByAnimation(void) const return m_bSuicideByAnimation; } +void CHudItem::debug_draw_firedeps() { +#if 0 //def DEBUG_DRAW + if(hud_adj_mode != 3 && hud_adj_mode != 4) { + return; + } + + auto xf = object().XFORM(); + auto model = object().Visual(); + + if(GetHUDmode()) { + xf = HudItemData()->m_item_transform; + model = HudItemData()->m_model->dcast_RenderVisual(); + } + + vis_data data = model->getVisData(); + Fvector center = {}, halfsize = {}; + + data.box.get_CD(center, halfsize); + xf.transform_tiny(center); + xf.c.set(center); + + Level().debug_renderer().draw_obb(xf, halfsize, color_xrgb(255, 0, 255)); +#endif +} + void CHudItem::SetModelBoneStatus(const char* bone, BOOL show) const { if (HudItemData()) { diff --git a/src/xrGame/HudItem.h b/src/xrGame/HudItem.h index 662845e817..8b1bc6210e 100644 --- a/src/xrGame/HudItem.h +++ b/src/xrGame/HudItem.h @@ -239,7 +239,7 @@ class CHudItem :public CHUDState void SetAnimationCallback(TAnimationEffector callback) { lock_time_callback = callback; } virtual void on_renderable_Render () = 0; - virtual void debug_draw_firedeps () {}; + virtual void debug_draw_firedeps (); virtual CHudItem* cast_hud_item () { return this; } }; diff --git a/src/xrGame/UIGameSP.cpp b/src/xrGame/UIGameSP.cpp index 7453b2f685..0dbb9f8534 100644 --- a/src/xrGame/UIGameSP.cpp +++ b/src/xrGame/UIGameSP.cpp @@ -82,6 +82,11 @@ void CUIGameSP::OnFrame() m_game_objective = nullptr; } } + +#ifndef MASTER_GOLD + hud_draw_adjust_mode(); + attach_draw_adjust_mode(); +#endif } bool CUIGameSP::IR_UIOnKeyboardPress(int dik) @@ -144,8 +149,6 @@ bool CUIGameSP::IR_UIOnKeyboardPress(int dik) void CUIGameSP::Render() { inherited::Render(); - hud_draw_adjust_mode(); - attach_draw_adjust_mode(); } #endif diff --git a/src/xrGame/Weapon.cpp b/src/xrGame/Weapon.cpp index a645167251..c8efd6ac1b 100644 --- a/src/xrGame/Weapon.cpp +++ b/src/xrGame/Weapon.cpp @@ -3996,29 +3996,51 @@ const bool CWeapon::ParentIsActor() const return Parent != nullptr && smart_cast(Parent) != nullptr; } -void CWeapon::debug_draw_firedeps() -{ -#ifdef DEBUG - if(hud_adj_mode==5||hud_adj_mode==6||hud_adj_mode==7) - { - CDebugRenderer &render = Level().debug_renderer(); +extern void TransformToHudTemp(Fvector&); - if (hud_adj_mode == 5) - render.draw_aabb(get_LastFP(), 0.005f, 0.005f, 0.005f, color_xrgb(255, 0, 0)); +void CWeapon::debug_draw_firedeps() { + inherited::debug_draw_firedeps(); - if (hud_adj_mode == 6) - render.draw_aabb(get_LastFP2(), 0.005f, 0.005f, 0.005f, color_xrgb(0, 0, 255)); +#ifdef DEBUG_DRAW + Fmatrix xf = GetHUDmode() ? HudItemData()->m_item_transform : XFORM(); + u32 color = 0; - if (hud_adj_mode == 7) - render.draw_aabb(get_LastSP(), 0.005f, 0.005f, 0.005f, color_xrgb(0, 255, 0)); + switch(hud_adj_mode) + { + case 3: + case 4: + case 5: + { + xf.c = get_LastFP(); + color = color_xrgb(255, 0, 0); + } + break; + case 6: + { + xf.c = get_LastFP2(); + color = color_xrgb(0, 0, 255); + } + break; + case 7: + { + xf.c = get_LastSP(); + color = color_xrgb(0, 255, 0); + } + break; + default: + { + return; + } } -#endif // DEBUG + + Level().debug_renderer().draw_obb(xf, {0.008f, 0.008f, 0.008f}, color); +#endif } -const float &CWeapon::hit_probability () const -{ - VERIFY ((g_SingleGameDifficulty >= egdNovice) && (g_SingleGameDifficulty <= egdMaster)); - return (m_hit_probability[egdNovice]); + +const float& CWeapon::hit_probability() const { + VERIFY((g_SingleGameDifficulty >= egdNovice) && (g_SingleGameDifficulty <= egdMaster)); + return (m_hit_probability[egdNovice]); } BOOL EnableDof = true; diff --git a/src/xrGame/player_hud.cpp b/src/xrGame/player_hud.cpp index e781c45822..9478ce963f 100644 --- a/src/xrGame/player_hud.cpp +++ b/src/xrGame/player_hud.cpp @@ -11,7 +11,7 @@ #include "WeaponBinoculars.h" player_hud* g_player_hud = nullptr; -player_hud* g_player_hud2 = nullptr; + Fvector _ancor_pos; Fvector _wpn_root_pos; @@ -322,7 +322,9 @@ void attachable_hud_item::render() { ::Render->set_Transform (&m_item_transform); ::Render->add_Visual (m_model->dcast_RenderVisual(), true); + debug_draw_firedeps (); + m_parent_hud_item->render_hud_mode(); } @@ -638,7 +640,7 @@ void player_hud::load(const shared_str& player_hud_sect) u16 l_arm = m_model->dcast_PKinematics()->LL_BoneID("l_clavicle"); if(l_arm != BI_NONE) { - m_model->dcast_PKinematics()->LL_GetBoneInstance(l_arm).set_callback(bctCustom, [](CBoneInstance* B) {g_player_hud->LeftArmCallback(B); }, NULL); + m_model->dcast_PKinematics()->LL_GetBoneInstance(l_arm).set_callback(bctCustom, [](CBoneInstance* B) { g_player_hud->LeftArmCallback(B); }, NULL); } auto& _sect = pSettings->r_section(player_hud_sect); @@ -805,36 +807,42 @@ u32 player_hud::motion_length(const MotionID& M, const CMotionDef*& md, float sp const Fvector& player_hud::attach_rot() const { static Fvector m_last_rot = zero_vel; - if (m_attached_items[0]) - return m_last_rot=m_attached_items[0]->hands_attach_rot(); - else - { - if (m_attached_items[1]) - return m_last_rot=m_attached_items[1]->hands_attach_rot(); + + if(m_attached_items[0]) { + m_last_rot = m_attached_items[0]->hands_attach_rot(); } + else if(m_attached_items[1]) { + m_last_rot = m_attached_items[1]->hands_attach_rot(); + } + return m_last_rot; } const Fvector& player_hud::attach_pos() const { static Fvector m_last_pos = zero_vel; - if (m_attached_items[0]) - return m_last_pos=m_attached_items[0]->hands_attach_pos(); - else - { - if (m_attached_items[1]) - return m_last_pos=m_attached_items[1]->hands_attach_pos(); + + if(m_attached_items[0]) { + m_last_pos = m_attached_items[0]->hands_attach_pos(); + } + else if(m_attached_items[1]) { + m_last_pos = m_attached_items[1]->hands_attach_pos(); } + return m_last_pos; } void player_hud::LeftArmCallback(CBoneInstance* B) { - if(!m_attached_items[1]) + if(!m_attached_items[1]) { return; + } + + static Fmatrix inv_transform; + inv_transform.invert(m_transform); - B->mTransform.mulA_44(m_attached_items[1]?m_transformL:m_transform); - B->mTransform.mulA_44(Fmatrix(m_transform).invert()); + B->mTransform.mulA_44(m_transformL); + B->mTransform.mulA_44(inv_transform); } void angle_inertion(Fvector& c_hpb, const Fvector& t_hpb, float speed) @@ -844,109 +852,83 @@ void angle_inertion(Fvector& c_hpb, const Fvector& t_hpb, float speed) c_hpb.x = angle_inertion(c_hpb.x, t_hpb.x, speed, PI, Device.fTimeDelta); } -#include "Missile.h" - -void player_hud::update(const Fmatrix& cam_trans) +void player_hud::update(const Fmatrix& trans) { - if(!m_attached_items[0] && !m_attached_items[1]) - { - m_transform.set(cam_trans); - m_transformL.set(cam_trans); + Fmatrix cam_trans = trans; + update_inertion(cam_trans); + + m_transform.set(cam_trans); + m_transformL.set(cam_trans); + + if(!m_attached_items[0] && !m_attached_items[1]) { return; } - Fmatrix trans = cam_trans; - update_inertion (trans); - update_additional (trans); + update_additional(m_transform); + Fvector ypr = attach_rot(); + ypr.mul(PI / 180.f); - { - m_attach_offsetr.setHPB(VPUSH(Fvector(attach_rot()).mul(PI / 180.f)));//generate and set Euler angles - m_attach_offsetr.c.set(attach_pos()); - m_transform.mul(trans, m_attach_offsetr); - } + m_attach_offsetr.setHPB(ypr.x, ypr.y, ypr.z); + m_attach_offsetr.translate_over(attach_pos()); + + m_transform.mulB_44(m_attach_offsetr); + if(m_attached_items[1]) { - bool isGuns = EngineExternal().isModificationGunslinger(); - CMissile* pMiss = m_attached_items[0] && !isGuns ? smart_cast(m_attached_items[0]->m_parent_hud_item) : NULL; - bool throwing_missile = pMiss && (pMiss->GetState()>=CMissile::EMissileStates::eThrowStart&&pMiss->GetState()<=CMissile::EMissileStates::eThrow); - bool left_hand_active = !throwing_missile && m_attached_items[1]; + ypr = m_attached_items[1]->hands_attach_rot(); + ypr.mul(PI / 180.f); + + m_attach_offsetl.setHPB(ypr.x, ypr.y, ypr.z); + m_attach_offsetl.translate_over(m_attached_items[1]->hands_attach_pos()); - Fmatrix attach_offset; - attach_offset.setHPB(VPUSH(Fvector(left_hand_active ? m_attached_items[1]->hands_attach_rot() : attach_rot()).mul(PI / 180.f)));//generate and set Euler angles - attach_offset.c.set(left_hand_active ? m_attached_items[1]->hands_attach_pos() : attach_pos()); - m_transformL.mul(trans, left_hand_active ? m_attach_offsetl.set(attach_offset) : m_attach_offsetl.inertion(attach_offset, 1-Device.fTimeDelta*10.f)); + m_transformL.mulB_44(m_attach_offsetl); + } + else { + m_transformL.set(m_transform); } - m_model->UpdateTracks(); m_model->dcast_PKinematics()->CalculateBones_Invalidate(); m_model->dcast_PKinematics()->CalculateBones(TRUE); - if(m_attached_items[0]) + if(m_attached_items[0]) { m_attached_items[0]->update(true); + } - if(m_attached_items[1]) + if(m_attached_items[1]) { m_attached_items[1]->update(true); + } } u32 player_hud::anim_play(u16 part, const MotionID& M, BOOL bMixIn, const CMotionDef*& md, float speed) { - ///partitions info - // 0==default (root_bone) - // 1==left_hand (left hand bone hierarchy) - // 2==right_hand (right hand bone hierarchy) - // please append new bone parts for more realistic behavior of animations - bool disable_root_part = false; - u16 part_id = u16(-1); - if(attached_item(0) && attached_item(1)) - { - disable_root_part = part==1;//if we run the animation for the left hand, we don't include the animation for the root bone (only if attached_item 1 active). - part_id = m_model->partitions().part_id((part==0)?"right_hand":"left_hand"); + u16 part_id = u16(-1); + + if(attached_item(0) && attached_item(1)) { + part_id = m_model->partitions().part_id(part == 0 ? "right_hand" : "left_hand"); } - bool isGuns = EngineExternal().isModificationGunslinger(); + u16 pc = m_model->partitions().count(); + for(u16 pid = 0; pid < pc; ++pid) { + if(pid == 0 || pid == part_id || part_id == u16(-1)) { + if(m_blocked_part_idx == pid) continue; - CMissile* pMiss = m_attached_items[0] && !isGuns ? smart_cast(m_attached_items[0]->m_parent_hud_item) : NULL; - bool throwing_missile = pMiss && (pMiss->GetState()>=CMissile::EMissileStates::eThrowStart&&pMiss->GetState()<=CMissile::EMissileStates::eThrow) && attached_item(1); - if (throwing_missile)//is the only when attached_item 1 is active and we have started throwing the item - { - if(part==0) - { - CBlend* B = NULL; - B = m_model->PlayCycle(0, M, bMixIn); - B = m_model->PlayCycle(1, M, bMixIn); - B = m_model->PlayCycle(2, M, bMixIn); + CBlend* B = m_model->PlayCycle(pid, M, part == 0 && pid == 0 && attached_item(1) ? TRUE : bMixIn); B->speed *= speed; } } - else - { - u16 pc = m_model->partitions().count(); - for(u16 pid=0; pidPlayCycle(pid, M, part==0&&pid==0&&attached_item(1)?TRUE:bMixIn); - B->speed *= speed; - } - } - } - m_model->dcast_PKinematics()->CalculateBones_Invalidate (); - return motion_length(M, md, speed); + m_model->dcast_PKinematics()->CalculateBones_Invalidate(); + return motion_length(M, md, speed); } -void player_hud::update_additional (Fmatrix& trans) +void player_hud::update_additional(Fmatrix& trans) { - if(m_attached_items[0] || m_attached_items[0]&&m_attached_items[1]) - m_attached_items[0]->update_hud_additional(trans); - else - { - if(m_attached_items[1]) - m_attached_items[1]->update_hud_additional(trans); + if(m_attached_items[0]) { + m_attached_items[0]->update_hud_additional(m_transform); + } + if(m_attached_items[1]) { + m_attached_items[1]->update_hud_additional(m_transformL); } } @@ -954,39 +936,40 @@ void player_hud::update_inertion(Fmatrix& trans) { auto hi = m_attached_items[0] ? m_attached_items[0] : m_attached_items[1]; - if (hi) - { + if(hi) { auto& inertion = hi->m_parent_hud_item->CurrentInertionData(); - Fmatrix xform; - Fvector& origin = trans.c; - xform = trans; + Fmatrix xform; + Fvector& origin = trans.c; + xform = trans; - static Fvector st_last_dir={0,0,0}; + static Fvector st_last_dir = {0,0,0}; // calc difference - Fvector diff_dir; - diff_dir.sub (xform.k, st_last_dir); + Fvector diff_dir; + diff_dir.sub(xform.k, st_last_dir); // clamp by PI_DIV_2 - Fvector last; last.normalize_safe(st_last_dir); - float dot = last.dotproduct(xform.k); - if (dot::iterator it = m_pool.begin(); xr_vector::iterator it_e = m_pool.end(); - for(;it!=it_e;++it) - { + + for(; it != it_e; ++it) { attachable_hud_item* itm = *it; - if(itm->m_sect_name==sect) + if(itm->m_sect_name == sect) return itm; } - attachable_hud_item* res = new attachable_hud_item(this); - res->load (sect); - res->m_hand_motions.load (m_model, sect); - m_pool.push_back (res); + + attachable_hud_item* res = new attachable_hud_item(this); + + res->load(sect); + res->m_hand_motions.load(m_model, sect); + m_pool.push_back(res); return res; } @@ -1460,27 +1445,26 @@ void player_hud::animator_fx_play(const shared_str& anim_name, u16 place_idx, u1 } } -player_hud::default_hud_coords_params player_hud::GetDefaultHudCoords(shared_str hud_sect) +player_hud::default_hud_coords_params player_hud::GetDefaultHudCoords(shared_str hud_sect, u16 idx, bool forse) { - if (_last_default_hud_params.hud_sect != hud_sect || UI().is_widescreen() != _last_default_hud_params.is16x9) + if (last_default_hud_params[idx].hud_sect != hud_sect || UI().is_widescreen() != last_default_hud_params[idx].is16x9 || forse) { - Fvector3 zerovec = { 0,0,0 }; - _last_default_hud_params.hud_sect = hud_sect; - _last_default_hud_params.is16x9 = UI().is_widescreen(); + last_default_hud_params[idx].hud_sect = hud_sect; + last_default_hud_params[idx].is16x9 = UI().is_widescreen(); - if (_last_default_hud_params.is16x9) + if (last_default_hud_params[idx].is16x9) { - _last_default_hud_params.hands_position = READ_IF_EXISTS(pSettings, r_fvector3, hud_sect, "hands_position_16x9", zerovec); - _last_default_hud_params.hands_orientation = READ_IF_EXISTS(pSettings, r_fvector3, hud_sect, "hands_orientation_16x9", zerovec); + last_default_hud_params[idx].hands_position = READ_IF_EXISTS(pSettings, r_fvector3, hud_sect, "hands_position_16x9", zero_vel); + last_default_hud_params[idx].hands_orientation = READ_IF_EXISTS(pSettings, r_fvector3, hud_sect, "hands_orientation_16x9", zero_vel); } else { - _last_default_hud_params.hands_position = READ_IF_EXISTS(pSettings, r_fvector3, hud_sect, "hands_position", zerovec); - _last_default_hud_params.hands_orientation = READ_IF_EXISTS(pSettings, r_fvector3, hud_sect, "hands_orientation", zerovec); + last_default_hud_params[idx].hands_position = READ_IF_EXISTS(pSettings, r_fvector3, hud_sect, "hands_position", zero_vel); + last_default_hud_params[idx].hands_orientation = READ_IF_EXISTS(pSettings, r_fvector3, hud_sect, "hands_orientation", zero_vel); } } - return _last_default_hud_params; + return last_default_hud_params[idx]; } float player_hud::GetCachedCfgParamFloatDef(cached_cfg_param_float& cached, const shared_str section, const shared_str key, float def) @@ -1908,8 +1892,14 @@ void player_hud::UpdateWeaponOffset(u32 delta) if (det != nullptr) { - attached_item(1)->set_hands_offset_pos(cur_pos); - attached_item(1)->set_hands_offset_rot(cur_rot); + auto detector_hud = attached_item(1); + auto det_hud_params = GetDefaultHudCoords(det->HudSection(), 1); + + cur_pos.sub(def_hud_params.hands_position).add(det_hud_params.hands_position); + cur_rot.sub(def_hud_params.hands_orientation).add(det_hud_params.hands_orientation); + + detector_hud->set_hands_offset_pos(cur_pos); + detector_hud->set_hands_offset_rot(cur_rot); } time_accumulator -= 8; @@ -1946,7 +1936,7 @@ void player_hud::ResetItmHudOffset(CHudItem* itm) if (hid == nullptr) return; - default_hud_coords_params def_hud_params = GetDefaultHudCoords(itm->HudSection()); + default_hud_coords_params def_hud_params = GetDefaultHudCoords(itm->HudSection(), hid->m_attach_place_idx); hid->set_hands_offset_pos(def_hud_params.hands_position); hid->set_hands_offset_rot(def_hud_params.hands_orientation); diff --git a/src/xrGame/player_hud.h b/src/xrGame/player_hud.h index da75d3b78a..8c9aecee13 100644 --- a/src/xrGame/player_hud.h +++ b/src/xrGame/player_hud.h @@ -171,8 +171,7 @@ class player_hud void SetHandsVisible(bool val){m_bhands_visible=val;}; bool GetHandsVisible(){return m_bhands_visible;}; void UpdateWeaponOffset(u32 delta); - default_hud_coords_params GetDefaultHudCoords(shared_str hud_sect); - default_hud_coords_params _last_default_hud_params; + default_hud_coords_params GetDefaultHudCoords(shared_str hud_sect, u16 idx = 0, bool forse = false); static float GetCachedCfgParamFloatDef(cached_cfg_param_float& cached, const shared_str section, const shared_str key, float def); void GetCurrentTargetOffset_aim(shared_str section, Fvector3& pos, Fvector3& rot, float& factor); void GetCurrentTargetOffset(shared_str section, Fvector3& pos, Fvector3& rot, float& factor); @@ -224,6 +223,7 @@ class player_hud IKinematicsAnimated* m_model; xr_vector m_ancors; attachable_hud_item* m_attached_items[2]; + default_hud_coords_params last_default_hud_params[2]; xr_vector m_pool; u16 m_blocked_part_idx; diff --git a/src/xrGame/player_hud_tune.cpp b/src/xrGame/player_hud_tune.cpp index 705932f0ca..bd2f3e1ab9 100644 --- a/src/xrGame/player_hud_tune.cpp +++ b/src/xrGame/player_hud_tune.cpp @@ -11,171 +11,180 @@ #include "../../xrUI/ui_base.h" #include "debug_renderer.h" -u32 hud_adj_mode = 0; -u32 hud_adj_item_idx = 0; -bool hud_adj_crosshair = false; -// "press SHIFT+NUM 0-return 1-hud_pos 2-hud_rot 3-itm_pos 4-itm_rot 5-fire_point 6-fire_2_point 7-shell_point"; - -float _delta_pos = 0.0005f; -float _delta_rot = 0.05f; - -bool is_attachable_item_tuning_mode() -{ - return pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT) || - pInput->iGetAsyncKeyState(SDL_SCANCODE_Z) || - pInput->iGetAsyncKeyState(SDL_SCANCODE_X) || - pInput->iGetAsyncKeyState(SDL_SCANCODE_C); +u32 hud_adj_mode = 0; +u32 hud_adj_item_idx = 0; +bool hud_adj_crosshair = false; + +float _delta_pos = 0.0005f; +float _delta_rot = 0.05f; + +bool is_attachable_item_tuning_mode() { + return pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT) || + pInput->iGetAsyncKeyState(SDL_SCANCODE_Z) || + pInput->iGetAsyncKeyState(SDL_SCANCODE_X) || + pInput->iGetAsyncKeyState(SDL_SCANCODE_C); } void tune_remap(const Ivector& in_values, Ivector& out_values) { - if( pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT) ) - { - out_values = in_values; - }else - if( pInput->iGetAsyncKeyState(SDL_SCANCODE_Z) ) - { //strict by X - out_values.x = in_values.y; + if(pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT)) { + out_values.x = -in_values.x; + out_values.y = -in_values.y; + + out_values.z = in_values.z; + } + else if(pInput->iGetAsyncKeyState(SDL_SCANCODE_Z)) { out_values.y = 0; out_values.z = 0; - }else - if( pInput->iGetAsyncKeyState(SDL_SCANCODE_X) ) - { //strict by Y + + out_values.x = in_values.z - in_values.x - in_values.y; + } + else if(pInput->iGetAsyncKeyState(SDL_SCANCODE_X)) { out_values.x = 0; - out_values.y = in_values.y; out_values.z = 0; - }else - if( pInput->iGetAsyncKeyState(SDL_SCANCODE_C) ) - { //strict by Z + + out_values.y = in_values.x - in_values.y + in_values.z; + } + else if(pInput->iGetAsyncKeyState(SDL_SCANCODE_C)) { out_values.x = 0; out_values.y = 0; - out_values.z = in_values.y; - }else - { - out_values.set(0,0,0); + + out_values.z = in_values.x - in_values.y + in_values.z; + } + else { + out_values.set(0, 0, 0); } } void calc_cam_diff_pos(Fmatrix item_transform, Fvector diff, Fvector& res) { - Fmatrix cam_m; - cam_m.i.set (Device.vCameraRight); - cam_m.j.set (Device.vCameraTop); - cam_m.k.set (Device.vCameraDirection); - cam_m.c.set (Device.vCameraPosition); + Fmatrix cam_m = Fidentity; + cam_m.i.set(Device.vCameraRight); + cam_m.j.set(Device.vCameraTop); + cam_m.k.set(Device.vCameraDirection); + cam_m.c.set(Device.vCameraPosition); - Fvector res1; - cam_m.transform_dir (res1, diff); + Fvector res1; + cam_m.transform_dir(res1, diff); - Fmatrix item_transform_i; - item_transform_i.invert (item_transform); - item_transform_i.transform_dir (res, res1); + Fmatrix item_transform_i; + item_transform_i.invert(item_transform); + item_transform_i.transform_dir(res, res1); } -void calc_cam_diff_rot(Fmatrix item_transform, Fvector diff, Fvector& res) -{ - Fmatrix cam_m; - cam_m.i.set (Device.vCameraRight); - cam_m.j.set (Device.vCameraTop); - cam_m.k.set (Device.vCameraDirection); - cam_m.c.set (Device.vCameraPosition); - - Fmatrix R; - R.identity (); - if(!fis_zero(diff.x)) - { - R.rotation(cam_m.i,diff.x); - }else - if(!fis_zero(diff.y)) - { - R.rotation(cam_m.j,diff.y); - }else - if(!fis_zero(diff.z)) - { - R.rotation(cam_m.k,diff.z); - }; +void calc_cam_diff_rot(Fmatrix item_transform, Fvector diff, Fvector& res) { + Fmatrix cam_m = Fidentity; + + cam_m.i.set(Device.vCameraRight); + cam_m.j.set(Device.vCameraTop); + cam_m.k.set(Device.vCameraDirection); + cam_m.c.set(Device.vCameraPosition); + + Fmatrix R = Fidentity; + + if(!fis_zero(diff.x)) { + R.rotation(cam_m.i, diff.x); + } + else if(!fis_zero(diff.y)) { + R.rotation(cam_m.j, diff.y); + } + else if(!fis_zero(diff.z)) { + R.rotation(cam_m.k, diff.z); + } + + Fmatrix item_transform_i; + item_transform_i.invert(item_transform); - Fmatrix item_transform_i; - item_transform_i.invert (item_transform); R.mulB_43(item_transform); R.mulA_43(item_transform_i); - - R.getHPB (res); - res.mul (180.0f/PI); + R.getHPB(res); + res.mul(180.0f / PI); } void attachable_hud_item::tune(Ivector values) { #ifndef MASTER_GOLD - if(!is_attachable_item_tuning_mode() ) + if(!is_attachable_item_tuning_mode()) { return; + } - Fvector diff; - diff.set (0,0,0); + Fvector diff = zero_vel; - if(hud_adj_mode==3 || hud_adj_mode==4) + if(hud_adj_mode == 3 || hud_adj_mode == 4) { - if(hud_adj_mode==3) - { - if(values.x) diff.x = (values.x>0)?_delta_pos:-_delta_pos; - if(values.y) diff.y = (values.y>0)?_delta_pos:-_delta_pos; - if(values.z) diff.z = (values.z>0)?_delta_pos:-_delta_pos; - - Fvector d; - Fmatrix ancor_m; - m_parent->calc_transform (m_attach_place_idx, Fidentity, ancor_m); - calc_cam_diff_pos (ancor_m, diff, d); - m_measures.m_item_attach[0].add (d); - }else - if(hud_adj_mode==4) - { - if(values.x) diff.x = (values.x>0)?_delta_rot:-_delta_rot; - if(values.y) diff.y = (values.y>0)?_delta_rot:-_delta_rot; - if(values.z) diff.z = (values.z>0)?_delta_rot:-_delta_rot; + Fvector d; + Fmatrix ancor_m; + + if(hud_adj_mode == 3) { + if(values.x) { + diff.x = (values.x > 0) ? _delta_pos : -_delta_pos; + } + if(values.y) { + diff.y = (values.y > 0) ? _delta_pos : -_delta_pos; + } + if(values.z) { + diff.z = (values.z > 0) ? _delta_pos : -_delta_pos; + } + + m_parent->calc_transform(m_attach_place_idx, Fidentity, ancor_m); + + calc_cam_diff_pos(ancor_m, diff, d); + m_measures.m_item_attach[0].add(d); + } + else if(hud_adj_mode == 4) { + if(values.x) { + diff.x = (values.x > 0) ? _delta_rot : -_delta_rot; + } + if(values.y) { + diff.y = (values.y > 0) ? _delta_rot : -_delta_rot; + } + if(values.z) { + diff.z = (values.z > 0) ? _delta_rot : -_delta_rot; + } - Fvector d; - Fmatrix ancor_m; - m_parent->calc_transform (m_attach_place_idx, Fidentity, ancor_m); + m_parent->calc_transform(m_attach_place_idx, Fidentity, ancor_m); - calc_cam_diff_pos (m_item_transform, diff, d); - m_measures.m_item_attach[1].add (d); + calc_cam_diff_pos(m_item_transform, diff, d); + m_measures.m_item_attach[1].add(d); } - if((values.x)||(values.y)||(values.z)) + if((values.x) || (values.y) || (values.z)) { Msg("[%s]",m_sect_name.c_str()); - Msg("item_position = %f,%f,%f",m_measures.m_item_attach[0].x, m_measures.m_item_attach[0].y, m_measures.m_item_attach[0].z); - Msg("item_orientation = %f,%f,%f",m_measures.m_item_attach[1].x, m_measures.m_item_attach[1].y, m_measures.m_item_attach[1].z); + Msg("item_position = %.6f,%.6f,%.6f",m_measures.m_item_attach[0].x, m_measures.m_item_attach[0].y, m_measures.m_item_attach[0].z); + Msg("item_orientation = %.6f,%.6f,%.6f",m_measures.m_item_attach[1].x, m_measures.m_item_attach[1].y, m_measures.m_item_attach[1].z); Log("-----------"); } } - if(hud_adj_mode==5||hud_adj_mode==6||hud_adj_mode==7) - { - if(values.x) diff.x = (values.x>0)?_delta_pos:-_delta_pos; - if(values.y) diff.y = (values.y>0)?_delta_pos:-_delta_pos; - if(values.z) diff.z = (values.z>0)?_delta_pos:-_delta_pos; + if(hud_adj_mode == 5 || hud_adj_mode == 6 || hud_adj_mode == 7) { + if(values.x) { + diff.x = (values.x > 0) ? _delta_pos : -_delta_pos; + } + if(values.y) { + diff.y = (values.y > 0) ? _delta_pos : -_delta_pos; + } + if(values.z) { + diff.z = (values.z > 0) ? _delta_pos : -_delta_pos; + } - if(hud_adj_mode==5) - { + if(hud_adj_mode == 5) { m_measures.m_fire_point_offset.add(diff); } - if(hud_adj_mode==6) - { + else if(hud_adj_mode == 6) { m_measures.m_fire_point2_offset.add(diff); } - if(hud_adj_mode==7) - { + else if(hud_adj_mode == 7) { m_measures.m_shell_point_offset.add(diff); } - if((values.x)||(values.y)||(values.z)) - { - Msg("[%s]", m_sect_name.c_str()); - Msg("fire_point = %f,%f,%f",m_measures.m_fire_point_offset.x, m_measures.m_fire_point_offset.y, m_measures.m_fire_point_offset.z); - Msg("fire_point2 = %f,%f,%f",m_measures.m_fire_point2_offset.x, m_measures.m_fire_point2_offset.y, m_measures.m_fire_point2_offset.z); - Msg("shell_point = %f,%f,%f",m_measures.m_shell_point_offset.x, m_measures.m_shell_point_offset.y, m_measures.m_shell_point_offset.z); + + if((values.x) || (values.y) || (values.z)) { + Msg("[%s]", m_sect_name.c_str()); + Msg("fire_point = %.6f,%.6f,%.6f", m_measures.m_fire_point_offset.x, m_measures.m_fire_point_offset.y, m_measures.m_fire_point_offset.z); + Msg("fire_point2 = %.6f,%.6f,%.6f", m_measures.m_fire_point2_offset.x, m_measures.m_fire_point2_offset.y, m_measures.m_fire_point2_offset.z); + Msg("shell_point = %.6f,%.6f,%.6f", m_measures.m_shell_point_offset.x, m_measures.m_shell_point_offset.y, m_measures.m_shell_point_offset.z); Log("-----------"); } } @@ -185,201 +194,174 @@ void attachable_hud_item::tune(Ivector values) void attachable_hud_item::debug_draw_firedeps() { #ifndef MASTER_GOLD - bool bForce = (hud_adj_mode==3||hud_adj_mode==4); - - if(hud_adj_mode==5||hud_adj_mode==6||hud_adj_mode==7 ||bForce) - { - CDebugRenderer &render = Level().debug_renderer(); - - firedeps fd; - setup_firedeps (fd); - - if (hud_adj_mode == 5 || bForce) - render.draw_aabb(fd.vLastFP, 0.005f, 0.005f, 0.005f, color_xrgb(255, 0, 0)); - - if (hud_adj_mode == 6) - render.draw_aabb(fd.vLastFP2, 0.005f, 0.005f, 0.005f, color_xrgb(0, 0, 255)); - - if (hud_adj_mode == 7) - render.draw_aabb(fd.vLastSP, 0.005f, 0.005f, 0.005f, color_xrgb(0, 255, 0)); + if(!m_parent_hud_item || m_attach_place_idx != hud_adj_item_idx) { + return; } -#endif // DEBUG + m_parent_hud_item->debug_draw_firedeps(); +#endif } -void player_hud::tune(Ivector _values) -{ +void player_hud::tune(Ivector _values) { #ifndef MASTER_GOLD - Ivector values; - tune_remap (_values,values); - - bool is_16x9 = UI().is_widescreen(); + Ivector values; + tune_remap(_values, values); - auto is_attached = m_attached_items[hud_adj_item_idx]; + bool is_16x9 = UI().is_widescreen(); - if (!is_attached) + if(!m_attached_items[hud_adj_item_idx]) { return; + } - if(hud_adj_mode==1 || hud_adj_mode==2) + if(hud_adj_mode == 1 || hud_adj_mode == 2) { - Fvector diff; - diff.set (0,0,0); - - float _curr_dr = _delta_rot; + Fvector diff = zero_vel; + float _curr_dr = _delta_rot; + u8 idx = m_attached_items[hud_adj_item_idx]->m_parent_hud_item->GetCurrentHudOffsetIdx(); - u8 idx = m_attached_items[hud_adj_item_idx]->m_parent_hud_item->GetCurrentHudOffsetIdx(); - if(idx) - _curr_dr /= 20.0f; + if(idx) { + _curr_dr /= 20.0f; + } - Fvector& pos_ =(idx!=0)?m_attached_items[hud_adj_item_idx]->hands_offset_pos():m_attached_items[hud_adj_item_idx]->hands_attach_pos(); - Fvector& rot_ =(idx!=0)?m_attached_items[hud_adj_item_idx]->hands_offset_rot():m_attached_items[hud_adj_item_idx]->hands_attach_rot(); + Fvector& pos_ = idx != 0 ? m_attached_items[hud_adj_item_idx]->hands_offset_pos() : last_default_hud_params[hud_adj_item_idx].hands_position; + Fvector& rot_ = idx != 0 ? m_attached_items[hud_adj_item_idx]->hands_offset_rot() : last_default_hud_params[hud_adj_item_idx].hands_orientation; - if(hud_adj_mode==1) - { - if(values.x) diff.x = (values.x<0)?_delta_pos:-_delta_pos; - if(values.y) diff.y = (values.y>0)?_delta_pos:-_delta_pos; - if(values.z) diff.z = (values.z>0)?_delta_pos:-_delta_pos; + if(hud_adj_mode == 1) { + if(values.x) { + diff.x = (values.x < 0) ? _delta_pos : -_delta_pos; + } + if(values.y) { + diff.y = (values.y > 0) ? _delta_pos : -_delta_pos; + } + if(values.z) { + diff.z = (values.z > 0) ? _delta_pos : -_delta_pos; + } - pos_.add (diff); + pos_.add(diff); } - if(hud_adj_mode==2) - { - if(values.x) diff.x = (values.x>0)?_curr_dr:-_curr_dr; - if(values.y) diff.y = (values.y>0)?_curr_dr:-_curr_dr; - if(values.z) diff.z = (values.z>0)?_curr_dr:-_curr_dr; + if(hud_adj_mode == 2) { + if(values.x) { + diff.x = values.x > 0 ? _curr_dr : -_curr_dr; + } + if(values.y) { + diff.y = values.y > 0 ? _curr_dr : -_curr_dr; + } + if(values.z) { + diff.z = values.z > 0 ? _curr_dr : -_curr_dr; + } - rot_.add (diff); + rot_.add(diff); } - if( (values.x)||(values.y)||(values.z) ) - { - if(idx==0) - { + + if((values.x) || (values.y) || (values.z)) { + if(idx == 0) { Msg("[%s]", m_attached_items[hud_adj_item_idx]->m_sect_name.c_str()); - Msg("hands_position%s = %f,%f,%f",(is_16x9)?"_16x9":"", pos_.x, pos_.y, pos_.z); - Msg("hands_orientation%s = %f,%f,%f",(is_16x9)?"_16x9":"", rot_.x, rot_.y, rot_.z); + Msg("hands_position%s = %.6f,%.6f,%.6f", (is_16x9) ? "_16x9" : "", pos_.x, pos_.y, pos_.z); + Msg("hands_orientation%s = %.6f,%.6f,%.6f", (is_16x9) ? "_16x9" : "", rot_.x, rot_.y, rot_.z); Log("-----------"); - }else - if(idx==1) - { + } + else if(idx == 1) { Msg("[%s]", m_attached_items[hud_adj_item_idx]->m_sect_name.c_str()); - Msg("aim_hud_offset_pos%s = %f,%f,%f",(is_16x9)?"_16x9":"", pos_.x, pos_.y, pos_.z); - Msg("aim_hud_offset_rot%s = %f,%f,%f",(is_16x9)?"_16x9":"", rot_.x, rot_.y, rot_.z); + Msg("aim_hud_offset_pos%s = %.6f,%.6f,%.6f", (is_16x9) ? "_16x9" : "", pos_.x, pos_.y, pos_.z); + Msg("aim_hud_offset_rot%s = %.6f,%.6f,%.6f", (is_16x9) ? "_16x9" : "", rot_.x, rot_.y, rot_.z); Log("-----------"); - }else - if(idx==2) - { + } + else if(idx == 2) { Msg("[%s]", m_attached_items[hud_adj_item_idx]->m_sect_name.c_str()); - Msg("gl_hud_offset_pos%s = %f,%f,%f",(is_16x9)?"_16x9":"", pos_.x, pos_.y, pos_.z); - Msg("gl_hud_offset_rot%s = %f,%f,%f",(is_16x9)?"_16x9":"", rot_.x, rot_.y, rot_.z); + Msg("gl_hud_offset_pos%s = %.6f,%.6f,%.6f", (is_16x9) ? "_16x9" : "", pos_.x, pos_.y, pos_.z); + Msg("gl_hud_offset_rot%s = %.6f,%.6f,%.6f", (is_16x9) ? "_16x9" : "", rot_.x, rot_.y, rot_.z); Log("-----------"); } } - }else - if(hud_adj_mode==8 || hud_adj_mode==9) - { - if(hud_adj_mode==8 && (values.z) ) - _delta_pos += (values.z>0)?0.001f:-0.001f; - - if(hud_adj_mode==9 && (values.z) ) - _delta_rot += (values.z>0)?0.1f:-0.1f; - }else - { - attachable_hud_item* hi = m_attached_items[hud_adj_item_idx]; - if(!hi) return; - hi->tune(values); + } + else if(hud_adj_mode == 8 || hud_adj_mode == 9) { + if(hud_adj_mode == 8 && (values.z)) { + _delta_pos += (values.z > 0) ? 0.001f : -0.001f; + } + else if(hud_adj_mode == 9 && (values.z)) { + _delta_rot += (values.z > 0) ? 0.01f : -0.01f; + } + } + else { + if(auto hi = m_attached_items[hud_adj_item_idx]) { + hi->tune(values); + } } #endif // #ifndef MASTER_GOLD } void hud_draw_adjust_mode() { - if(!hud_adj_mode) + if(!hud_adj_mode) { return; + } LPCSTR _text = nullptr; - if(pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT) && hud_adj_mode) + if(pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT) && hud_adj_mode) { _text = "press SHIFT+NUM 0-return 1-hud_pos 2-hud_rot 3-itm_pos 4-itm_rot 5-fire_point 6-fire_2_point 7-shell_point 8-pos_step 9-rot_step"; + } - switch (hud_adj_mode) - { - case 1: - _text = "adjusting HUD POSITION"; - break; - case 2: - _text = "adjusting HUD ROTATION"; - break; - case 3: - _text = "adjusting ITEM POSITION"; - break; - case 4: - _text = "adjusting ITEM ROTATION"; - break; - case 5: - _text = "adjusting FIRE POINT"; - break; - case 6: - _text = "adjusting FIRE 2 POINT"; - break; - case 7: - _text = "adjusting SHELL POINT"; - break; - case 8: - _text = "adjusting pos STEP"; - break; - case 9: - _text = "adjusting rot STEP"; - break; - - }; - if(_text) - { - CGameFont* F = UI().Font().pFontDI; - F->SetAligment (CGameFont::alCenter); - F->OutSetI (0.f,-0.8f); - F->SetColor (0xffffffff); - F->OutNext (_text); - F->OutNext ("for item [%d]", hud_adj_item_idx); - F->OutNext ("delta values dP=%f dR=%f", _delta_pos, _delta_rot); - F->OutNext ("[Z]-x axis [X]-y axis [C]-z axis"); - } + switch(hud_adj_mode) { + case 1: _text = "adjusting HUD POSITION"; break; + case 2: _text = "adjusting HUD ROTATION"; break; + case 3: _text = "adjusting ITEM POSITION"; break; + case 4: _text = "adjusting ITEM ROTATION"; break; + case 5: _text = "adjusting FIRE POINT"; break; + case 6: _text = "adjusting FIRE 2 POINT"; break; + case 7: _text = "adjusting SHELL POINT"; break; + case 8: _text = "adjusting pos STEP"; break; + case 9: _text = "adjusting rot STEP"; break; + } + + if(_text) { + CGameFont* F = UI().Font().pFontDI; + F->SetAligment(CGameFont::alCenter); + F->OutSetI(0.f, -0.8f); + F->SetColor(color_xrgb(255, 20, 90)); + F->OutNext(_text); + F->OutNext("for item [%d]", hud_adj_item_idx); + F->OutNext("delta values dP=%.6f dR=%.6f", _delta_pos, _delta_rot); + F->OutNext("[Z]-x axis [X]-y axis [C]-z axis"); + } } void hud_adjust_mode_keyb(int dik) { if(pInput->iGetAsyncKeyState(SDL_SCANCODE_LSHIFT)) { - if(dik== SDL_SCANCODE_KP_0) - hud_adj_mode = 0; - if(dik== SDL_SCANCODE_KP_1) - hud_adj_mode = 1; - if(dik== SDL_SCANCODE_KP_2) - hud_adj_mode = 2; - if(dik== SDL_SCANCODE_KP_3) - hud_adj_mode = 3; - if(dik== SDL_SCANCODE_KP_4) - hud_adj_mode = 4; - if(dik== SDL_SCANCODE_KP_5) - hud_adj_mode = 5; - if(dik== SDL_SCANCODE_KP_6) - hud_adj_mode = 6; - if(dik== SDL_SCANCODE_KP_7) - hud_adj_mode = 7; - if(dik== SDL_SCANCODE_KP_8) - hud_adj_mode = 8; - if(dik== SDL_SCANCODE_KP_9) - hud_adj_mode = 9; - if (dik == SDL_SCANCODE_KP_ENTER) - { + if(dik == SDL_SCANCODE_KP_ENTER) { hud_adj_crosshair = !hud_adj_crosshair; } + else if(dik == SDL_SCANCODE_KP_PERIOD) { + if(auto item = g_player_hud->attached_item(hud_adj_item_idx)) { + item->m_measures.load(item->m_sect_name, item->m_model); + g_player_hud->GetDefaultHudCoords(item->m_sect_name, hud_adj_item_idx, true); + } + } + else { + switch(dik) { + case SDL_SCANCODE_KP_0: hud_adj_mode = 0; break; + case SDL_SCANCODE_KP_1: hud_adj_mode = 1; break; + case SDL_SCANCODE_KP_2: hud_adj_mode = 2; break; + case SDL_SCANCODE_KP_3: hud_adj_mode = 3; break; + case SDL_SCANCODE_KP_4: hud_adj_mode = 4; break; + case SDL_SCANCODE_KP_5: hud_adj_mode = 5; break; + case SDL_SCANCODE_KP_6: hud_adj_mode = 6; break; + case SDL_SCANCODE_KP_7: hud_adj_mode = 7; break; + case SDL_SCANCODE_KP_8: hud_adj_mode = 8; break; + case SDL_SCANCODE_KP_9: hud_adj_mode = 9; break; + } + } } if(pInput->iGetAsyncKeyState(SDL_SCANCODE_LCTRL)) { - if(dik== SDL_SCANCODE_KP_0) + if(dik == SDL_SCANCODE_KP_0) { hud_adj_item_idx = 0; - if(dik== SDL_SCANCODE_KP_1) + } + else if(dik == SDL_SCANCODE_KP_1) { hud_adj_item_idx = 1; + } } }