matrix4.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include "vec4.h"
  16. /* 4x4 Matrix */
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. struct matrix3;
  21. struct matrix4 {
  22. struct vec4 x, y, z, t;
  23. };
  24. static inline void matrix4_copy(struct matrix4 *dst, const struct matrix4 *m)
  25. {
  26. dst->x.m = m->x.m;
  27. dst->y.m = m->y.m;
  28. dst->z.m = m->z.m;
  29. dst->t.m = m->t.m;
  30. }
  31. static inline void matrix4_identity(struct matrix4 *dst)
  32. {
  33. vec4_zero(&dst->x);
  34. vec4_zero(&dst->y);
  35. vec4_zero(&dst->z);
  36. vec4_zero(&dst->t);
  37. dst->x.x = 1.0f;
  38. dst->y.y = 1.0f;
  39. dst->z.z = 1.0f;
  40. dst->t.w = 1.0f;
  41. }
  42. EXPORT void matrix4_from_matrix3(struct matrix4 *dst, const struct matrix3 *m);
  43. EXPORT void matrix4_mul(struct matrix4 *dst, const struct matrix4 *m1,
  44. const struct matrix4 *m2);
  45. EXPORT float matrix4_determinant(const struct matrix4 *m);
  46. EXPORT bool matrix4_inv(struct matrix4 *dst, const struct matrix4 *m);
  47. EXPORT void matrix4_transpose(struct matrix4 *dst, const struct matrix4 *m);
  48. #ifdef __cplusplus
  49. }
  50. #endif