matrix4.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 3 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. #ifndef MATRIX4_H
  15. #define MATRIX4_H
  16. #include "vec4.h"
  17. /* 4x4 Matrix */
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. struct matrix3;
  22. struct matrix4 {
  23. struct vec4 x, y, z, t;
  24. };
  25. static inline void matrix4_copy(struct matrix4 *dst, const struct matrix4 *m)
  26. {
  27. dst->x.m = m->x.m;
  28. dst->y.m = m->y.m;
  29. dst->z.m = m->z.m;
  30. dst->t.m = m->t.m;
  31. }
  32. static inline void matrix4_identity(struct matrix4 *dst)
  33. {
  34. vec4_zero(&dst->x);
  35. vec4_zero(&dst->y);
  36. vec4_zero(&dst->z);
  37. vec4_zero(&dst->t);
  38. dst->x.x = 1.0f;
  39. dst->y.y = 1.0f;
  40. dst->z.z = 1.0f;
  41. dst->t.w = 1.0f;
  42. }
  43. EXPORT void matrix4_from_matrix3(struct matrix4 *dst, const struct matrix3 *m);
  44. EXPORT void matrix4_mul(struct matrix4 *dst, const struct matrix4 *m1,
  45. const struct matrix4 *m2);
  46. EXPORT float matrix4_determinant(const struct matrix4 *m);
  47. EXPORT bool matrix4_inv(struct matrix4 *dst, const struct matrix4 *m);
  48. EXPORT void matrix4_transpose(struct matrix4 *dst, const struct matrix4 *m);
  49. EXPORT void matrix4_ortho(struct matrix4 *dst, float left, float right,
  50. float top, float bottom, float near, float far);
  51. EXPORT void matrix4_frustum(struct matrix4 *dst, float left, float right,
  52. float top, float bottom, float near, float far);
  53. EXPORT void matrix4_perspective(struct matrix4 *dst, float angle,
  54. float aspect, float near, float far);
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif