humanoid_math.h 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. #include "gl/render_constants.h"
  3. #include <QVector3D>
  4. #include <cmath>
  5. #include <cstdint>
  6. namespace Render::GL {
  7. inline auto hash_01(uint32_t x) -> float {
  8. x ^= x << HashXorShift::k_xor_shift_amount_13;
  9. x ^= x >> HashXorShift::k_xor_shift_amount_17;
  10. x ^= x << HashXorShift::k_xor_shift_amount_5;
  11. return (x & BitShift::Mask24Bit) / float(BitShift::k_mask_24bit_hex);
  12. }
  13. inline auto rot_y(const QVector3D &v, float angle_rad) -> QVector3D {
  14. const float c = std::cos(angle_rad);
  15. const float s = std::sin(angle_rad);
  16. return {c * v.x() + s * v.z(), v.y(), -s * v.x() + c * v.z()};
  17. }
  18. inline auto right_of(const QVector3D &fwd) -> QVector3D {
  19. const QVector3D UP(0.0F, 1.0F, 0.0F);
  20. return QVector3D::crossProduct(UP, fwd).normalized();
  21. }
  22. auto elbow_bend_torso(const QVector3D &shoulder, const QVector3D &hand,
  23. const QVector3D &outward_dir, float along_frac,
  24. float lateral_offset, float y_bias,
  25. float outward_sign) -> QVector3D;
  26. } // namespace Render::GL