headwrap.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "headwrap.h"
  2. #include "../../geom/transforms.h"
  3. #include "../../gl/primitives.h"
  4. #include "../../humanoid/humanoid_math.h"
  5. #include "../../humanoid/rig.h"
  6. #include "../../humanoid/style_palette.h"
  7. #include "../../submitter.h"
  8. #include <QMatrix4x4>
  9. #include <QVector3D>
  10. namespace Render::GL {
  11. using Render::Geom::cylinder_between;
  12. using Render::GL::Humanoid::saturate_color;
  13. void HeadwrapRenderer::render(const DrawContext &ctx, const BodyFrames &frames,
  14. const HumanoidPalette &palette,
  15. const HumanoidAnimationContext &anim,
  16. ISubmitter &submitter) {
  17. (void)anim;
  18. QVector3D const cloth_color =
  19. saturate_color(palette.cloth * QVector3D(0.9F, 1.05F, 1.05F));
  20. const AttachmentFrame &head = frames.head;
  21. float const head_r = head.radius;
  22. if (head_r <= 0.0F) {
  23. return;
  24. }
  25. auto headPoint = [&](const QVector3D &normalized) -> QVector3D {
  26. return HumanoidRendererBase::frame_local_position(head, normalized);
  27. };
  28. QVector3D const band_top = headPoint(QVector3D(0.0F, 0.70F, 0.0F));
  29. QVector3D const band_bot = headPoint(QVector3D(0.0F, 0.30F, 0.0F));
  30. submitter.mesh(
  31. get_unit_cylinder(),
  32. cylinder_between(ctx.model, band_bot, band_top, head_r * 1.08F),
  33. cloth_color, nullptr, 1.0F);
  34. QVector3D const knot_center = headPoint(QVector3D(0.10F, 0.60F, 0.72F));
  35. QMatrix4x4 knot_m = ctx.model;
  36. knot_m.translate(knot_center);
  37. knot_m.scale(head_r * 0.32F);
  38. submitter.mesh(get_unit_sphere(), knot_m, cloth_color * 1.05F, nullptr, 1.0F);
  39. QVector3D const tail_top = knot_center + head.right * (-0.08F) +
  40. head.up * (-0.05F) + head.forward * (-0.06F);
  41. QVector3D const tail_bot = tail_top + head.right * 0.02F +
  42. head.up * (-0.28F) + head.forward * (-0.08F);
  43. submitter.mesh(
  44. get_unit_cylinder(),
  45. cylinder_between(ctx.model, tail_top, tail_bot, head_r * 0.28F),
  46. cloth_color * QVector3D(0.92F, 0.98F, 1.05F), nullptr, 1.0F);
  47. }
  48. } // namespace Render::GL