matrix.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * 3D Engine
  3. * matrice.h:
  4. * Based on pikuma.com 3D software renderer in C
  5. * Copyright (c) 2021 986-Studio. All rights reserved.
  6. *
  7. * Created by Manoël Trapier on 06/03/2021.
  8. */
  9. #ifndef THREEDENGINE_SOURCE_INCLUDE_MATRICE_H
  10. #define THREEDENGINE_SOURCE_INCLUDE_MATRICE_H
  11. #include <vector.h>
  12. /***********************************************************************************************************************
  13. * Data types
  14. **********************************************************************************************************************/
  15. typedef struct matrix4_t
  16. {
  17. double v[4*4];
  18. } matrix4_t;
  19. /***********************************************************************************************************************
  20. * Global variables
  21. **********************************************************************************************************************/
  22. static const struct matrix4_t mat4Identity =
  23. {
  24. .v =
  25. {
  26. 1, 0, 0, 0,
  27. 0, 1, 0, 0,
  28. 0, 0, 1, 0,
  29. 0, 0, 0, 1
  30. }
  31. };
  32. /***********************************************************************************************************************
  33. * Prototypes
  34. **********************************************************************************************************************/
  35. #define FastGet4(_m, _x, _y) ((_m).v[4 * (_x) + (_y)])
  36. #define FastSet4(_m, _x, _y, _v) (((_m).v[4 * (_x) + (_y)]) = (_v))
  37. vec4_t mat4ProdVec4(matrix4_t mat, vec4_t v);
  38. matrix4_t mat4ProdMat4(matrix4_t a, matrix4_t b);
  39. vec4_t mat4ProdVec4Project(matrix4_t mat, vec4_t v);
  40. matrix4_t mat4Scale(double scaleX, double scaleY, double scaleZ);
  41. matrix4_t mat4Translate(double tX, double tY, double tZ);
  42. matrix4_t mat4RotationX(double angle);
  43. matrix4_t mat4RotationY(double angle);
  44. matrix4_t mat4RotationZ(double angle);
  45. matrix4_t mat4Perspective(double aspectRatio, double FOV, double zNear, double zFar);
  46. matrix4_t mat4LookAt(vec3_t eye, vec3_t target, vec3_t up);
  47. #endif /* THREEDENGINE_SOURCE_INCLUDE_MATRICE_H */