Generic.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef CORE_GENERIC_H
  2. #define CORE_GENERIC_H
  3. #include "core/Matrix.h"
  4. #ifdef IMPORT_CORE
  5. #define addSet(a, b) \
  6. _Generic((a), \
  7. Vector2 *: addSetV2, \
  8. Vector3 *: addSetV3, \
  9. Vector4 *: addSetV4, \
  10. IntVector2 *: addSetIV2, \
  11. IntVector3 *: addSetIV3, \
  12. IntVector4 *: addSetIV4)(a, b)
  13. #define add(a, b, c) \
  14. _Generic((a), \
  15. Vector2 *: addV2, \
  16. Vector3 *: addV3, \
  17. Vector4 *: addV4, \
  18. IntVector2 *: addIV2, \
  19. IntVector3 *: addIV3, \
  20. IntVector4 *: addIV4)(a, b, c)
  21. #define subSet(a, b) \
  22. _Generic((a), \
  23. Vector2 *: subSetV2, \
  24. Vector3 *: subSetV3, \
  25. Vector4 *: subSetV4, \
  26. IntVector2 *: subSetIV2, \
  27. IntVector3 *: subSetIV3, \
  28. IntVector4 *: subSetIV4)(a, b)
  29. #define sub(a, b, c) \
  30. _Generic((a), \
  31. Vector2 *: subV2, \
  32. Vector3 *: subV3, \
  33. Vector4 *: subV4, \
  34. IntVector2 *: subIV2, \
  35. IntVector3 *: subIV3, \
  36. IntVector4 *: subIV4)(a, b, c)
  37. #define mulSet(a, b) \
  38. _Generic((a), \
  39. Vector2 *: _Generic((b), Vector2 *: mulSetV2, default: mulSetV2F), \
  40. Vector3 *: _Generic((b), Vector3 *: mulSetV3, default: mulSetV3F), \
  41. Vector4 *: _Generic((b), Vector4 *: mulSetV4, default: mulSetV4F), \
  42. IntVector2 *: _Generic((b), \
  43. IntVector2 *: mulSetIV2, \
  44. default: mulSetIV2F), \
  45. IntVector3 *: _Generic((b), \
  46. IntVector3 *: mulSetIV3, \
  47. default: mulSetIV3F), \
  48. IntVector4 *: _Generic((b), \
  49. IntVector4 *: mulSetIV4, \
  50. default: mulSetIV4F))(a, b)
  51. #define mul(a, b, c) \
  52. _Generic((a), \
  53. Vector2 *: _Generic((c), Vector2 *: mulV2, default: mulV2F), \
  54. Vector3 *: _Generic((c), \
  55. Vector3 *: _Generic((b), \
  56. const Quaternion*: mulQV3, \
  57. default: mulV3), \
  58. default: mulV3F), \
  59. Vector4 *: _Generic((c), Vector4 *: mulV4, default: mulV4F), \
  60. IntVector2 *: _Generic((c), IntVector2 *: mulIV2, default: mulIV2F), \
  61. IntVector3 *: _Generic((c), IntVector3 *: mulIV3, default: mulIV3F), \
  62. IntVector4 *: _Generic((c), IntVector4 *: mulIV4, default: mulIV4F))( \
  63. a, b, c)
  64. #define divSet(a, b) \
  65. _Generic((a), \
  66. Vector2 *: _Generic((b), Vector2 *: divSetV2, default: divSetV2F), \
  67. Vector3 *: _Generic((b), Vector3 *: divSetV3, default: divSetV3F), \
  68. Vector4 *: _Generic((b), Vector4 *: divSetV4, default: divSetV4F), \
  69. IntVector2 *: _Generic((b), \
  70. IntVector2 *: divSetIV2, \
  71. default: divSetIV2F), \
  72. IntVector3 *: _Generic((b), \
  73. IntVector3 *: divSetIV3, \
  74. default: divSetIV3F), \
  75. IntVector4 *: _Generic((b), \
  76. IntVector4 *: divSetIV4, \
  77. default: divSetIV4F))(a, b)
  78. #define div(a, b, c) \
  79. _Generic((a), \
  80. Vector2 *: _Generic((c), Vector2 *: divV2, default: divV2F), \
  81. Vector3 *: _Generic((c), Vector3 *: divV3, default: divV3F), \
  82. Vector4 *: _Generic((c), Vector4 *: divV4, default: divV4F), \
  83. IntVector2 *: _Generic((c), IntVector2 *: divIV2, default: divIV2F), \
  84. IntVector3 *: _Generic((c), IntVector3 *: divIV3, default: divIV3F), \
  85. IntVector4 *: _Generic((c), IntVector4 *: divIV4, default: divIV4F))( \
  86. a, b, c)
  87. #define invertSet(a) \
  88. _Generic((a), \
  89. Vector2 *: invertSetV2, \
  90. Vector3 *: invertSetV3, \
  91. Vector4 *: invertSetV4, \
  92. IntVector2 *: invertSetIV2, \
  93. IntVector3 *: invertSetIV3, \
  94. IntVector4 *: invertSetIV4)(a)
  95. #define invert(a, b) \
  96. _Generic((a), \
  97. Vector2 *: invertV2, \
  98. Vector3 *: invertV3, \
  99. Vector4 *: invertV4, \
  100. IntVector2 *: invertIV2, \
  101. IntVector3 *: invertIV3, \
  102. IntVector4 *: invertIV4)(a, b)
  103. #define dot(a, b) \
  104. _Generic((a), \
  105. Vector2 *: dotV2, \
  106. const Vector2*: dotV2, \
  107. Vector3*: dotV3, \
  108. const Vector3*: dotV3, \
  109. Vector4*: dotV4, \
  110. const Vector4*: dotV4)(a, b)
  111. #define squareLength(a) \
  112. _Generic((a), \
  113. Vector2 *: squareLengthV2, \
  114. Vector3 *: squareLengthV3, \
  115. Vector4 *: squareLengthV4)(a)
  116. #define length(a) \
  117. _Generic((a), \
  118. Vector2 *: lengthV2, \
  119. Vector3 *: lengthV3, \
  120. Vector4 *: lengthV4)(a)
  121. #define normalize(a) \
  122. _Generic((a), \
  123. Vector2 *: normalizeV2, \
  124. Vector3 *: normalizeV3, \
  125. Vector4 *: normalizeV4)(a)
  126. #define convert(a, b) \
  127. _Generic((a), \
  128. Vector2 *: convertIV2, \
  129. Vector3 *: convertIV3, \
  130. Vector4 *: convertIV4, \
  131. IntVector2 *: convertV2, \
  132. IntVector3 *: convertV3, \
  133. IntVector4 *: convertV4)(a, b)
  134. // #define toStringV2 coreToStringV2
  135. #endif
  136. #endif