matrix3.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 MATRIX_H
  15. #define MATRIX_H
  16. #include "vec3.h"
  17. /* 3x4 Matrix */
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. struct axisang;
  22. struct matrix4;
  23. struct matrix3 {
  24. struct vec3 x;
  25. struct vec3 y;
  26. struct vec3 z;
  27. struct vec3 t;
  28. };
  29. static inline void matrix3_copy(struct matrix3 *dst, const struct matrix3 *m)
  30. {
  31. vec3_copy(&dst->x, &m->x);
  32. vec3_copy(&dst->y, &m->y);
  33. vec3_copy(&dst->z, &m->z);
  34. vec3_copy(&dst->t, &m->t);
  35. }
  36. static inline void matrix3_identity(struct matrix3 *dst)
  37. {
  38. vec3_zero(&dst->x);
  39. vec3_zero(&dst->y);
  40. vec3_zero(&dst->z);
  41. vec3_zero(&dst->t);
  42. dst->x.x = dst->y.y = dst->z.z = 1.0f;
  43. }
  44. EXPORT void matrix3_from_quat(struct matrix3 *dst, const struct quat *q);
  45. EXPORT void matrix3_from_axisang(struct matrix3 *dst,
  46. const struct axisang *aa);
  47. EXPORT void matrix3_from_matrix4(struct matrix3 *dst, const struct matrix4 *m);
  48. EXPORT void matrix3_mul(struct matrix3 *dst, const struct matrix3 *m1,
  49. const struct matrix3 *m2);
  50. static inline void matrix3_translate(struct matrix3 *dst,
  51. const struct matrix3 *m, const struct vec3 *v)
  52. {
  53. vec3_sub(&dst->t, &m->t, v);
  54. }
  55. EXPORT void matrix3_rotate(struct matrix3 *dst, const struct matrix3 *m,
  56. const struct quat *q);
  57. EXPORT void matrix3_rotate_aa(struct matrix3 *dst, const struct matrix3 *m,
  58. const struct axisang *aa);
  59. EXPORT void matrix3_scale(struct matrix3 *dst, const struct matrix3 *m,
  60. const struct vec3 *v);
  61. EXPORT void matrix3_transpose(struct matrix3 *dst, const struct matrix3 *m);
  62. EXPORT void matrix3_inv(struct matrix3 *dst, const struct matrix3 *m);
  63. EXPORT void matrix3_mirror(struct matrix3 *dst, const struct matrix3 *m,
  64. const struct plane *p);
  65. EXPORT void matrix3_mirrorv(struct matrix3 *dst, const struct matrix3 *m,
  66. const struct vec3 *v);
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif