util.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. .. default-domain:: C
  2. utils / helpers
  3. ================================================================================
  4. Header: cglm/util.h
  5. Table of contents (click to go):
  6. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. Functions:
  8. 1. :c:func:`glm_sign`
  9. #. :c:func:`glm_signf`
  10. #. :c:func:`glm_rad`
  11. #. :c:func:`glm_deg`
  12. #. :c:func:`glm_make_rad`
  13. #. :c:func:`glm_make_deg`
  14. #. :c:func:`glm_pow2`
  15. #. :c:func:`glm_min`
  16. #. :c:func:`glm_max`
  17. #. :c:func:`glm_clamp`
  18. #. :c:func:`glm_lerp`
  19. #. :c:func:`glm_swapf`
  20. Functions documentation
  21. ~~~~~~~~~~~~~~~~~~~~~~~
  22. .. c:function:: int glm_sign(int val)
  23. | returns sign of 32 bit integer as +1, -1, 0
  24. | **Important**: It returns 0 for zero input
  25. Parameters:
  26. | *[in]* **val** an integer
  27. Returns:
  28. sign of given number
  29. .. c:function:: float glm_signf(float val)
  30. | returns sign of 32 bit integer as +1.0, -1.0, 0.0
  31. | **Important**: It returns 0.0f for zero input
  32. Parameters:
  33. | *[in]* **val** a float
  34. Returns:
  35. sign of given number
  36. .. c:function:: float glm_rad(float deg)
  37. | convert degree to radians
  38. Parameters:
  39. | *[in]* **deg** angle in degrees
  40. .. c:function:: float glm_deg(float rad)
  41. | convert radians to degree
  42. Parameters:
  43. | *[in]* **rad** angle in radians
  44. .. c:function:: void glm_make_rad(float *degm)
  45. | convert exsisting degree to radians. this will override degrees value
  46. Parameters:
  47. | *[in, out]* **deg** pointer to angle in degrees
  48. .. c:function:: void glm_make_deg(float *rad)
  49. | convert exsisting radians to degree. this will override radians value
  50. Parameters:
  51. | *[in, out]* **rad** pointer to angle in radians
  52. .. c:function:: float glm_pow2(float x)
  53. | multiplies given parameter with itself = x * x or powf(x, 2)
  54. Parameters:
  55. | *[in]* **x** value
  56. Returns:
  57. square of a given number
  58. .. c:function:: float glm_min(float a, float b)
  59. | returns minimum of given two values
  60. Parameters:
  61. | *[in]* **a** number 1
  62. | *[in]* **b** number 2
  63. Returns:
  64. minimum value
  65. .. c:function:: float glm_max(float a, float b)
  66. | returns maximum of given two values
  67. Parameters:
  68. | *[in]* **a** number 1
  69. | *[in]* **b** number 2
  70. Returns:
  71. maximum value
  72. .. c:function:: void glm_clamp(float val, float minVal, float maxVal)
  73. constrain a value to lie between two further values
  74. Parameters:
  75. | *[in]* **val** input value
  76. | *[in]* **minVal** minimum value
  77. | *[in]* **maxVal** maximum value
  78. Returns:
  79. clamped value
  80. .. c:function:: float glm_lerp(float from, float to, float t)
  81. linear interpolation between two number
  82. | formula: from + s * (to - from)
  83. Parameters:
  84. | *[in]* **from** from value
  85. | *[in]* **to** to value
  86. | *[in]* **t** interpolant (amount) clamped between 0 and 1
  87. Returns:
  88. interpolated value
  89. .. c:function:: bool glm_eq(float a, float b)
  90. check if two float equal with using EPSILON
  91. Parameters:
  92. | *[in]* **a** a
  93. | *[in]* **b** b
  94. Returns:
  95. true if a and b are equal
  96. .. c:function:: float glm_percent(float from, float to, float current)
  97. percentage of current value between start and end value
  98. Parameters:
  99. | *[in]* **from** from value
  100. | *[in]* **to** to value
  101. | *[in]* **current** value between from and to values
  102. Returns:
  103. percentage of current value
  104. .. c:function:: float glm_percentc(float from, float to, float current)
  105. clamped percentage of current value between start and end value
  106. Parameters:
  107. | *[in]* **from** from value
  108. | *[in]* **to** to value
  109. | *[in]* **current** value between from and to values
  110. Returns:
  111. clamped normalized percent (0-100 in 0-1)
  112. .. c:function:: void glm_swapf(float *a, float *b)
  113. swap two float values
  114. Parameters:
  115. | *[in]* **a** float 1
  116. | *[in]* **b** float 2