mat4.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. local ffi = require("ffi")
  2. ffi.cdef
  3. [[
  4. typedef struct
  5. {
  6. float r1c1;
  7. float r2c1;
  8. float r3c1;
  9. float r4c1;
  10. float r1c2;
  11. float r2c2;
  12. float r3c2;
  13. float r4c2;
  14. float r1c3;
  15. float r2c3;
  16. float r3c3;
  17. float r4c3;
  18. float r1c4;
  19. float r2c4;
  20. float r3c4;
  21. float r4c4;
  22. } Mat4;
  23. Mat4& mat4(float r1c1, float r2c1, float r3c1, float r1c2, float r2c2, float r3c2, float r1c3, float r2c3, float r3c3);
  24. Mat4& mat4_add(Mat4& self, Mat4& m);
  25. Mat4& mat4_subtract(Mat4& self, Mat4& m);
  26. Mat4& mat4_multiply(Mat4& self, Mat4& m);
  27. Mat4& mat4_multiply_by_scalar(Mat4& self, float k);
  28. Mat4& mat4_divide_by_scalar(Mat4& self, float k);
  29. void mat4_build_rotation_x(Mat4& self, float radians);
  30. void mat4_build_rotation_y(Mat4& self, float radians);
  31. void mat4_build_rotation_z(Mat4& self, float radians);
  32. void mat4_build_rotation(Mat4& self, const Vec3& n, float radians);
  33. void mat4_build_projection_perspective_rh(Mat4& self, float fovy, float aspect, float near, float far);
  34. void mat4_build_projection_perspective_lh(Mat4& self, float fovy, float aspect, float near, float far);
  35. void mat4_build_projection_ortho_rh(Mat4& self, float width, float height, float near, float far);
  36. void mat4_build_projection_ortho_lh(Mat4& self, float width, float height, float near, float far);
  37. void mat4_build_projection_ortho_2d_rh(Mat4& self, float width, float height, float near, float far);
  38. void mat4_build_look_at_rh(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& up);
  39. void mat4_build_look_at_lh(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& up);
  40. void mat4_build_viewpoint_billboard(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& up);
  41. void mat4_build_axis_billboard(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& axis);
  42. Mat4& mat4_transpose(Mat4& self);
  43. float mat4_determinant(Mat4& self);
  44. Mat4& mat4_invert(Mat4& self);
  45. void mat4_load_identity(Mat4& self);
  46. Vec3& mat4_get_translation(Mat4& self);
  47. void mat4_set_translation(Mat4& self, const Vec3& trans);
  48. Vec3& mat4_get_scale(Mat4& self);
  49. void mat4_set_scale(Mat4& self, const Vec3& scale);
  50. void mat4_print(Mat4& self);
  51. ]]
  52. Mat4 = {}
  53. Mat4.mat4 = lib.mat4
  54. Mat4.add = lib.mat4_add
  55. Mat4.subtract = lib.mat4_subtract
  56. Mat4.multiply = lib.mat4_multiply
  57. Mat4.multiply_by_scalar = lib.mat4_multiply_by_scalar
  58. Mat4.divide_by_scalar = lib.mat4_divide_by_scalar
  59. Mat4.build_rotation_x = lib.mat4_build_rotation_x
  60. Mat4.build_rotation_y = lib.mat4_build_rotation_y
  61. Mat4.build_rotation_z = lib.mat4_build_rotation_z
  62. Mat4.build_rotation = lib.mat4_build_rotation
  63. Mat4.build_projection_perspective_rh = lib.mat4_build_projection_perspective_rh
  64. Mat4.build_projection_perspective_lh = lib.mat4_build_projection_perspective_lh
  65. Mat4.build_projection_ortho_rh = lib.mat4_build_projection_ortho_rh
  66. Mat4.build_projection_ortho_lh = lib.mat4_build_projection_ortho_lh
  67. Mat4.build_projection_ortho_2d_rh = lib.mat4_build_projection_ortho_2d_rh
  68. Mat4.build_look_at_rh = lib.mat4_build_look_at_rh
  69. Mat4.build_look_at_lh = lib.mat4_build_look_at_lh
  70. Mat4.build_viewpoint_billboard = lib.mat4_build_viewpoint_billboard
  71. Mat4.build_axis_billboard = lib.mat4_build_axis_billboard
  72. Mat4.transpose = lib.mat4_transpose
  73. Mat4.determinant = lib.mat4_determinant
  74. Mat4.invert = lib.mat4_invert
  75. Mat4.load_identity = lib.mat4_load_identity
  76. Mat4.get_translation = lib.mat4_get_translation
  77. Mat4.set_translation = lib.mat4_set_translation
  78. Mat4.get_scale = lib.mat4_get_scale
  79. Mat4.set_scale = lib.mat4_set_scale
  80. Mat4.print = lib.mat4_print