modeling/src/maths/mat4/fromScaling.js

  1. /**
  2. * Creates a matrix from a vector scaling.
  3. * This is equivalent to (but much faster than):
  4. *
  5. * mat4.identity(dest)
  6. * mat4.scale(dest, dest, vec)
  7. *
  8. * @param {mat4} out - receiving matrix
  9. * @param {vec3} vector - X, Y, Z factors by which to scale
  10. * @returns {mat4} out
  11. * @alias module:modeling/maths/mat4.fromScaling
  12. * @example
  13. * let matrix = fromScaling([1, 2, 0.5])
  14. */
  15. const fromScaling = (out, vector) => {
  16. out[0] = vector[0]
  17. out[1] = 0
  18. out[2] = 0
  19. out[3] = 0
  20. out[4] = 0
  21. out[5] = vector[1]
  22. out[6] = 0
  23. out[7] = 0
  24. out[8] = 0
  25. out[9] = 0
  26. out[10] = vector[2]
  27. out[11] = 0
  28. out[12] = 0
  29. out[13] = 0
  30. out[14] = 0
  31. out[15] = 1
  32. return out
  33. }
  34. module.exports = fromScaling