affine-mat.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c), Recep Aslantas.
  3. *
  4. * MIT License (MIT), http://opensource.org/licenses/MIT
  5. * Full license can be found in the LICENSE file
  6. */
  7. /*
  8. Functions:
  9. CGLM_INLINE mat4s glms_mul(mat4 m1, mat4 m2);
  10. CGLM_INLINE mat4s glms_mul_rot(mat4 m1, mat4 m2);
  11. CGLM_INLINE mat4s glms_inv_tr();
  12. */
  13. #ifndef cglms_affine_mat_h
  14. #define cglms_affine_mat_h
  15. #include "../common.h"
  16. #include "../types-struct.h"
  17. #include "../affine-mat.h"
  18. #include "vec3.h"
  19. #include "vec4.h"
  20. #include "mat4.h"
  21. /*!
  22. * @brief this is similar to glms_mat4_mul but specialized to affine transform
  23. *
  24. * Matrix format should be:
  25. * R R R X
  26. * R R R Y
  27. * R R R Z
  28. * 0 0 0 W
  29. *
  30. * this reduces some multiplications. It should be faster than mat4_mul.
  31. * if you are not sure about matrix format then DON'T use this! use mat4_mul
  32. *
  33. * @param[in] m1 affine matrix 1
  34. * @param[in] m2 affine matrix 2
  35. * @returns destination matrix
  36. */
  37. CGLM_INLINE
  38. mat4s
  39. glms_mul(mat4s m1, mat4s m2){
  40. mat4s r;
  41. glm_mul(m1.raw, m2.raw, r.raw);
  42. return r;
  43. }
  44. /*!
  45. * @brief this is similar to glm_mat4_mul but specialized to affine transform
  46. *
  47. * Right Matrix format should be:
  48. * R R R 0
  49. * R R R 0
  50. * R R R 0
  51. * 0 0 0 1
  52. *
  53. * this reduces some multiplications. It should be faster than mat4_mul.
  54. * if you are not sure about matrix format then DON'T use this! use mat4_mul
  55. *
  56. * @param[in] m1 affine matrix 1
  57. * @param[in] m2 affine matrix 2
  58. * @returns destination matrix
  59. */
  60. CGLM_INLINE
  61. mat4s
  62. glms_mul_rot(mat4s m1, mat4s m2){
  63. mat4s r;
  64. glm_mul_rot(m1.raw, m2.raw, r.raw);
  65. return r;
  66. }
  67. /*!
  68. * @brief inverse orthonormal rotation + translation matrix (ridig-body)
  69. *
  70. * @code
  71. * X = | R T | X' = | R' -R'T |
  72. * | 0 1 | | 0 1 |
  73. * @endcode
  74. *
  75. * @param[in] m matrix
  76. * @returns destination matrix
  77. */
  78. CGLM_INLINE
  79. mat4s
  80. glms_inv_tr(mat4s m){
  81. glm_inv_tr(m.raw);
  82. return m;
  83. }
  84. #endif /* cglms_affine_mat_h */