9
3

quaternion_transform.inl 629 B

123456789101112131415161718192021222324
  1. namespace glm
  2. {
  3. template<typename T, qualifier Q>
  4. GLM_FUNC_QUALIFIER qua<T, Q> rotate(qua<T, Q> const& q, T const& angle, vec<3, T, Q> const& v)
  5. {
  6. vec<3, T, Q> Tmp = v;
  7. // Axis of rotation must be normalised
  8. T len = glm::length(Tmp);
  9. if(abs(len - static_cast<T>(1)) > static_cast<T>(0.001))
  10. {
  11. T oneOverLen = static_cast<T>(1) / len;
  12. Tmp.x *= oneOverLen;
  13. Tmp.y *= oneOverLen;
  14. Tmp.z *= oneOverLen;
  15. }
  16. T const AngleRad(angle);
  17. T const Sin = sin(AngleRad * static_cast<T>(0.5));
  18. return q * qua<T, Q>(cos(AngleRad * static_cast<T>(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin);
  19. }
  20. }//namespace glm