dd_math.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef DD_MATH_H
  2. #define DD_MATH_H
  3. #include "dd_vec2.h"
  4. #include "dd_vec3.h"
  5. #include <math.h>
  6. #include <stdlib.h>
  7. // Random
  8. int dd_math_rand(int to);
  9. /*
  10. * Eases
  11. *
  12. * Linear
  13. * Bezier
  14. * Catmull-Rom
  15. *
  16. * The 2D versions do the same on a vector2d
  17. *
  18. */
  19. float dd_math_ease_linear(float t, float p0, float p1);
  20. void dd_math_ease_linear2d(struct dd_vec2 *point, float t, struct dd_vec2 p0, struct dd_vec2 p1);
  21. float dd_math_ease_bezier(float t, float p0, float p1, float p2);
  22. void dd_math_ease_bezier2d(struct dd_vec2 *point, float t, struct dd_vec2 p0, struct dd_vec2 p1, struct dd_vec2 p2);
  23. float dd_math_ease_catmullrom(float t, float p0, float p1, float p2, float p3);
  24. void dd_math_ease_catmullrom2d(struct dd_vec2 *point, float t, struct dd_vec2 p0, struct dd_vec2 p1, struct dd_vec2 p2, struct dd_vec2 p3);
  25. // operations
  26. #define dd_math_pow(x, times) pow(x, times)
  27. #define dd_math_abs(val) fabs((float)val)
  28. #define dd_math_sqrt(val) sqrt(val)
  29. #define dd_math_sin(val) sinf(val)
  30. #define dd_math_cos(val) cosf(val)
  31. #define dd_math_tan(val) tanf(val)
  32. #define dd_math_asin(val) asinf(val)
  33. #define dd_math_acos(val) acosf(val)
  34. #define dd_math_atan(val) atanf(val)
  35. #define dd_math_floor(val) floorf(val)
  36. #define dd_math_ceil(val) ceilf(val)
  37. float dd_math_tan(float val);
  38. #define dd_math_min(a, b) (a > b ? b : a)
  39. #define dd_math_max(a, b) (a > b ? a : b)
  40. #define dd_math_minf(a, b) (a > b ? b : a)
  41. #define dd_math_maxf(a, b) (a > b ? a : b)
  42. float dd_math_rad2dec(float rad);
  43. float dd_math_dec2rad(float dec);
  44. // vector math
  45. float dd_math_dot2(struct dd_vec2 *v1, struct dd_vec2 *v2);
  46. float dd_math_dot3(struct dd_vec3 *v1, struct dd_vec3 *v2);
  47. #endif