spear_renderer.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "spear_renderer.h"
  2. #include "../../entity/renderer_constants.h"
  3. #include "../../geom/transforms.h"
  4. #include "../../gl/primitives.h"
  5. #include "../../humanoid/rig.h"
  6. #include "../../humanoid/spear_pose_utils.h"
  7. #include "../../submitter.h"
  8. #include <QMatrix4x4>
  9. #include <QVector3D>
  10. #include <cmath>
  11. namespace Render::GL {
  12. using Render::Geom::cone_from_to;
  13. using Render::Geom::cylinder_between;
  14. SpearRenderer::SpearRenderer(SpearRenderConfig config)
  15. : m_config(std::move(config)) {}
  16. void SpearRenderer::render(const DrawContext &ctx, const BodyFrames &frames,
  17. const HumanoidPalette &palette,
  18. const HumanoidAnimationContext &anim,
  19. ISubmitter &submitter) {
  20. QVector3D const grip_pos = frames.hand_r.origin;
  21. QVector3D const spear_dir = compute_spear_direction(anim.inputs);
  22. QVector3D const shaft_base = grip_pos - spear_dir * 0.28F;
  23. QVector3D shaft_mid = grip_pos + spear_dir * (m_config.spear_length * 0.5F);
  24. QVector3D const shaft_tip = grip_pos + spear_dir * m_config.spear_length;
  25. shaft_mid.setY(shaft_mid.y() + 0.02F);
  26. submitter.mesh(
  27. get_unit_cylinder(),
  28. cylinder_between(ctx.model, shaft_base, shaft_mid, m_config.shaft_radius),
  29. m_config.shaft_color, nullptr, 1.0F, m_config.material_id);
  30. submitter.mesh(get_unit_cylinder(),
  31. cylinder_between(ctx.model, shaft_mid, shaft_tip,
  32. m_config.shaft_radius * 0.95F),
  33. m_config.shaft_color * 0.98F, nullptr, 1.0F,
  34. m_config.material_id);
  35. QVector3D const spearhead_base = shaft_tip;
  36. QVector3D const spearhead_tip =
  37. shaft_tip + spear_dir * m_config.spearhead_length;
  38. submitter.mesh(get_unit_cone(),
  39. cone_from_to(ctx.model, spearhead_base, spearhead_tip,
  40. m_config.shaft_radius * 1.8F),
  41. m_config.spearhead_color, nullptr, 1.0F, m_config.material_id);
  42. QVector3D const grip_end = grip_pos + spear_dir * 0.10F;
  43. submitter.mesh(get_unit_cylinder(),
  44. cylinder_between(ctx.model, grip_pos, grip_end,
  45. m_config.shaft_radius * 1.5F),
  46. palette.leather * 0.92F, nullptr, 1.0F, m_config.material_id);
  47. }
  48. } // namespace Render::GL