1
0

affine-pre.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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_translate(mat4s m, vec3s v);
  10. CGLM_INLINE mat4s glms_translate_x(mat4s m, float x);
  11. CGLM_INLINE mat4s glms_translate_y(mat4s m, float y);
  12. CGLM_INLINE mat4s glms_translate_z(mat4s m, float z);
  13. CGLM_INLINE mat4s glms_rotate_x(mat4s m, float angle);
  14. CGLM_INLINE mat4s glms_rotate_y(mat4s m, float angle);
  15. CGLM_INLINE mat4s glms_rotate_z(mat4s m, float angle);
  16. CGLM_INLINE mat4s glms_rotate(mat4s m, float angle, vec3s axis);
  17. CGLM_INLINE mat4s glms_rotate_at(mat4s m, vec3s pivot, float angle, vec3s axis);
  18. CGLM_INLINE mat4s glms_spin(mat4s m, float angle, vec3s axis);
  19. */
  20. #ifndef cglms_affines_pre_h
  21. #define cglms_affines_pre_h
  22. #include "../common.h"
  23. #include "../types-struct.h"
  24. #include "../affine.h"
  25. #include "vec3.h"
  26. #include "vec4.h"
  27. #include "mat4.h"
  28. /*!
  29. * @brief translate existing transform matrix by v vector
  30. * and stores result in same matrix
  31. *
  32. * @param[in] m affine transform
  33. * @param[in] v translate vector [x, y, z]
  34. * @returns affine transform
  35. */
  36. CGLM_INLINE
  37. mat4s
  38. glms_translate(mat4s m, vec3s v) {
  39. glm_translate(m.raw, v.raw);
  40. return m;
  41. }
  42. /*!
  43. * @brief translate existing transform matrix by x factor
  44. *
  45. * @param[in] m affine transform
  46. * @param[in] x x factor
  47. * @returns affine transform
  48. */
  49. CGLM_INLINE
  50. mat4s
  51. glms_translate_x(mat4s m, float x) {
  52. glm_translate_x(m.raw, x);
  53. return m;
  54. }
  55. /*!
  56. * @brief translate existing transform matrix by y factor
  57. *
  58. * @param[in] m affine transform
  59. * @param[in] y y factor
  60. * @returns affine transform
  61. */
  62. CGLM_INLINE
  63. mat4s
  64. glms_translate_y(mat4s m, float y) {
  65. glm_translate_y(m.raw, y);
  66. return m;
  67. }
  68. /*!
  69. * @brief translate existing transform matrix by z factor
  70. *
  71. * @param[in] m affine transform
  72. * @param[in] z z factor
  73. * @returns affine transform
  74. */
  75. CGLM_INLINE
  76. mat4s
  77. glms_translate_z(mat4s m, float z) {
  78. glm_translate_z(m.raw, z);
  79. return m;
  80. }
  81. /*!
  82. * @brief rotate existing transform matrix around X axis by angle
  83. * and store result in dest
  84. *
  85. * @param[in] m affine transform
  86. * @param[in] angle angle (radians)
  87. * @returns rotated matrix
  88. */
  89. CGLM_INLINE
  90. mat4s
  91. glms_rotate_x(mat4s m, float angle) {
  92. mat4s r;
  93. glm_rotate_x(m.raw, angle, r.raw);
  94. return r;
  95. }
  96. /*!
  97. * @brief rotate existing transform matrix around Y axis by angle
  98. * and store result in dest
  99. *
  100. * @param[in] m affine transform
  101. * @param[in] angle angle (radians)
  102. * @returns rotated matrix
  103. */
  104. CGLM_INLINE
  105. mat4s
  106. glms_rotate_y(mat4s m, float angle) {
  107. mat4s r;
  108. glm_rotate_y(m.raw, angle, r.raw);
  109. return r;
  110. }
  111. /*!
  112. * @brief rotate existing transform matrix around Z axis by angle
  113. * and store result in dest
  114. *
  115. * @param[in] m affine transform
  116. * @param[in] angle angle (radians)
  117. * @returns rotated matrix
  118. */
  119. CGLM_INLINE
  120. mat4s
  121. glms_rotate_z(mat4s m, float angle) {
  122. mat4s r;
  123. glm_rotate_z(m.raw, angle, r.raw);
  124. return r;
  125. }
  126. /*!
  127. * @brief rotate existing transform matrix around given axis by angle
  128. *
  129. * @param[in] m affine transform
  130. * @param[in] angle angle (radians)
  131. * @param[in] axis axis
  132. * @returns affine transform
  133. */
  134. CGLM_INLINE
  135. mat4s
  136. glms_rotate(mat4s m, float angle, vec3s axis) {
  137. glm_rotate(m.raw, angle, axis.raw);
  138. return m;
  139. }
  140. /*!
  141. * @brief rotate existing transform
  142. * around given axis by angle at given pivot point (rotation center)
  143. *
  144. * @param[in] m affine transform
  145. * @param[in] pivot rotation center
  146. * @param[in] angle angle (radians)
  147. * @param[in] axis axis
  148. * @returns affine transform
  149. */
  150. CGLM_INLINE
  151. mat4s
  152. glms_rotate_at(mat4s m, vec3s pivot, float angle, vec3s axis) {
  153. glm_rotate_at(m.raw, pivot.raw, angle, axis.raw);
  154. return m;
  155. }
  156. /*!
  157. * @brief rotate existing transform matrix around given axis by angle around self (doesn't affected by position)
  158. *
  159. * @param[in] m affine transform
  160. * @param[in] angle angle (radians)
  161. * @param[in] axis axis
  162. * @returns affine transform
  163. */
  164. CGLM_INLINE
  165. mat4s
  166. glms_spin(mat4s m, float angle, vec3s axis) {
  167. glm_spin(m.raw, angle, axis.raw);
  168. return m;
  169. }
  170. #endif /* cglms_affines_pre_h */