1
0

mat2x3.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. Macros:
  9. GLMS_MAT2X3_ZERO_INIT
  10. GLMS_MAT2X3_ZERO
  11. Functions:
  12. CGLM_INLINE mat2x3s glms_mat2x3_zero(void);
  13. CGLM_INLINE mat2x3s glms_mat2x3_make(const float * __restrict src);
  14. CGLM_INLINE mat2s glms_mat2x3_mul(mat2x3s m1, mat3x2s m2);
  15. CGLM_INLINE vec3s glms_mat2x3_mulv(mat2x3s m, vec2s v);
  16. CGLM_INLINE mat3x2s glms_mat2x3_transpose(mat2x3s m);
  17. CGLM_INLINE mat2x3s glms_mat2x3_scale(mat2x3s m, float s);
  18. */
  19. #ifndef cglms_mat2x3_h
  20. #define cglms_mat2x3_h
  21. #include "../common.h"
  22. #include "../types-struct.h"
  23. #include "../mat2x3.h"
  24. /* api definition */
  25. #define glms_mat2x3_(NAME) CGLM_STRUCTAPI(mat2x3, NAME)
  26. #define GLMS_MAT2X3_ZERO_INIT {GLM_MAT2X3_ZERO_INIT}
  27. /* for C only */
  28. #define GLMS_MAT2X3_ZERO ((mat2x3s)GLMS_MAT2X3_ZERO_INIT)
  29. /*!
  30. * @brief make given matrix zero.
  31. *
  32. * @param[in, out] mat matrix
  33. */
  34. CGLM_INLINE
  35. mat2x3s
  36. glms_mat2x3_(zero)(void) {
  37. mat2x3s r;
  38. glm_mat2x3_zero(r.raw);
  39. return r;
  40. }
  41. /*!
  42. * @brief Create mat2x3 matrix from pointer
  43. *
  44. * @param[in] src pointer to an array of floats
  45. * @return constructed matrix from raw pointer
  46. */
  47. CGLM_INLINE
  48. mat2x3s
  49. glms_mat2x3_(make)(const float * __restrict src) {
  50. mat2x3s r;
  51. glm_mat2x3_make(src, r.raw);
  52. return r;
  53. }
  54. /*!
  55. * @brief multiply m1 and m2 to dest
  56. *
  57. * @code
  58. * r = glms_mat2x3_mul(mat2x3s, mat3x2s);
  59. * @endcode
  60. *
  61. * @param[in] m1 left matrix (mat2x3s)
  62. * @param[in] m2 right matrix (mat3x2s)
  63. * @returns destination matrix (mat2s)
  64. */
  65. CGLM_INLINE
  66. mat3s
  67. glms_mat2x3_(mul)(mat2x3s m1, mat3x2s m2) {
  68. mat3s r;
  69. glm_mat2x3_mul(m1.raw, m2.raw, r.raw);
  70. return r;
  71. }
  72. /*!
  73. * @brief multiply matrix with column vector and store in dest vector
  74. *
  75. * @param[in] m matrix (left)
  76. * @param[in] v vector (right, column vector)
  77. * @returns destination vector (vec3s)
  78. */
  79. CGLM_INLINE
  80. vec3s
  81. glms_mat2x3_(mulv)(mat2x3s m, vec2s v) {
  82. vec3s r;
  83. glm_mat2x3_mulv(m.raw, v.raw, r.raw);
  84. return r;
  85. }
  86. /*!
  87. * @brief transpose matrix and store in dest
  88. *
  89. * @param[in] m matrix
  90. * @param[out] dest result
  91. */
  92. CGLM_INLINE
  93. mat3x2s
  94. glms_mat2x3_(transpose)(mat2x3s m) {
  95. mat3x2s r;
  96. glm_mat2x3_transpose(m.raw, r.raw);
  97. return r;
  98. }
  99. /*!
  100. * @brief scale (multiply with scalar) matrix
  101. *
  102. * multiply matrix with scalar
  103. *
  104. * @param[in, out] m matrix
  105. * @param[in] s scalar
  106. */
  107. CGLM_INLINE
  108. mat2x3s
  109. glms_mat2x3_(scale)(mat2x3s m, float s) {
  110. glm_mat2x3_scale(m.raw, s);
  111. return m;
  112. }
  113. #endif /* cglms_mat2x3_h */