Mat4Binds.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #include "Device.h"
  2. #include "ScriptSystem.h"
  3. #include "OS.h"
  4. namespace crown
  5. {
  6. extern "C"
  7. {
  8. Mat4& mat4(float r1c1, float r2c1, float r3c1, float r1c2, float r2c2, float r3c2, float r1c3, float r2c3, float r3c3);
  9. Mat4& mat4_add(Mat4& self, Mat4& m);
  10. Mat4& mat4_subtract(Mat4& self, Mat4& m);
  11. Mat4& mat4_multiply(Mat4& self, Mat4& m);
  12. Mat4& mat4_multiply_by_scalar(Mat4& self, float k);
  13. Mat4& mat4_divide_by_scalar(Mat4& self, float k);
  14. void mat4_build_rotation_x(Mat4& self, float radians);
  15. void mat4_build_rotation_y(Mat4& self, float radians);
  16. void mat4_build_rotation_z(Mat4& self, float radians);
  17. void mat4_build_rotation(Mat4& self, const Vec3& n, float radians);
  18. void mat4_build_projection_perspective_rh(Mat4& self, float fovy, float aspect, float near, float far);
  19. void mat4_build_projection_perspective_lh(Mat4& self, float fovy, float aspect, float near, float far);
  20. void mat4_build_projection_ortho_rh(Mat4& self, float width, float height, float near, float far);
  21. void mat4_build_projection_ortho_lh(Mat4& self, float width, float height, float near, float far);
  22. void mat4_build_projection_ortho_2d_rh(Mat4& self, float width, float height, float near, float far);
  23. void mat4_build_look_at_rh(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& up);
  24. void mat4_build_look_at_lh(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& up);
  25. void mat4_build_viewpoint_billboard(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& up);
  26. void mat4_build_axis_billboard(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& axis);
  27. Mat4& mat4_transpose(Mat4& self);
  28. float mat4_determinant(Mat4& self);
  29. Mat4& mat4_invert(Mat4& self);
  30. void mat4_load_identity(Mat4& self);
  31. Vec3& mat4_get_translation(Mat4& self);
  32. void mat4_set_translation(Mat4& self, const Vec3& trans);
  33. Vec3& mat4_get_scale(Mat4& self);
  34. void mat4_set_scale(Mat4& self, const Vec3& scale);
  35. void mat4_print(Mat4& self);
  36. }
  37. Mat4& mat4(float r1c1, float r2c1, float r3c1, float r1c2, float r2c2, float r3c2, float r1c3, float r2c3, float r3c3)
  38. {
  39. return device()->script_system()->next_mat4(r1c1, r2c1, r3c1, r1c2, r2c2, r3c2, r1c3, r2c3, r3c3);
  40. }
  41. Mat4& mat4_add(Mat4& self, Mat4& m)
  42. {
  43. self += m;
  44. return self;
  45. }
  46. Mat4& mat4_subtract(Mat4& self, Mat4& m)
  47. {
  48. self -= m;
  49. return self;
  50. }
  51. Mat4& mat4_multiply(Mat4& self, Mat4& m)
  52. {
  53. self *= m;
  54. return self;
  55. }
  56. Mat4& mat4_multiply_by_scalar(Mat4& self, float k)
  57. {
  58. self *= k;
  59. return self;
  60. }
  61. Mat4& mat4_divide_by_scalar(Mat4& self, float k)
  62. {
  63. self /= k;
  64. return self;
  65. }
  66. void mat4_build_rotation_x(Mat4& self, float radians)
  67. {
  68. self.build_rotation_x(radians);
  69. }
  70. void mat4_build_rotation_y(Mat4& self, float radians)
  71. {
  72. self.build_rotation_y(radians);
  73. }
  74. void mat4_build_rotation_z(Mat4& self, float radians)
  75. {
  76. self.build_rotation_z(radians);
  77. }
  78. void mat4_build_rotation(Mat4& self, const Vec3& n, float radians)
  79. {
  80. self.build_rotation(n, radians);
  81. }
  82. void mat4_build_projection_perspective_rh(Mat4& self, float fovy, float aspect, float near, float far)
  83. {
  84. self.build_projection_perspective_rh(fovy, aspect, near, far);
  85. }
  86. void mat4_build_projection_perspective_lh(Mat4& self, float fovy, float aspect, float near, float far)
  87. {
  88. self.build_projection_perspective_lh(fovy, aspect, near, far);
  89. }
  90. void mat4_build_projection_ortho_rh(Mat4& self, float width, float height, float near, float far)
  91. {
  92. self.build_projection_ortho_rh(width, height, near, far);
  93. }
  94. void mat4_build_projection_ortho_lh(Mat4& self, float width, float height, float near, float far)
  95. {
  96. self.build_projection_ortho_lh(width, height, near, far);
  97. }
  98. void mat4_build_projection_ortho_2d_rh(Mat4& self, float width, float height, float near, float far)
  99. {
  100. self.build_projection_ortho_2d_rh(width, height, near, far);
  101. }
  102. void mat4_build_look_at_rh(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& up)
  103. {
  104. self.build_look_at_rh(pos, target, up);
  105. }
  106. void mat4_build_look_at_lh(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& up)
  107. {
  108. self.build_look_at_lh(pos, target, up);
  109. }
  110. void mat4_build_viewpoint_billboard(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& up)
  111. {
  112. self.build_viewpoint_billboard(pos, target, up);
  113. }
  114. void mat4_build_axis_billboard(Mat4& self, const Vec3& pos, const Vec3& target, const Vec3& axis)
  115. {
  116. self.build_axis_billboard(pos, target, axis);
  117. }
  118. Mat4& mat4_transpose(Mat4& self)
  119. {
  120. self.transpose();
  121. return self;
  122. }
  123. float mat4_determinant(Mat4& self)
  124. {
  125. return self.get_determinant();
  126. }
  127. Mat4& mat4_invert(Mat4& self)
  128. {
  129. self.invert();
  130. return self;
  131. }
  132. void mat4_load_identity(Mat4& self)
  133. {
  134. self.load_identity();
  135. }
  136. Vec3& mat4_get_translation(Mat4& self)
  137. {
  138. Vec3 tmp = self.get_translation();
  139. return device()->script_system()->next_vec3(tmp.x, tmp.y, tmp.z);
  140. }
  141. void mat4_set_translation(Mat4& self, const Vec3& trans)
  142. {
  143. self.set_translation(trans);
  144. }
  145. Vec3& mat4_get_scale(Mat4& self)
  146. {
  147. Vec3 tmp = self.get_scale();
  148. return device()->script_system()->next_vec3(tmp.x, tmp.y, tmp.z);
  149. }
  150. void mat4_set_scale(Mat4& self, const Vec3& scale)
  151. {
  152. self.set_scale(scale);
  153. }
  154. void mat4_print(Mat4& self)
  155. {
  156. os::printf("|%.1f|%.1f|%.1f|%.1f|\n", self.m[0], self.m[4], self.m[8], self.m[12]);
  157. os::printf("|%.1f|%.1f|%.1f|%.1f|\n", self.m[1], self.m[5], self.m[9], self.m[13]);
  158. os::printf("|%.1f|%.1f|%.1f|%.1f|\n", self.m[2], self.m[6], self.m[10], self.m[14]);
  159. os::printf("|%.1f|%.1f|%.1f|%.1f|\n", self.m[3], self.m[7], self.m[11], self.m[15]);
  160. }
  161. } //namespace crown