humanoid_math.cpp 827 B

12345678910111213141516171819202122232425
  1. #include "humanoid_math.h"
  2. namespace Render::GL {
  3. QVector3D elbowBendTorso(const QVector3D &shoulder, const QVector3D &hand,
  4. const QVector3D &outwardDir, float alongFrac,
  5. float lateralOffset, float yBias, float outwardSign) {
  6. QVector3D dir = hand - shoulder;
  7. float dist = std::max(dir.length(), 1e-5f);
  8. dir /= dist;
  9. QVector3D lateral = outwardDir - dir * QVector3D::dotProduct(outwardDir, dir);
  10. if (lateral.lengthSquared() < 1e-8f) {
  11. lateral = QVector3D::crossProduct(dir, QVector3D(0, 1, 0));
  12. }
  13. if (QVector3D::dotProduct(lateral, outwardDir) < 0.0f) {
  14. lateral = -lateral;
  15. }
  16. lateral.normalize();
  17. return shoulder + dir * (dist * alongFrac) +
  18. lateral * (lateralOffset * outwardSign) + QVector3D(0, yBias, 0);
  19. }
  20. } // namespace Render::GL