modeling/src/maths/mat4/fromXRotation.js

  1. const { sin, cos } = require('../utils/trigonometry')
  2. /**
  3. * Creates a matrix from the given angle around the X axis.
  4. * This is equivalent to (but much faster than):
  5. *
  6. * mat4.identity(dest)
  7. * mat4.rotateX(dest, dest, radians)
  8. *
  9. * @param {mat4} out - receiving matrix
  10. * @param {Number} radians - angle to rotate the matrix by
  11. * @returns {mat4} out
  12. * @alias module:modeling/maths/mat4.fromXRotation
  13. * @example
  14. * let matrix = fromXRotation(create(), TAU / 4)
  15. */
  16. const fromXRotation = (out, radians) => {
  17. const s = sin(radians)
  18. const c = cos(radians)
  19. // Perform axis-specific matrix multiplication
  20. out[0] = 1
  21. out[1] = 0
  22. out[2] = 0
  23. out[3] = 0
  24. out[4] = 0
  25. out[5] = c
  26. out[6] = s
  27. out[7] = 0
  28. out[8] = 0
  29. out[9] = -s
  30. out[10] = c
  31. out[11] = 0
  32. out[12] = 0
  33. out[13] = 0
  34. out[14] = 0
  35. out[15] = 1
  36. return out
  37. }
  38. module.exports = fromXRotation