mounted_pose_controller.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #pragma once
  2. #include "../horse/rig.h"
  3. #include "rig.h"
  4. #include <QVector3D>
  5. #include <string_view>
  6. namespace Render::GL {
  7. class HumanoidPoseController;
  8. struct MountedAttachmentFrame;
  9. enum class SpearGrip { OVERHAND, COUCHED, TWO_HANDED };
  10. class MountedPoseController {
  11. public:
  12. MountedPoseController(HumanoidPose &pose,
  13. const HumanoidAnimationContext &anim_ctx);
  14. void mount_on_horse(const MountedAttachmentFrame &mount);
  15. void dismount();
  16. void riding_idle(const MountedAttachmentFrame &mount);
  17. void riding_leaning(const MountedAttachmentFrame &mount, float forward_lean,
  18. float side_lean);
  19. void riding_charging(const MountedAttachmentFrame &mount, float intensity);
  20. void riding_reining(const MountedAttachmentFrame &mount, float left_tension,
  21. float right_tension);
  22. void riding_melee_strike(const MountedAttachmentFrame &mount,
  23. float attack_phase);
  24. void riding_spear_thrust(const MountedAttachmentFrame &mount,
  25. float attack_phase);
  26. void riding_bow_shot(const MountedAttachmentFrame &mount, float draw_phase);
  27. void riding_shield_defense(const MountedAttachmentFrame &mount, bool raised);
  28. void hold_reins(const MountedAttachmentFrame &mount, float left_slack,
  29. float right_slack, float left_tension = 0.0F,
  30. float right_tension = 0.0F);
  31. void hold_spear_mounted(const MountedAttachmentFrame &mount,
  32. SpearGrip grip_style);
  33. void hold_bow_mounted(const MountedAttachmentFrame &mount);
  34. enum class MountedSeatPose { Neutral, Forward, Defensive };
  35. enum class MountedWeaponPose {
  36. None,
  37. SwordIdle,
  38. SwordStrike,
  39. SpearGuard,
  40. SpearThrust,
  41. BowDraw
  42. };
  43. enum class MountedShieldPose { None, Stowed, Guard, Raised };
  44. struct MountedRiderPoseRequest {
  45. HorseDimensions dims{};
  46. MountedSeatPose seat_pose{MountedSeatPose::Neutral};
  47. MountedWeaponPose weapon_pose{MountedWeaponPose::None};
  48. MountedShieldPose shield_pose{MountedShieldPose::None};
  49. float action_phase{0.0F};
  50. float forward_bias{0.0F};
  51. float side_bias{0.0F};
  52. float torso_compression{0.0F};
  53. float torso_twist{0.0F};
  54. float shoulder_dip{0.0F};
  55. float clearance_forward{1.0F};
  56. float clearance_up{1.0F};
  57. float rein_slack_left{0.20F};
  58. float rein_slack_right{0.20F};
  59. float rein_tension_left{0.25F};
  60. float rein_tension_right{0.25F};
  61. bool left_hand_on_reins{true};
  62. bool right_hand_on_reins{true};
  63. };
  64. void apply_pose(const MountedAttachmentFrame &mount,
  65. const MountedRiderPoseRequest &request);
  66. void finalize_head_sync(const MountedAttachmentFrame &mount,
  67. std::string_view debug_label = "final_head_sync");
  68. private:
  69. HumanoidPose &m_pose;
  70. const HumanoidAnimationContext &m_anim_ctx;
  71. void attach_feet_to_stirrups(const MountedAttachmentFrame &mount);
  72. void position_pelvis_on_saddle(const MountedAttachmentFrame &mount);
  73. void translate_upper_body(const QVector3D &delta);
  74. void calculate_riding_knees(const MountedAttachmentFrame &mount);
  75. auto solve_elbow_ik(bool is_left, const QVector3D &shoulder,
  76. const QVector3D &hand, const QVector3D &outward_dir,
  77. float along_frac, float lateral_offset, float y_bias,
  78. float outward_sign) const -> QVector3D;
  79. auto solve_knee_ik(bool is_left, const QVector3D &hip, const QVector3D &foot,
  80. float height_scale) const -> QVector3D;
  81. auto get_shoulder(bool is_left) const -> const QVector3D &;
  82. auto get_hand(bool is_left) -> QVector3D &;
  83. auto get_hand(bool is_left) const -> const QVector3D &;
  84. auto get_elbow(bool is_left) -> QVector3D &;
  85. auto compute_right_axis() const -> QVector3D;
  86. auto compute_outward_dir(bool is_left) const -> QVector3D;
  87. void apply_lean(const MountedAttachmentFrame &mount, float forward_lean,
  88. float side_lean);
  89. void apply_shield_defense(const MountedAttachmentFrame &mount, bool raised);
  90. void apply_shield_stowed(const MountedAttachmentFrame &mount,
  91. const HorseDimensions &dims);
  92. void apply_sword_idle_pose(const MountedAttachmentFrame &mount,
  93. const HorseDimensions &dims);
  94. void apply_sword_strike(const MountedAttachmentFrame &mount,
  95. float attack_phase, bool keep_left_hand);
  96. void apply_spear_thrust(const MountedAttachmentFrame &mount,
  97. float attack_phase);
  98. void apply_spear_guard(const MountedAttachmentFrame &mount, SpearGrip grip);
  99. void apply_bow_draw(const MountedAttachmentFrame &mount, float draw_phase);
  100. void apply_saddle_clearance(const MountedAttachmentFrame &mount,
  101. const HorseDimensions &dims, float forward_bias,
  102. float up_bias);
  103. void stabilize_upper_body(const MountedAttachmentFrame &mount,
  104. const HorseDimensions &dims);
  105. void apply_torso_sculpt(const MountedAttachmentFrame &mount,
  106. float compression, float twist, float shoulder_dip);
  107. void update_head_hierarchy(const MountedAttachmentFrame &mount,
  108. float extra_forward_tilt, float extra_side_tilt,
  109. std::string_view debug_label = "head_sync");
  110. void hold_reins_impl(const MountedAttachmentFrame &mount, float left_slack,
  111. float right_slack, float left_tension,
  112. float right_tension, bool apply_left, bool apply_right);
  113. void apply_fixed_head_frame(const MountedAttachmentFrame &mount,
  114. std::string_view debug_label);
  115. };
  116. } // namespace Render::GL