vec3.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. local ffi = require("ffi")
  2. ffi.cdef
  3. [[
  4. typedef struct
  5. {
  6. float x;
  7. float y;
  8. float z;
  9. }
  10. Vec3;
  11. Vec3& vec3(float nx, float ny, float nz);
  12. Vec3& vec3_add(Vec3& self, const Vec3& v);
  13. Vec3& vec3_subtract(Vec3& self, const Vec3& v);
  14. Vec3& vec3_multiply(Vec3& self, const float s);
  15. Vec3& vec3_divide(Vec3& self, const float s);
  16. float vec3_dot(Vec3& self, const Vec3& v);
  17. Vec3& vec3_cross(Vec3& self, const Vec3& v);
  18. bool vec3_equal(Vec3& self, const Vec3& other);
  19. bool vec3_lower(Vec3& self, const Vec3& other);
  20. bool vec3_greater(Vec3& self, const Vec3& other);
  21. float vec3_length(Vec3& self);
  22. float vec3_squared_length(Vec3& self);
  23. void vec3_set_length(Vec3& self, float len);
  24. Vec3& vec3_normalize(Vec3& self);
  25. Vec3& vec3_negate(Vec3& self);
  26. float vec3_get_distance_to(Vec3& self, const Vec3& a);
  27. float vec3_get_angle_between(Vec3& self, const Vec3& a);
  28. void vec3_zero(Vec3& self);
  29. ]]
  30. -- Encapsulate method in Vec3 table
  31. Vec3 = {}
  32. Vec3.vec3 = lib.vec3;
  33. Vec3.add = lib.vec3_add
  34. Vec3.subtract = lib.vec3_subtract
  35. Vec3.multiply = lib.vec3_multiply
  36. Vec3.divide = lib.vec3_divide
  37. Vec3.dot = lib.vec3_dot
  38. Vec3.cross = lib.vec3_cross
  39. Vec3.equal = lib.vec3_equal
  40. Vec3.lower = lib.vec3_lower
  41. Vec3.greater = lib.vec3_greater
  42. Vec3.lenght = lib.vec3_length
  43. Vec3.squared_length = lib.vec3_squared_length
  44. Vec3.set_length = lib.vec3_set_length
  45. Vec3.normalize = lib.vec3_normalize
  46. Vec3.negate = lib.vec3_negate
  47. Vec3.get_distance_to = lib.vec3_get_distance_to
  48. Vec3.get_angle_between = lib.vec3_get_angle_between
  49. Vec3.zero = lib.vec3_zero