1
- #include " stdafx.h"
1
+ #include " stdafx.h"
2
2
#include " player_hud.h"
3
3
#include " HudItem.h"
4
4
#include " ui_base.h"
@@ -14,6 +14,17 @@ player_hud* g_player_hud = nullptr;
14
14
Fvector _ancor_pos;
15
15
Fvector _wpn_root_pos;
16
16
17
+ // clang-format off
18
+ static const float PITCH_OFFSET_R = 0 .017f ; // Насколько сильно ствол смещается вбок (влево) при вертикальных поворотах камеры --#SM+#--
19
+ static const float PITCH_OFFSET_N = 0 .012f ; // Насколько сильно ствол поднимается\опускается при вертикальных поворотах камеры --#SM+#--
20
+ static const float PITCH_OFFSET_D = 0 .02f ; // Насколько сильно ствол приближается\отдаляется при вертикальных поворотах камеры --#SM+#--
21
+ static const float PITCH_LOW_LIMIT = -PI; // Минимальное значение pitch при использовании совместно с PITCH_OFFSET_N --#SM+#--
22
+ static const float ORIGIN_OFFSET = -0 .05f ; // Фактор влияния инерции на положение ствола (чем меньше, тем маштабней инерция) --#SM+#--
23
+ static const float ORIGIN_OFFSET_AIM = -0 .03f ; // (Для прицеливания) --#SM+#--
24
+ static const float TENDTO_SPEED = 5 .f; // Скорость нормализации положения ствола --#SM+#--
25
+ static const float TENDTO_SPEED_AIM = 8 .f; // (Для прицеливания) --#SM+#--
26
+ // clang-format on
27
+
17
28
float CalcMotionSpeed (const shared_str& anim_name)
18
29
{
19
30
if (!IsGameTypeSingle () && (anim_name == " anm_show" || anim_name == " anm_hide" ))
@@ -281,6 +292,19 @@ void hud_item_measures::load(const shared_str& sect_name, IKinematics* K)
281
292
sect_name.c_str ());
282
293
283
294
m_prop_flags.set (e_16x9_mode_now, is_16x9);
295
+
296
+ // Загрузка параметров инерции --#SM+# Begin--
297
+ m_inertion_params.m_pitch_offset_r = READ_IF_EXISTS (pSettings, r_float, sect_name, " pitch_offset_right" , PITCH_OFFSET_R);
298
+ m_inertion_params.m_pitch_offset_n = READ_IF_EXISTS (pSettings, r_float, sect_name, " pitch_offset_up" , PITCH_OFFSET_N);
299
+ m_inertion_params.m_pitch_offset_d = READ_IF_EXISTS (pSettings, r_float, sect_name, " pitch_offset_forward" , PITCH_OFFSET_D);
300
+ m_inertion_params.m_pitch_low_limit = READ_IF_EXISTS (pSettings, r_float, sect_name, " pitch_offset_up_low_limit" , PITCH_LOW_LIMIT);
301
+
302
+ m_inertion_params.m_origin_offset = READ_IF_EXISTS (pSettings, r_float, sect_name, " inertion_origin_offset" , ORIGIN_OFFSET);
303
+ m_inertion_params.m_origin_offset_aim = READ_IF_EXISTS (pSettings, r_float, sect_name, " inertion_origin_aim_offset" , ORIGIN_OFFSET_AIM);
304
+ m_inertion_params.m_tendto_speed = READ_IF_EXISTS (pSettings, r_float, sect_name, " inertion_tendto_speed" , TENDTO_SPEED);
305
+ m_inertion_params.m_tendto_speed_aim = READ_IF_EXISTS (pSettings, r_float, sect_name, " inertion_tendto_aim_speed" , TENDTO_SPEED_AIM);
306
+ // --#SM+# End--
307
+
284
308
}
285
309
286
310
attachable_hud_item::~attachable_hud_item ()
@@ -598,22 +622,43 @@ void player_hud::update_additional(Fmatrix& trans)
598
622
m_attached_items[1 ]->update_hud_additional (trans);
599
623
}
600
624
601
- static const float PITCH_OFFSET_R = 0 .017f ;
602
- static const float PITCH_OFFSET_N = 0 .012f ;
603
- static const float PITCH_OFFSET_D = 0 .02f ;
604
- static const float ORIGIN_OFFSET = -0 .05f ;
605
- static const float TENDTO_SPEED = 5 .f;
606
-
607
625
void player_hud::update_inertion (Fmatrix& trans)
608
626
{
609
627
if (inertion_allowed ())
610
628
{
629
+ attachable_hud_item* pMainHud = m_attached_items[0 ];
630
+
611
631
Fmatrix xform;
612
632
Fvector& origin = trans.c ;
613
633
xform = trans;
614
634
615
635
static Fvector st_last_dir = {0 , 0 , 0 };
616
636
637
+ // load params
638
+ hud_item_measures::inertion_params inertion_data;
639
+ if (pMainHud != NULL )
640
+ { // Загружаем параметры инерции из основного худа
641
+ inertion_data.m_pitch_offset_r = pMainHud->m_measures .m_inertion_params .m_pitch_offset_r ;
642
+ inertion_data.m_pitch_offset_n = pMainHud->m_measures .m_inertion_params .m_pitch_offset_n ;
643
+ inertion_data.m_pitch_offset_d = pMainHud->m_measures .m_inertion_params .m_pitch_offset_d ;
644
+ inertion_data.m_pitch_low_limit = pMainHud->m_measures .m_inertion_params .m_pitch_low_limit ;
645
+ inertion_data.m_origin_offset = pMainHud->m_measures .m_inertion_params .m_origin_offset ;
646
+ inertion_data.m_origin_offset_aim = pMainHud->m_measures .m_inertion_params .m_origin_offset_aim ;
647
+ inertion_data.m_tendto_speed = pMainHud->m_measures .m_inertion_params .m_tendto_speed ;
648
+ inertion_data.m_tendto_speed_aim = pMainHud->m_measures .m_inertion_params .m_tendto_speed_aim ;
649
+ }
650
+ else
651
+ { // Загружаем дефолтные параметры инерции
652
+ inertion_data.m_pitch_offset_r = PITCH_OFFSET_R;
653
+ inertion_data.m_pitch_offset_n = PITCH_OFFSET_N;
654
+ inertion_data.m_pitch_offset_d = PITCH_OFFSET_D;
655
+ inertion_data.m_pitch_low_limit = PITCH_LOW_LIMIT;
656
+ inertion_data.m_origin_offset = ORIGIN_OFFSET;
657
+ inertion_data.m_origin_offset_aim = ORIGIN_OFFSET_AIM;
658
+ inertion_data.m_tendto_speed = TENDTO_SPEED;
659
+ inertion_data.m_tendto_speed_aim = TENDTO_SPEED_AIM;
660
+ }
661
+
617
662
// calc difference
618
663
Fvector diff_dir;
619
664
diff_dir.sub (xform.k , st_last_dir);
@@ -631,14 +676,46 @@ void player_hud::update_inertion(Fmatrix& trans)
631
676
}
632
677
633
678
// tend to forward
634
- st_last_dir.mad (diff_dir, TENDTO_SPEED * Device.fTimeDelta );
635
- origin.mad (diff_dir, ORIGIN_OFFSET);
679
+ float _tendto_speed, _origin_offset;
680
+ if (pMainHud != NULL && pMainHud->m_parent_hud_item ->GetCurrentHudOffsetIdx () > 0 )
681
+ { // Худ в режиме "Прицеливание"
682
+ float factor = pMainHud->m_parent_hud_item ->GetInertionFactor ();
683
+ _tendto_speed = inertion_data.m_tendto_speed_aim - (inertion_data.m_tendto_speed_aim - inertion_data.m_tendto_speed ) * factor;
684
+ _origin_offset =
685
+ inertion_data.m_origin_offset_aim - (inertion_data.m_origin_offset_aim - inertion_data.m_origin_offset ) * factor;
686
+ }
687
+ else
688
+ { // Худ в режиме "От бедра"
689
+ _tendto_speed = inertion_data.m_tendto_speed ;
690
+ _origin_offset = inertion_data.m_origin_offset ;
691
+ }
692
+
693
+ // Фактор силы инерции
694
+ if (pMainHud != NULL )
695
+ {
696
+ float power_factor = pMainHud->m_parent_hud_item ->GetInertionPowerFactor ();
697
+ _tendto_speed *= power_factor;
698
+ _origin_offset *= power_factor;
699
+ }
700
+
701
+ st_last_dir.mad (diff_dir, _tendto_speed * Device.fTimeDelta );
702
+ origin.mad (diff_dir, _origin_offset);
636
703
637
704
// pitch compensation
638
705
float pitch = angle_normalize_signed (xform.k .getP ());
639
- origin.mad (xform.k , -pitch * PITCH_OFFSET_D);
640
- origin.mad (xform.i , -pitch * PITCH_OFFSET_R);
641
- origin.mad (xform.j , -pitch * PITCH_OFFSET_N);
706
+
707
+ if (pMainHud != NULL )
708
+ pitch *= pMainHud->m_parent_hud_item ->GetInertionFactor ();
709
+
710
+ // Отдаление\приближение
711
+ origin.mad (xform.k , -pitch * inertion_data.m_pitch_offset_d );
712
+
713
+ // Сдвиг в противоположную часть экрана
714
+ origin.mad (xform.i , -pitch * inertion_data.m_pitch_offset_r );
715
+
716
+ // Подьём\опускание
717
+ clamp (pitch, inertion_data.m_pitch_low_limit , PI);
718
+ origin.mad (xform.j , -pitch * inertion_data.m_pitch_offset_n );
642
719
}
643
720
}
644
721
0 commit comments