1
0

mat3x4.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_MAT3X4_ZERO_INIT
  10. GLMS_MAT3X4_ZERO
  11. Functions:
  12. CGLM_INLINE mat3x4s glms_mat3x4_zero(void);
  13. CGLM_INLINE mat3x4s glms_mat3x4_make(const float * __restrict src);
  14. CGLM_INLINE mat4s glms_mat3x4_mul(mat3x4s m1, mat4x3s m2);
  15. CGLM_INLINE vec4s glms_mat3x4_mulv(mat3x4s m, vec3s v);
  16. CGLM_INLINE mat4x3s glms_mat3x4_transpose(mat3x4s m);
  17. CGLM_INLINE mat3x4s glms_mat3x4_scale(mat3x4s m, float s);
  18. */
  19. #ifndef cglms_mat3x4_h
  20. #define cglms_mat3x4_h
  21. #include "../common.h"
  22. #include "../types-struct.h"
  23. #include "../mat3x4.h"
  24. /* api definition */
  25. #define glms_mat3x4_(NAME) CGLM_STRUCTAPI(mat3x4, NAME)
  26. #define GLMS_MAT3X4_ZERO_INIT {GLM_MAT3X4_ZERO_INIT}
  27. /* for C only */
  28. #define GLMS_MAT3X4_ZERO ((mat3x4s)GLMS_MAT3X4_ZERO_INIT)
  29. /*!
  30. * @brief make given matrix zero.
  31. *
  32. * @param[in, out] mat matrix
  33. */
  34. CGLM_INLINE
  35. mat3x4s
  36. glms_mat3x4_(zero)(void) {
  37. mat3x4s r;
  38. glm_mat3x4_zero(r.raw);
  39. return r;
  40. }
  41. /*!
  42. * @brief Create mat3x4 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. mat3x4s
  49. glms_mat3x4_(make)(const float * __restrict src) {
  50. mat3x4s r;
  51. glm_mat3x4_make(src, r.raw);
  52. return r;
  53. }
  54. /*!
  55. * @brief multiply m1 and m2 to dest
  56. *
  57. * @code
  58. * r = glms_mat3x4_mul(mat3x4s, mat4x3s);
  59. * @endcode
  60. *
  61. * @param[in] m1 left matrix (mat3x4s)
  62. * @param[in] m2 right matrix (mat4x3s)
  63. * @returns destination matrix (mat4s)
  64. */
  65. CGLM_INLINE
  66. mat4s
  67. glms_mat3x4_(mul)(mat3x4s m1, mat4x3s m2) {
  68. mat4s r;
  69. glm_mat3x4_mul(m1.raw, m2.raw, r.raw);
  70. return r;
  71. }
  72. /*!
  73. * @brief multiply matrix with column vector and store in dest column vector
  74. *
  75. * @param[in] m matrix (left)
  76. * @param[in] v vector (right, column vector)
  77. * @returns destination vector (vec4s)
  78. */
  79. CGLM_INLINE
  80. vec4s
  81. glms_mat3x4_(mulv)(mat3x4s m, vec3s v) {
  82. vec4s r;
  83. glm_mat3x4_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. mat4x3s
  94. glms_mat3x4_(transpose)(mat3x4s m) {
  95. mat4x3s r;
  96. glm_mat3x4_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. mat3x4s
  109. glms_mat3x4_(scale)(mat3x4s m, float s) {
  110. glm_mat3x4_scale(m.raw, s);
  111. return m;
  112. }
  113. #endif /* cglms_mat3x4_h */