Re-implementation of Izanami game engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

53 lignes
924 B

  1. #ifndef IZ_VECTOR_H
  2. #define IZ_VECTOR_H
  3. #include "IZ_math.h"
  4. typedef struct {
  5. // positive X is rightwards
  6. IZ_Real x;
  7. // positive Y is downwards
  8. IZ_Real y;
  9. } IZ_Vector;
  10. inline IZ_Vector IZ_VectorAdd(IZ_Vector a, IZ_Vector b) {
  11. return (IZ_Vector) {
  12. .x = a.x + b.x,
  13. .y = a.y + b.y,
  14. };
  15. }
  16. inline IZ_Vector IZ_VectorSubtract(IZ_Vector a, IZ_Vector b) {
  17. return (IZ_Vector) {
  18. .x = a.x - b.x,
  19. .y = a.y - b.y,
  20. };
  21. }
  22. inline IZ_Vector IZ_VectorMultiply(IZ_Vector a, IZ_Real b) {
  23. return (IZ_Vector) {
  24. .x = a.x * b,
  25. .y = a.y * b,
  26. };
  27. }
  28. inline IZ_Vector IZ_VectorDivide(IZ_Vector a, IZ_Real b) {
  29. return (IZ_Vector) {
  30. .x = a.x / b,
  31. .y = a.y / b,
  32. };
  33. }
  34. inline IZ_Real IZ_VectorDot(IZ_Vector a, IZ_Vector b) {
  35. return a.x * b.x + a.y * b.y;
  36. }
  37. inline IZ_Real IZ_VectorDistance(IZ_Vector a, IZ_Vector b) {
  38. IZ_Real x = b.x - a.x;
  39. IZ_Real y = b.y - a.y;
  40. return IZ_Sqrt(x * x + y * y);
  41. }
  42. #endif //IZ_VECTOR_H